Monday, June 22, 2015

Internet connected LCD

A while ago I told you about my smart home setup. Part of it was a cheap Nokia 3310 LCD displaying the time and room temperature. Then I told you about the ESP8266, a microcontroller with built in WiFi.
Today, after a lot of struggling, I finally managed to combine these 2 together. Now I have an internet connected LCD:

Two ESPs died in the process - no idea how, they just died. RIP. Its time to order some more, because I have only one left.

Originally, I used the Adafruit library on the Arduino. So, the first thing I tried was to try to compile it for the ESP. Unfortunately, it didn't compile and at that time porting it seemed non-trivial. So I looked up for alternatives. And found out here that these examples should just work on the ESP.
The first problem is that these examples require 5 GPIO pins and the ESP-01 only has 4.
But, in the description of this library it says you can connect Chip Select to ground (because I don't have other devices sharing the SPI bus) and Reset to the Reset of the ESP. Which would mean it would only take 3 GPIO pins and leave me 1 spare!
So, I tried, compiled the examples and ... they didn't work. Just a blank screen. I double and triple checked my connections, my code ... everything was fine.
In desperation I tried the same examples, but with the Arduino instead with the ESP. Surprise, surprise, they didn't work on the Arduino either.
So I took the Adafruit's library and example (which work on the Arduino) and started comparing it with the code I was using.
Ultimately, I found out the following:
- You have to call "set contrast" again after initialization of the LCD for some reason (the initialization itself sets it). No idea why. But that was what caused the playground samples not to work. Maybe it is only the Chinese LCD + breakout I am using.
- It is indeed OK to connect "chip select to ground"
- It is NOT OK to connect Reset to the reset pin of the ESP. It needs a reset after the ESP has started. I am guessing it is because the ESP outputs stuff on its pins on boot, which might confuse the LCD.

So, for now I have 2 options - to waste the 4th GPIO pin with the sole purpose to reset the LCD at startup and stay HIGH from then on ... or to somehow reset the LCD by other means.
For the moment I just added another push button to reset the LED manually and made the code wait for 2 seconds on startup (so I have time to press it). It is far from ideal - as I have said before, finished projects should only have an on-off switch and that's it.
I believe it is possible to replace the push button with or more 555 timer chips, I just have no idea how ... yet.

Still, I now have an internet connected LCD and a spare GPIO pin. I have no idea how I am going to use them, but it is cool by itself.

The next step would be to actually port the Adafruit library - I now know enough about its inner workings, so it shouldn't be a problem.

No comments:

Post a Comment