Motorcycle Picture Frame: Programming
This has multiple parts, each contributing to the displays. The simplest being the microSD breakout board to provide the pictures for the TFT display, and the other being the RTC module providing the date and time for the OLED display. Additionally, the pictures on the microSD have to be loaded and looped for display.
For the most part, the code is readily available through the example sketches in the Arduino IDE. There will need to be changes for the specific setup, as expected, but it’s minor entries for the components. The main changes will be for the OLED display, ensuring that we use the “0x3C” device ID, and 128×64 display size. The RTC module needs to be setup with the current time, then it will continue on its own.
The microSD reader on the TFT will not be used, but rather read from the microSD breakout board. The pins will connect as follows:
| microSD Breakout Board | Arduino Mega | |
|---|---|---|
| Power | 5V | 5V |
| Ground | GND | GND |
| Serial Clock | CLK | D52 |
| Master In Slave Out (MISO) | DO | 50 |
| Master Out Slave In (MOSI) | DI | 51 |
| Chip/Slave Select | CS/SS | 53 |
The Sketch
setup()
In the setup, the TFT and OLED displays will need to be started, and ensure we can send data. Following the displays, the RTC will be initialized for a time stamp. Lastly, the microSD card will be checked for readability, then open the root directory.
loop()
The continuous loop function will output the text on the OLED display, getting the date counter data from the annidate() function. After the counter data is displayed, it will begin the showImage() function, cycling through the pictures on the microSD card.
annidate()
The RTC will provide a date. The Arduino Mega will perform the math to check if today’s date is July 17. If so, count the years since 2016, and output “Happy X-Year Anniversary” on the OLED display. If it’s not July 17, it will check if today is the 17th of any other month, and if so, output “Happy X Months” on the OLED display. Lastly, if it’s not the 17th, it will count the days since July 17, 2016, and output “My Happiness For X Days” on the OLED display. This check occurs after it is done cycling through all of the pictures in the showImage() function.
showImage()
This function serves the purpose of cycling through the pictures in the root directory of the microSD card, and sending the image to the bmpDraw() function, to be displayed on the TFT display. Each picture is shown for 4000ms (4 seconds), before cycling to the next image. Once it is done going through all the images in the root directory, the break in the image cycling function will end the loop() function. Upon doing so, the loop() function repeats its tasks of checking the time stamp from the RTC, processing it through annidate(), and then looping through the pictures once again.
bmpDraw()
This part of the sketch comes from the example in the Arduino IDE. It will only be called once an image is ready to be shown on the TFT display. Whenever showImage() finds an image, it sends the filename to the bmpDraw() function, and swipes the current image for the next in the directory listing.
Conclusion
This sketch works, and does what I need. Looking back, I could have slimmed down the design, by using 2 Arduino Pro Mini, each handling the different displays, and respective components. One of the Arduino Pro Mini could have been checking the date from the RTC, and sent the data to the OLED display. The other could read from the microSD breakout board, and send the image to be drawn on the TFT display. This is a lesson in patience and efficiency.