Skip to main content

First steps with a screen

I haven't written anything for months ! But lots of things happened.

First, I made my first steps with the STM32 and the KaRadio communication through serial. It ran into lots of trouble regarding the Arduino Code, and the limitations of writing with Arduino only. In order to get it working, I used the existing code from Jean-Pierre Cocatrix (the creator of KaRadio) for his own STM32 with full LCD screen and IR remote. As I read it, I slowly started to understand that he used special functions from the FreeRTOS implementation for STM32, which allowed him to use timers to schedule multiple functions to be run in parallel. I though it was brilliant, and since I had problems with the serial buffer size with regular programmation (sorry not to give more information about this, there is some on Facebook but I desactivated my account some time ago), I ended up adapting Jean-Pierre's code to use the FreeRTOS implementation of scheduled tasks for the different tasks of my program. It fixed the problem with reading and writing on serial, so I was happy with it.

I connected my LCD screen on the STM32 on PB6 and PB7, to use SDA and SCL for I2C communication. My LCD is connected with the address 0x3f. Because I wanted to be able to print easily something on a line that can be horizontally scrolled, or on multiple lines that can be vertically scrolled, I wrote several functions in the LiquidCrystal_I2C library for Arduino that I used previously. My modified library will be available, although I don't plan to use it as-is in the near future. The functions I've written are extensively using delays, so they're messing up with the division in tasks and they're blocking the whole STM32 so I will definitely re-write them in a better way. Still, I think they are a valuable piece of information for the future on how NOT to write code.

Concerning the hardware, I arranged some of my PCBs on a single board and soldered them so that their power supply is directly shared. It makes it easier to power the STM32, the ESP8266 and the VS1053 at once. You can see the result here :

The screen is nice !

I directly stole the functions to decode the UART and to create scheduled tasks from Jean-Pierre's STM32 code. I wrote just a bit of code to display things like artist and title, and the radio name, with my (poorly written) functions, and also to display time.
Time is first known through an NTP requets, and then it is counted on the STM32 itself. In order not to have too frequent NTP requests, I decided to schedule NTP requests every 2mn for the moment, and to count seconds with a scheduled task. For the moment, every second lasts 2 seconds (which is awfully bad I know :D) but I think it's because of my delays in the LCD print functions I build. As soon as they're re-built, I should be far better.

I decided to extract the speakers from their wooden frame, so that they would adapt on a future, newer frame.


Lots of parts are still connected with plug, allowing easy separations.

I am still unsure of how to design the final box. The more I think of it, the more I suspect that drilling holes in a wooden box will be a hassle and a tiring operation. So I am thinking of using wood (or agglomerated wood) for the whole box except the front face. For the front face, I can 3D print some plate I can design with SolidWorks. This way, I would have holes and openings all ready as soon as the face gets out of the printer. Assembling the two could be done by screws.

This is getting a bit more complicated since I'm decided for good to build some kind of alarm-clock with this webradio. I want it to be an alarm clock. So I may have to re-work how many buttons I should have, how they should work, how can I set the alarm time (I don't need to set the global time since it's NTP based, but I want to be able to set the alarm anytime), how to set it ON or OFF... and how to display time on every situation ! I will buy some 7-segments display , driven by a TM1637 chip just dedicated to that task.

For the moment, I didn't find a nice wooden case to put everything in yet. It's getting more and more complicated, but at least it's also getting more and more interesting.

The code is available here, it's dirty, ugly, but I think preserving it for history may be nice. So here it is. https://drive.google.com/open?id=1eXwoX-yZ6Oo6ycYR64UcktSgxkpoHvxl

Next time would be re-writing all my libs to make them faster and cleaner (and not use delays !). I want to try to add some buttons to add control through the STM32 to the KaRadio (I can already ask for NTP requests, I want to do more).
For hardware work, I need to organize my buttons and to prepare a real VCC-GND line for all the components that are not connected yet. This means the LCD screen, the PAM8403 amplifier, and the future TM1637 display. In the future, the LCD display would be able to be shut down to save power and not to be annoying at night time.

See you next time !

Comments

Popular posts from this blog

Flashing an STM32 "Blue Pill"

Flashing this STM32 "Blue Pill" board took me 5 hours. I finally recieved my microcontrollers. I have at disposal : A brand new WeMos D1 Mini (it's a smallish NodeMCU) An Arduino Pro Mini (it acts just like a Leonardo, but it lacks some interesting pins sadly :(  ) An STM32F103C8T6, I'll call this the Blue Pill for short. The Arduino Pro Mini has an Arduino bootloader out-of-the-box, so  I could play with it directly. It's nice ! Still, it lacks the double Serial of the original Leonardo, and most importantly, there's no A4 and A5 pins, so libraries for I2C won't work without modification. But the Blue Pill needs more work. Basically, I followed the instructions on this site : http://wiki.stm32duino.com/index.php?title=Installation Since it's quite complicated, consider the following as a tutorial to set up your Blue Pill. I tried different things, the following has worked for me. Before doing anything software-related, while reading the B

Anti-optimization, hardware crumbling apart, GitHub

Today, short post about deceiving software. Remember when last time, I said I had to do optmizations on my code ? Well I tried. And it went worse than I expected ! First, I tried to gather similar codes in some tasks, but it came out they were too heavy for FreeRTOS to handle them correctly, resulting in heap panic... So trying to enhance my code, I worsen it ! So I hard to roll it back. Then, I tried to implement real mutexes for some resources that are shared among the tasks, in particular the screen (and maybe the UART one day, but I can manage to use it only in one task, if I split it in several functions). When I though I understood it and implemented it correctly, it turned out to make the STM32 crash at bootup, and being non recognizable by my PC anymore ! So again, I had to rollback to the previous version. I'm still trying to figure out how to re-design my code, while keeping it runnable on that picky Blue Pill. You can FINALLY find my code on Github ! I suggest

Buttons and alarm

Now I have my buttons. And it didn't go smooth sailing. Before all, let's try to review what I want and how to do that : I want buttons to control the KaRadio. 6 buttons are enough. We will detail them a bit afterwards. I want my buttons to also set an alarm clock. This should stay visible, and should use the already implemented buttons to be modified and set. I want that any push in a button results in changes that are visible on the LCD screen. If the volume changes, I want to see it. If the station changes, well that's already implemented. First, I went to read the documentation on how to operate the GPIO. I knew I needed only to read digital states of the GPIO. At first, I found this document straight from Maple docs : http://docs.leaflabs.com/static.leaflabs.com/pub/leaflabs/maple-docs/0.0.12/libmaple/api/gpio.html It's quite dense, but there is some information. GPIOs must be initialized with gpio_init(), then you need to set their state to output or in