During my childhood, I used to have lots of fun putting together electronic contraptions. Every month I browsed the local magazines (yes, we used to have those) looking for projects to build. What a joyful moment when they actually worked - most of the time did they did not.
Anyway, several decades later I've rediscovered this passion by playing with modern microcontrollers during my weekends. My favorite one is the ESP32 from Espressif, specially when programmed with MicroPython.
The ATOM Matrix is the latest and most compact development board in the awesome M5Stack development kit series. It has a built-in MPU6886 accelerometer, which I have used together with my colleague's library to "move" a dot in the device LED Matrix. Both my code and the library has been written in MicroPython and tested with the current 1.12 version.
HardwareIf you use an ATOM Matrix you have everything you will need.
Alternatively this project would also run on a M5StickC - in this case you will need to connect a NeoFlash hat into its back as showed in the picture below.
Connect your ESP32 device to your computer USB port. To check if it has been recognized on Windows you can run device manager (Press the Windows Key and search for device manager).
On device manager a new COM port should be detected as showed in the picture below. Note the COM port that was assigned - we will need that later.
If your computer does not recognize any new USB device, check your cable. If the new device did not install correctly, please manually install the device drivers from the link below.
https://www.ftdichip.com/Drivers/VCP.htm (M5StickC)
Now you are ready to "burn" the MicroPython firmware into the non volatile memory of your device.
You will find the firmware and instructions how to flash it on the official MicroPython site http://micropython.org/download#esp32. I tested the code on this article using the GENERIC firmware esp32-20210418-v1.15.bin.
There is very detailed video explaining all of this in case you prefer to follow along.
VS Code and the Pymakr PluginOnce you have MicroPython on your device the final step is download and copy main.py and mpu6886.py files to it.
That can be accomplished in different ways my favorite been from Visual Studio Code. You will need an extension developed by Pycom. Instructions can be found here:
https://docs.pycom.io/pymakr/installation/vscode/
To use VS Code with MicroPython, make sure you have a folder containing only the files you want to copy to the device. Open this folder from VS Code and use the Upload command from the Pymakr extension. It will copy all the files from the folder in your computer to the device.
SoftwareThe code basically uses the 3-axis acceleration measurements from the sensor to calculate the Pitch and Roll angles using the formulas from here. Yaw is ignored. If the Pitch / Roll angles are above 5°, the dot moves in that direction. You can adjust the tilt angle needed to move the dot by changing the variable threshold (line 23) - the value is in degrees.
When the dot reaches the LED matrix border it changes color.
I hope you have enjoyed this article and had some fun with it.
Comments