Hello,
TL;DR: my goal is to develop a GUI application in Python for the MP135, using QT or GTK.
I would like to share the following notes after testing the MP135 for a few days. Hopefully, they can be useful to others, but I would welcome any comments (or criticism).
I have used the Debian Bookworm image (M5_CoreMP135_debian12_20240515), which can be found here.
NB: after burning the image to a SD card, don’t forget to extend the partition. This is easy to do with Gparted as shown below.
I have used a 8 Gb SD card, and the image takes about 1 Gb. Besides, you will need some free space to install a few big packages :)
The final result is a GTK app running in Openbox.
At the moment, I run applications as root user. This is something I would rather avoid in the future. Probably, a few things can be improved as well.
I have used a computer running Linux, so the instructions will be slightly different for Windows users.
Serial console
You can use a PC with a free USB port as power source for the MP135 and serial console. NB: if the USB port does not deliver enough power, try another.
After one minute, the serial console should be ready, probably mounted under /dev/ttyACM0 but that may vary from one PC to another.
You can run this command before plugging in the device to see the name assigned to the USB serial console on your computer:
sudo dmesg -wT
Example:
[Wed May 29 20:48:54 2024] usb 1-4: new high-speed USB device number 5 using xhci_hcd
[Wed May 29 20:48:54 2024] usb 1-4: New USB device found, idVendor=0525, idProduct=a4a7, bcdDevice= 5.15
[Wed May 29 20:48:54 2024] usb 1-4: New USB device strings: Mfr=1, Product=2, SerialNumber=0
[Wed May 29 20:48:54 2024] usb 1-4: Product: Gadget Serial v2.4
[Wed May 29 20:48:54 2024] usb 1-4: Manufacturer: Linux 5.15.118 with 49000000.usb-otg
[Wed May 29 20:48:54 2024] cdc_acm 1-4:2.0: ttyACM0: USB ACM device
[Wed May 29 20:48:54 2024] usbcore: registered new interface driver cdc_acm
[Wed May 29 20:48:54 2024] cdc_acm: USB Abstract Control Model driver for USB modems and ISDN adapters
Here we can see that the device name is ttyACM0.
You can now access the console using Minicom or GNU Screen eg.:
screen /dev/ttyACM0 115200
When using the serial console you can adjust the terminal width to fill up your screen, in my case the right dimensions are like this:
stty rows 41 cols 190
Configure hostname
Add an entry in: /etc/hosts like this:
127.0.0.1 M5Core135
SSH configuration
As per the docs:
In the new version of debian image, the root login permission is turned off by default.
Create a new user, you can use the adduser command for that and possibly usermod after, to put the user in additional groups.
Optional: MDNS
Install MDNS aka zeroconf aka Avahi:
apt install avahi-daemon
Then you can log in to the device over SSH with a .local address instead of IP address eg:
ssh root@M5Core135.local
Testing the LCD screen and the touch device
Before going further, it is a good idea to make sure that the hardware is recognized by Linux and all necessary drivers are loaded.
LCD screen
These commands can be used to test the display using the frame buffer:
(as root)
# write random pixels
cat /dev/urandom > /dev/fb1
# display the M5Stack logo
FRAMEBUFFER=/dev/fb1 fbv /usr/local/m5stack/logo.jpg
Touch device
apt install libts-bin
apt install evtest
Then:
export TSLIB_FBDEVICE=/dev/fb1
export TSLIB_TSDEVICE=/dev/input/event0
export TSLIB_CONFFILE=/etc/ts.conf
Then you can run the following commands to test the pointer:
ts_test
ts_calibrate
evtest /dev/input/event0
Install Openbox
Install:
apt-get install --no-install-recommends xserver-xorg x11-xserver-utils xinit openbox
Force X to use fb1
NB: I have not found a better way to start X on the LCD screen. For instance:
FRAMEBUFFER=/dev/fb1 startx
still outputs on the external screen instead of the built-in LCD.
My workaround is as follows:
Create a config file with following contents in /usr/share/X11/xorg.conf.d/99-fbdev.conf containing the following:
Section "Device"
Identifier "MP135"
Driver "fbdev"
Option "fbdev" "/dev/fb1"
EndSection
Create a sample Python app
Install some tools and dependencies
apt install xterm
Install Python
apt install python3
Install QT (optional)
We current don't use QT5 but to install it:
apt install qtbase5-dev qt5-qmake qtbase5-dev-tools
apt install python3-pyqt5
GTK
Install GTK4 on Debian:
apt install libgtk-4-dev
apt install python3-gi python3-gi-cairo gir1.2-gtk-4.0
Create a test app
This is an example of GTK application (hello world).
Code borrowed from the GTK docs. Create file: /root/gtk_demo.py
import sys
import gi
gi.require_version("Gtk", "4.0")
from gi.repository import GLib, Gtk
class MyApplication(Gtk.Application):
def __init__(self):
super().__init__(application_id="com.example.MyGtkApplication")
GLib.set_application_name('My Gtk Application')
def do_activate(self):
window = Gtk.ApplicationWindow(application=self, title="Hello World")
window.present()
app = MyApplication()
exit_status = app.run(sys.argv)
sys.exit(exit_status)
Add this line in file /etc/xdg/openbox/autostart
/usr/bin/python3 /root/gtk_demo.py &
Now run startx from the console – the GTK app should appear after a while.
Final steps
To run the app on startup, add this line at the end of file /etc/rc.local
startx
# or startx -- -nocursor to hide the mouse cursor
Reboot the device to test.
THE END