this is a fork from @julisa99's original code at https://github.com/julisa99/Lovebox
See https://frightanic.com/iot/the-lovebox-a-gift-from-a-maker/ for build instructions and a description of the (early) code improvements I integrated.
Real quick here's how the Lovebox works:
- device connects to WiFi
- it then either
- polls a GitHub gist you configure for messages to display OR
- subscribes to a topic on an MQTT broker and waits for new messages to arrive
- when a new message arrives
- it is displayed on the OLED display
- the heart starts wiggling
- as soon as the lid is lifted from the box, the photoresistor (acronymed LDR for Light Decreasing Resistance, or light-dependent resistor) registers the extra light, assumes the message was read and stops the wiggling heart
Refer to my aforementioned blog post and @julisa99's README for building instructions.
This project targets the Arduino IDE. I actually prefer to work with Visual Studio Code and PlatformIO (a lot) but the Arduino IDE is better suited for IoT beginners.
See https://docs.thingpulse.com/how-tos/Arduino-IDE-for-ESP8266/ for how to prepare the Arduino IDE for this project. Once done install the following two libraries in Arduino IDE (Tools > Manage Libraries):
Contrary to Lisa's original code this fork offers two ways of obtaining the messages to display: polling a GitHub gist every n seconds (default 60) or subscribing to a topic on an MQTT broker.
I find MQTT the much saner approach and I strongly suggest you give it try.
Go to https://gist.github.com, create a new gist (see "message format" below) and configure the path to it in settings.h
in the Arduino IDE. Also, disable the MQTT option in the same file.
The only challenge in using the MQTT approach is the fact that you need access to an MQTT broker the Lovebox can connect to. Also, you will need an MQTT client for your computer or mobile device with which you will publish messages.
If you don't have access to an MQTT broker already I suggest you open an account with adafruit.io. They also documented nicely how to set up a desktop MQTT client.
Finally, configure all MQTT settings in settings.h
in the Arduino IDE.
The Lovebox supports two types of messages: plain text and (pseudo-)binary; a text message with 0/1 representing the black & white pixels of an image.
Please adhere strictly to the message format defined below to avoid unexpected results.
- 1st line: increasing message ID only for GitHub gist i.e. omit for MQTT messages! The Lovebox uses this ID to determine whether the message it polls from the GitHub gist is different from the one it previously displayed.
- 2nd line: message type
t
= text orb
= (pseudo-)binary. - 3rd and subsequent lines: text or (pseudo-)binary message content.
GitHub gist example
42
t
Look, just because I don't be givin' no man a foot massage don't make it right for Marsellus to throw Antwone into a glass motherfuckin' house...
MQTT example
t
Look, just because I don't be givin' no man a foot massage don't make it right for Marsellus to throw Antwone into a glass motherfuckin' house...
To send a (pseudo-)binary message prepare a 128x64 black & white image. Then upload it to https://www.dcode.fr/binary-image and set the target width to 128 pixels. The image will then be converted to "0" and "1", each black pixel represented as a 0 and each white pixel as a 1.
GitHub gist binary example