As a maker during the holiday season, you might be rushing to think about what whacky gifts to make for your family and friends. In my case, we are all spread throughout the western hemisphere, ranging from Venezuela, Brazil, US, Spain and the UK. This means for us, Christmas, is a particularly important holiday as it gives us a chance to get together to catch up and celebrate the main achievements of the year.
Given the current global situation, seeing each other has been particularly difficult and ensuring that we are and remain in good spirit has become more important than ever. For these reasons, I have decided to make a "smart" messaging device to keep my family more connected and ensure we can check on each other during these difficult times. The base for this project is the InkyShot from Balena, which allows me to easily connect the Raspberry Pi with the e-ink display to the cloud and flash it remotely to deliver quotes. Building on this idea, I can use the Balena Python SDK to create a script that connects to the Balena Cloud and updates the device environment variables to update the message on the device. Finally, I can wrap this up in a nice interface to allow my less tech-savvy family members to be able to update the messages through a GUI.
This should allow you to deliver personal quotes to your family members in a more intimate way than just a text message. Also, you can be constantly reminded of them by having it on your desk.
What we'll cover:
Part 1: how to get the basic project running on the Raspberry Pi Zero with Balena Cloud
Part 2: integrating our Balena Cloud application with a graphical interface through their Python SDK and PySimpleGUI
Part 1Build materials
· Raspberry Pi Zero w/h
· Power supply (5v 2A)
· Micro SD card at least 8GB with an adaptor to connect to the computer
· Some case or enclosure for the Pi
· An inky pHAT e-ink display
Software tools
Application Flow
Raspberry Pi -> Balena Cloud -> Updating the state of the device variables on Balena Cloud -> Send new state back to the board -> Update screen on the device.
Instructions
All you need to do is set up your device and change the state variable to see the chosen message on display. To do this yourself, follow the steps below:
Step 1: Create a Balena account
Step 2: Click here to deploy the InkyShot project automatically
Step 3: Give your application a name and select the Raspberry Pi zero as shown below
Step 4: Click "Create and deploy"
Step 5: Add your device
Step 6: Select "Wifi + Ethernet" and enter your credentials
Step 7: Download OS image
Step 8: Flash the SD card using Etcher
Step 9: Put the Inky display on the Raspberry Pi
Step 10: Put the SD card on the Raspberry Pi and connect it to a power supply
This step can take up to 10 minutes whilst the device installs the OS. Afterwards, it should automatically connect to Wi-Fi with the credentials defined above. This will mean that we should see the device appear live on the Balena web console under the "Devices" tab.
Next, you should be able to update the messages on the board's display by creating a device variable named "INKY_MESSAGE" this should be under the "D(x) Device Variables" tab.
As a foundation for understanding the next part of this project, I suggest checking out this page on the Balena SDK.
Part 2Now we're going to put together a simple Python script that allows us to change the message on the e-ink display through a GUI. The idea is that you can set up this whole process to make it simpler for your non-tech savvy family members. In the end, all they have to do is click on an icon, enter the message and press an "OK" button. No coding required.
Jump into your terminal and make sure you install the following Python packages:
pip install balena-sdk
pip install PySimpleGUI
pip install pyinstaller
Note: I had to use Python 3.6 to ensure this all worked.
The following script connects to our Balena account, get's the id of the last created device environment variable and updates its content to the string that we typed on the GUI.
import PySimpleGUI as sg
from balena import Balena
balena = Balena()
credentials = {'username':'EMAIL_YOU_USED_WITH_BALENA@gmail.com','password':'YOUR_BALENA_PASSWORD'}
balena.auth.login(**credentials)
# Define the window's contents
layout = [ [sg.Text("What's the message?")],
[sg.Input()],
[sg.Button('Ok')] ]
# Create the window
window = sg.Window('IoT Communicator', layout)
# Display and interact with the Window
event, values = window.read()
id = balena.models.environment_variables.device.get_all('YOUR_DEVICE_UUID')[0]['id']
balena.models.environment_variables.device.update(id, values[0])
window.close()
Here you have to replace your Balena email, password and device UUID with your own values.
Next, you should run the program to test that it works.
Your device should update the display's message within a minute although slower internet may impact this.
Next, we want to turn this into an executable so that people can click on an icon to get this GUI. To do that, we'll use a library called PyInstaller.
pyinstaller --onefile christmas_gift.py
This should generate an executable inside the "dist" folder created. Now you can drop that executable on your non-tech savvy family members' computer, and they should be able to update your Inky display remotely.
You can right-click the icon and go into properties to change the icon.
If you have a similar Arm-based project, such as this, feel free to share it for a chance to be featured on the weekly Innovation Coffee Live Stream.
Comments