Running Python GUI apps on CoreMP135 with Debian
-
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.pyimport 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
-
@prima Thanks for this.
-
-
I am one of those other lame-Windows guys which can't run Gparted from a WSL ( access to raw disk )...
Any advices on extending the partition just with the pre-mounted packages of the "images" found with your link ?
The 3x Debian builds do not even have 'parted' installed and executing apt-get update BEFORE extending the partiotion extension doesn't leave enough room to install parted ,,,
I tried a few times using fdisk directly but the result is always the same -> bricked
--> mandatory BelenaEtcher sdcardfdisk -l ( results )
Device Start End Sectors Size Type
/dev/mmcblk0p1 34 200 167 83.5K Linux filesystem
/dev/mmcblk0p2 201 367 167 83.5K Linux filesystem
/dev/mmcblk0p3 368 3385 3018 1.5M Linux filesystem
/dev/mmcblk0p4 3386 7481 4096 2M Linux filesystem
/dev/mmcblk0p5 7482 2104633 2097152 1G Linux filesystem
root@CoreMP135:~#-deleted last partition ( p5 )
- created new parttion
start @ 7482
End @ default much large value presented
type @ default - write ( save )
reboot
BRICKED !
any advice ?
So close ( but still so far .... ) to getting to start using my CoreMp135 ! :-) - created new parttion
-
@EricB I'm going to have to Ask this but Did you read the instructions?
I know I didn't and missed the command!In the root folder run :
./user/local/m5stack/resize_mmc.sh
-
@ajb2k3 You were darn right about not reading the instructions.
I found them minutes after my post...
I've been using pretty much all other M5 products for which I accessed from the "Store"/<product> --> Documents link at the bottomUsing the same link for MP135 doesn't bring the usefull link you mention :
https://docs.m5stack.com/en/core/M5CoreMP135THIS ONE should be added to the previous: https://docs.m5stack.com/en/guide/linux/coremp135/image
Thank you for feeding my addiction ! ...
I am now officially sleep deprived ! -
@EricB if you are on Facebook you can find a free sample of my books as well as some write up on hackster.io