Navigate back to the homepage

Arduino Dollhouse Mini TV

Markus
December 13th, 2020 · 4 min read

A mini TV for my daughter’s dollhouse

This project and the blog post about it were originally created in February 2019. A few weeks ago I updated the Mini TV software so it was time to update the blog post as well.

The dollhouse Mini TV is a small Arduino project using an ESP8266 chip on a Wemos D1 board and an SSD1306 OLED display to build a small working TV for my daughter’s birthday. She already had this older plastic TV showing some yellowed picture and the project brings that TV to life.

The TV displays an endless loop of different TV “channels” showing animations, a clock, and a weather forecast. With a small button at the side, one could stop the loop and watch the current channel. Another button press continues the loop.

From prototype to working mini TV

The display size for this project was predefined by the frame size of the old dollhouse TV. There were only a few options and I had an SSD1306 OLED display laying around. A normal NodeMCU or Adafruit feather was too big for the small frame, so I decided on a Wemos D1 which fitted nicely into the old TV.

The TV is powered via dollhouse cabling. All rooms have mini sockets installed providing 4.5 volts, enough to power the mini TV. Only the DC polarity is a small problem for the TV, it needs to be plugged in the correct way.

The display shows 5 screens (can be extended) in a carousel mode. Most of them are little cat or dinosaur animations but it has a real weather forecast and a nice clock as well. Additionally, I added some real black & white pictures of our cats with the last update.

Hardware components & tools

  • Wemos D1 mini
  • SSD1306 OLED Display
  • Tactile Button Switch
  • Dollhouse plug (fitting into the sockets the dollhouse already has)
  • USB cable (for programming only)
  • Some wires
  • Soldering iron
  • Hot glue

The wiring is pretty simple the display connects via I2C bus to the Wemos board and the button just needs two wires.

Software

Like some of my other Arduino projects, I used Homie as a base library for this project. This is actually not really necessary for the Mini TV as it has no special requirements and does not need MQTT. But since it uses the same SSD1306 OLED display I could reuse some of the Homie node classes from the mqtt-bme280-homie project.

Additionally, with Homie one gets OTA update as well, which is important here because I hot glued the board to the rear wall of the TV and could not access the USB connector anymore.

The following software libraries are used for this project:

Code structure

As usual, the source code and configuration details can be found on GitHub: https://github.com/mhaack/arduino-dollhouse-tv It is organized into 4 main modules:

  • dollhouse-tv.cpp - the main program drawing all the TV screens and assembling them all together
  • DisplayNode.h / .cpp - generic class to control the SSD1306 display
  • ButtonNode.h / .cpp - simple and generic class to capture the button press (this is from http://github.com/luebbe Homie node collection)
  • WeatherStationNode.h / .cpp - Homie wrapper class around the OpenWeatherMap client of the ESP8266 Weather Station project

Additionally, we have WeatherStationFonts.h to store the weather icons like sun, clouds, etc. for the weather display. And images.h which has a list of array constants storing the images & bitmaps.

The TV logic itself is very simple. For each screen aka. channel there is a “draw” method defined in dollhouse-tv.cpp:

1void drawCat(OLEDDisplay *display, OLEDDisplayUiState *state, int16_t x, int16_t y);
2void drawStars(OLEDDisplay *display, OLEDDisplayUiState *state, int16_t x, int16_t y);
3void drawClock(OLEDDisplay *display, OLEDDisplayUiState *state, int16_t x, int16_t y);
4void drawWeather(OLEDDisplay *display, OLEDDisplayUiState *state, int16_t x, int16_t y);
5void drawDino(OLEDDisplay *display, OLEDDisplayUiState *state, int16_t x, int16_t y);
6void drawPictures(OLEDDisplay *display, OLEDDisplayUiState *state, int16_t x, int16_t y);

Each method is used to draw the channel-specific information or images on the screen. They contain mostly painting method calls and have access to the entire display. For transitions between the different screens the draw method gets virtual x & y coordinate. This is used to have a smooth animation while the current screen is transition in and out.

1void drawDino(OLEDDisplay *display, OLEDDisplayUiState *state, int16_t x, int16_t y) {
2 display->setColor(WHITE);
3 display->drawXbm(x + dinoPosX, y, dino_width, dino_height, dinoPointers[dinoState]);
4
5 dinoState++;
6 if (dinoState >= 16) {
7 dinoState = 0;
8 }
9 dinoPosX++;
10 if (dinoPosX > 128) {
11 dinoPosX = -64;
12 }
13}

The above example shows a dinosaur animation build-out of different sprites. It sets the color (there are only white and black on an SSD1306 OLED display) and draws the bitmap image. Then it moves to the next sprite and one pixel to the right on the x coordinates until the dinosaur reaches the edge of the screen.

Configuration

Like all Homie-based projects, this project needs a configuration file as well. To configure the device, you have to create and manually flash the configuration file to the device SPIFFS at the /homie/config.json. The following sample configuration file can be used for upload. This file is in the GitHub repository as well.

1{
2 "name": "Dollhous TV",
3 "device_id": "mqtt-dollhouse-tv",
4 "wifi": {
5 "ssid": "<wifi ssid>",
6 "password": "<wifi password>"
7 },
8 "mqtt": {
9 "host": "<mqtt server hostname or ip>",
10 "port": 1883,
11 "auth": true, // if MQTT server requieres authentication
12 "username": "<mqtt username>",
13 "password": "<mqtt password>"
14 },
15 "ota": {
16 "enabled": true
17 },
18 "settings": {
19 "flipScreen": true,
20 "WeatherApiKey": "<your open weather map api key",
21 "WeatherLanguage": "en",
22 "WeatherLocation": "2950159",
23 "WeatherUpdate": 15
24 }
25}

The important configuration settings here are the wifi username & password, the MQTT settings, and the parameters for the OpenWeatherMap client.

For MQTT you need to provide the server’s hostname or IP address. If authentication is used username and password are required here as well. If not you don’t need to include these in your config.

To retrieve OpenWeatherMap weather three configuration parameters are needed:

  • WeatherApiKey - To load weather data from OpenWeatherMap you need an API key, follow the instructions create one for your needs.
  • WeatherLanguage - set this to get the output in your language, see https://openweathermap.org/current#multi for available languages
  • WeatherLocation- this is the identifier of the location you want to load the weather data for. To get it open the weather details for the place you are interested in and copy the number of the location from the URL. For example for Berlin the OpenWeatherMap page is https://openweathermap.org/city/2950159, you take 2950159 from the URL.

As an alternative to the file upload configuration, Homie ESP8266 also allows configuration via HTTP JSON API. Once the device is running and connected individual configuration settings can be changed via MQTT as well.

Your own screens and animations

You can add as many screens as you want and add them to dollhouse-tv.cpp via the setup method. Each screen animation goes into its own “drawXYZ” method, for an animation example see drawCat.

If you want to build animations out of a sequence of XBM bitmaps you can follow the procedure below.

The workflow to add a new image animation is simple. First get the image either as an animated gif or independent image files, ideally in black and white format. The size of the image should match the screen size of the display. For the SSD1306 OLED display it must have a width of 128 pixels and a height of 64 pixels. Gif animations have to be split into individual image files.

These can be converted to an XBM bitmap file using some image tool or an online service like https://convertio.co/gif-xbm/. Put the XBM files into the project src folder or merge them into images.h. After that, they can be loaded into the code by using drawXbm. Make sure you add the x & y coordinates from the method parameters when drawing on the screen to have smooth transitions if the screen is changed to the next one.

That’s it have fun with the Mini TV.

Read More

Home Assistant: You have got mail

Today I want to share a little holiday project I build this week: a mailbox sensor to make a dumb mailbox smart and notifying us if we got new mail. I’m talking about real physical mail here - letters, postcards, newspapers etc. dropped into our mailbox.

September 5th, 2020 · 3 min read

Building Experiences - AEM & Magento Commerce Integration

On July 28th I was a guest on Mark Szulc's Building Experiences using Adobe Experience Cloud show. We discussed how Adobe Experience Manager works together with Magento, using the latest release of the Commerce Integration Framework.

July 31st, 2020 · 1 min read
© 2017–2020 | Made with ❤ by Markus Haack | Built with: Gatsby.js & Novela theme
Link to $https://twitter.com/mhaackLink to $https://instagram.com/mhaackLink to $https://github.com/mhaackLink to $https://de.linkedin.com/in/markushaack