🤖Have you ever tried Chat.M5Stack.com before asking??😎
    M5Stack Community
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Register
    • Login

    Running Python GUI apps on CoreMP135 with Debian

    Cores
    3
    8
    2.0k
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • P
      prima
      last edited by

      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.
      Gparted

      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

      ajb2k3A E 2 Replies Last reply Reply Quote 4
      • ajb2k3A
        ajb2k3 @prima
        last edited by

        @prima Thanks for this.

        UIFlow, so easy an adult can learn it!
        If I don't know it, be patient!
        I've ether not learned it or am too drunk to remember it!
        Author of the WIP UIFlow Handbook!
        M5Black, Go, Stick, Core2, and so much more it cant be fit in here!

        E 1 Reply Last reply Reply Quote 0
        • P prima referenced this topic on
        • E
          EricB @ajb2k3
          last edited by

          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 sdcard

          fdisk -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 ! :-)

          ajb2k3A 1 Reply Last reply Reply Quote 0
          • ajb2k3A
            ajb2k3 @EricB
            last edited by

            @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
            

            UIFlow, so easy an adult can learn it!
            If I don't know it, be patient!
            I've ether not learned it or am too drunk to remember it!
            Author of the WIP UIFlow Handbook!
            M5Black, Go, Stick, Core2, and so much more it cant be fit in here!

            E 1 Reply Last reply Reply Quote 0
            • E
              EricB @ajb2k3
              last edited by

              @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 bottom

              Using the same link for MP135 doesn't bring the usefull link you mention :
              https://docs.m5stack.com/en/core/M5CoreMP135

              THIS 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 !

              ajb2k3A 1 Reply Last reply Reply Quote 0
              • ajb2k3A
                ajb2k3 @EricB
                last edited by

                @EricB if you are on Facebook you can find a free sample of my books as well as some write up on hackster.io

                UIFlow, so easy an adult can learn it!
                If I don't know it, be patient!
                I've ether not learned it or am too drunk to remember it!
                Author of the WIP UIFlow Handbook!
                M5Black, Go, Stick, Core2, and so much more it cant be fit in here!

                1 Reply Last reply Reply Quote 0
                • E
                  EricB @prima
                  last edited by EricB

                  @ajb2k3
                  Awesome demo ! thanks .
                  Any advice on "softer" way to reload an updated GTK app ?

                  been using "reboot" and "kill <proces num>"

                  most of my experience on linux has been backend with CLI only ...
                  otherwise ESP32 with micropython/circuitpython for display management

                  Thx
                  will certainly look for your facebook material

                  ajb2k3A 1 Reply Last reply Reply Quote 0
                  • ajb2k3A
                    ajb2k3 @EricB
                    last edited by

                    @EricB said in Running Python GUI apps on CoreMP135 with Debian:

                    @ajb2k3
                    Awesome demo ! thanks .
                    Any advice on "softer" way to reload an updated GTK app ?

                    been using "reboot" and "kill <proces num>"
                    I haven't gotten that far yet, still working on backend information

                    UIFlow, so easy an adult can learn it!
                    If I don't know it, be patient!
                    I've ether not learned it or am too drunk to remember it!
                    Author of the WIP UIFlow Handbook!
                    M5Black, Go, Stick, Core2, and so much more it cant be fit in here!

                    1 Reply Last reply Reply Quote 0
                    • First post
                      Last post