This guide will show you how to make a simple wireless doorbell that uses an M5Stack Atom Matrix as a transmitter and an M5Stack Core2 as a receiver using Espressiv's ESP-Now system in UIFlow.
Before we start programming, we first need to Update the firmware on the devices to the latest version using M5Burner.
Make sure the Com port is set to the port that shows up when the matrix is plugged in and then click the green "Erase" button to remove the existing firmware. Next select the newest version of the Matrix version using the drop down menu, click on download and then the red "Burn" button to burn the new firmware.
Repeat the firmware process for the Core2 using the Core2 firmware menu and when complete close M5Burner.
Finding the M5Stack Atom Matrix MAC Address.
In order to use the ESP-Now to communicate between devices we need to know each devices MAC address. On the Core2 we can use a label to display it on the screen however, the Atom Matrix does not have a screen and so we need to use some Micropython code to send this over a terminal to another program.
For retrieving the MAC address I use Thonny's terminal and program in UIFLOW Online version. Press the button at the top of the screen to switch UIFlow into the Micropython text mode and type the following code in.
Once the code above is typed in, click on the play button at the top of the screen to send the code to the Atom Matrix and then switch to Thonny.
Important Note: If a red X appears on the Atom Matrix screen, in Thonny you will see an error message about m5ui. delete from m5ui import* and resend the program.
When you switch to Thonny you should see this shown in the terminal panel, if you seen red error messages, check the device settings and com port in Thonny's setting and reset the Atom Matrix.
The Last line of text in the terminal output is the hexadecimal MAC address of the Atom Matrix. Write this down and copy it to the computers memory and then switch back to UIFLlow.
Setting up the Core2 as the receiver.
In order to connect the Atom Matrix and Core2 together we need to find the Core2's Mac address. To do that we can use the following simple program to display it on the Core2's screen
Write this number down and then replace the code with the following.
Leave this running or the Core2 and then switch UIFlow to connect to the Atom Matrix.
Copy the following code into UIflow but replace the MAC address in the "Add Peer" block with the MAC address you copied from the Core2 earlier.
All this code does is send the message "doorbell" every time the screen of the Atom Matrix is pressed.
The receiver code on the Core2 waits for this message to be received, activates the vibrating motor, shows the message on the screen and then changes the colour of the screen to attract the attention of anyone in the area.
Issues.
Bug 1: Unfortunately, this basic program shows a bug in UIFlow in that every time the Atom Matrix is pressed, the vibration motor activates before the screen functions even though the screen function are set to run first. If the vibration motor is not switched off, the screen fails to turn green and show the doorbell message.
Bug2: The second bug is pressing the Atom Matrix too many times will cause it to crash.
Bug3: When Using ESP-Now, WIFI is disconnected meaning that devices need to be reset before they can be reprogrammed. Sometimes when switching between ESP-Now mode and Wifi mode, the matrix will fail to connect and requires powering down completely instead of just pressing reset.
What's Next for this project?
Next I need to make a new 3d printed shell for the matrix that includes a battery, Add visual indication to the Atom Matrix screen, add audio to the Core2 and connect the Core2 to Amazon AWS.
This will come in part 2 but this quick introduction to ESP-Now is complete. If you found this guide useful, please click on the "Thumbs up" icon.
Comments