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 Blue Pill page …

Adding some speakers, part 1

I've got speakers, an amplifier, audio transformers, and a KaRadio.
Let's have fun with that !

So in order to connect everything, I took the plugs from the original radio and soldered them along with headers, to connect things easily.



Then I soldered headers on the amp side, easy connection. And I wired them together. I also soldered a USB cable on the power input of the amp board.

On the VS1053 side, I have a Arduino-shaped board, so I took advantage of some unused pins to wire the output speakers to 3 pins. Again, the easier, the better... Except that soldering these 3 little cables was FRIGGING HARD, they kept swinging and moving around, it was hellish. But oh well, it's done now.



Finally, I took 3 wires to link the VS1053 to the amp (it's a PAM8403). The pair ESP8266 + VS1053 has its own power supply (it's a USB battery) while the amplifier has a separate USB power supply.



Aaaaaaand it works very well :)

I tried to put the whole on the same power supply and I g…

Adding some speakers, part 2

I added the audio transistors.

Before diving into this modification, I wanted to see how deteriorated the sound is when you try to link everything on the same power supply WITHOUT transistors. So I made this little video. You can hear the difference !



First, I noticed that my three little wires (on the output of the VS1053) were badly soldered and caused a short-circuit somewhere. So I removed them, and replaced them with a naked Jack plug. (I took it from a selfie stick. True story. These selfie sticks have an audio Jack plug to be able to take a shot from a button near the hand, that acts just like a button from headphones with mic. End of the story, back to business :p )

I wired the output of the VS1053 to the input of the transformers, and I wired the output of the transformers to the input of the PAM8403 (the amplifier). Since on the input and on the output, they have common ground between the two channels, I kept the common ground. You can see a rough scheme below (the "Aud…