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

    Touchscreen not responding when using GoPlus2 with two servo motors

    Core 2
    2
    4
    270
    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.
    • E
      eleonorafontana16
      last edited by

      Hello everyone,
      I’m new to the forum and definitely new to programming M5Stack components.

      Let me explain my problem. I’m using a GoPlus2 module (with 2 servo motors connected to ports 1 and 2) together with a Core2. I also have an external power supply connected to the GoPlus2. What I did was create some code in UIFlow1 (v1.9.5) with buttons that control the servo motor positions. I actually made two versions of this code.

      In the first version, I didn’t explicitly control the motors but only printed the (theoretical) angle of the motors to the screen.
      In the second version, I added the actual control commands for the two servos.
      When running the first version, everything worked fine: I could see the correct angles displayed on the screen according to the button presses. However, when I ran the second version, the code froze right after pressing the start button, and the touchscreen stopped responding.

      I’ve attached the code for this second case:

      from m5stack import *
      from m5stack_ui import *
      from uiflow import *
      import time
      import module
      
      
      screen = M5Screen()
      screen.clean_screen()
      screen.set_screen_bg_color(0xffffff)
      
      
      cmdServo2 = None
      running = None
      resetAll = None
      minus5 = None
      plus5 = None
      i = None
      k = None
      
      go_plus_2 = module.get(module.GOPLUS2)
      
      Servo1 = M5Label('Servo 1 [deg]: ', x=24, y=48, color=0x000, font=FONT_MONT_14, parent=None)
      Servo2 = M5Label('Servo 2 [deg]: ', x=165, y=48, color=0x000, font=FONT_MONT_14, parent=None)
      touch_buttonStart = M5Btn(text='Start', x=24, y=91, w=70, h=30, bg_c=0xFFFFFF, text_c=0x000000, font=FONT_MONT_14, parent=None)
      touch_buttonStop = M5Btn(text='Stop', x=125, y=91, w=70, h=30, bg_c=0xFFFFFF, text_c=0x000000, font=FONT_MONT_14, parent=None)
      plus5deg = M5Btn(text='+ 5 deg', x=69, y=190, w=70, h=30, bg_c=0xFFFFFF, text_c=0x000000, font=FONT_MONT_14, parent=None)
      minus5deg = M5Btn(text='- 5 deg', x=180, y=190, w=70, h=30, bg_c=0xFFFFFF, text_c=0x000000, font=FONT_MONT_14, parent=None)
      title = M5Label('Test', x=138, y=17, color=0x000, font=FONT_MONT_14, parent=None)
      switch0 = M5Switch(x=118, y=144, w=70, h=30, bg_c=0xCCCCCC, color=0x0288FB, parent=None)
      cmdS1 = M5Label('Servo1', x=69, y=152, color=0x000, font=FONT_MONT_14, parent=None)
      cmdS2 = M5Label('Servo2', x=190, y=152, color=0x000, font=FONT_MONT_14, parent=None)
      reset = M5Btn(text='Reset', x=239, y=91, w=70, h=30, bg_c=0xFFFFFF, text_c=0x000000, font=FONT_MONT_14, parent=None)
      
      from numbers import Number
      
      
      
      def switch0_on():
        global cmdServo2, running, resetAll, minus5, plus5, i, k
        cmdServo2 = True
        minus5 = False
        plus5 = False
        pass
      switch0.on(switch0_on)
      
      def touch_buttonStart_pressed():
        global cmdServo2, running, resetAll, minus5, plus5, i, k
        running = True
        title.set_text('Start')
        wait(2)
        Servo1.set_text(str((str('Servo 1 [deg]:') + str(90))))
        Servo2.set_text(str((str('Servo 2 [deg]:') + str(90))))
        go_plus_2.set_servo_angle(go_plus_2.S1, 90)
        go_plus_2.set_servo_angle(go_plus_2.S2, 90)
        pass
      touch_buttonStart.pressed(touch_buttonStart_pressed)
      
      def touch_buttonStop_pressed():
        global cmdServo2, running, resetAll, minus5, plus5, i, k
        running = False
        i = 0
        k = 0
        plus5 = False
        minus5 = False
        pass
      touch_buttonStop.pressed(touch_buttonStop_pressed)
      
      def reset_pressed():
        global cmdServo2, running, resetAll, minus5, plus5, i, k
        resetAll = True
        running = False
        plus5 = False
        minus5 = False
        cmdServo2 = False
        switch0.set_off()
        pass
      reset.pressed(reset_pressed)
      
      def plus5deg_pressed():
        global cmdServo2, running, resetAll, minus5, plus5, i, k
        minus5 = False
        plus5 = True
        pass
      plus5deg.pressed(plus5deg_pressed)
      
      def minus5deg_pressed():
        global cmdServo2, running, resetAll, minus5, plus5, i, k
        plus5 = False
        minus5 = True
        pass
      minus5deg.pressed(minus5deg_pressed)
      
      
      running = False
      resetAll = False
      i = 90
      k = 90
      while True:
        while not running:
          title.set_text('Stop')
          if resetAll:
            title.set_text('Reset')
            Servo1.set_text(str((str('Servo 1 [deg]:') + str(90))))
            Servo2.set_text(str((str('Servo 2 [deg]:') + str(90))))
            go_plus_2.set_servo_angle(go_plus_2.S1, 90)
            go_plus_2.set_servo_angle(go_plus_2.S2, 90)
            wait(2)
            resetAll = False
        while running:
          if resetAll:
            title.set_text('Reset')
            Servo1.set_text(str((str('Servo 1 [deg]:') + str(90))))
            Servo2.set_text(str((str('Servo 2 [deg]:') + str(90))))
            go_plus_2.set_servo_angle(go_plus_2.S1, 90)
            go_plus_2.set_servo_angle(go_plus_2.S2, 90)
            wait(2)
            resetAll = False
          if cmdServo2:
            title.set_text('Comanding Servo 2')
            if plus5:
              if k == 180:
                k = 90
              Servo2.set_text(str((str('Servo 2 [deg]: ') + str(k))))
              go_plus_2.set_servo_angle(go_plus_2.S2, k)
              wait(1)
              k = (k if isinstance(k, Number) else 0) + 5
            if minus5:
              if k == 0:
                k = 90
              Servo2.set_text(str((str('Servo 2 [deg]: ') + str(k))))
              go_plus_2.set_servo_angle(go_plus_2.S2, k)
              wait(1)
              k = (k if isinstance(k, Number) else 0) + -5
          if not cmdServo2:
            title.set_text('Comanding Servo 1')
            if plus5:
              if i == 180:
                i = 90
              Servo1.set_text(str((str('Servo 1 [deg]: ') + str(i))))
              go_plus_2.set_servo_angle(go_plus_2.S1, i)
              wait(1)
              i = (i if isinstance(i, Number) else 0) + 5
            if minus5:
              if i == 0:
                i = 90
              Servo1.set_text(str((str('Servo 1 [deg]: ') + str(i))))
              go_plus_2.set_servo_angle(go_plus_2.S1, i)
              wait(1)
              i = (i if isinstance(i, Number) else 0) + -5
      
      

      To rule out an issue with the motors, I also created a simple routine that moves the servos back and forth between 60 and 120 degrees. Without interacting with the touchscreen, I didn’t experience any problems.

      Do you have any advice or suggestions on how I could solve this issue?

      P.S. I’m not using UIFlow2 because when I connect everything and try to run any code, the motors start vibrating heavily and I get the following error:

      E (28183) i2c: i2c driver install error 
      E (28183) i2c: i2c driver install error
      Traceback (most recent call last): 
        File "<stdin>", line 5, in <module> 
        File "module/goplus2.py", line 43, in __init__ 
      Exception: GoPlus2 Module not found in Base
      

      Thanks a lot in advance!

      felmueF 1 Reply Last reply Reply Quote 0
      • felmueF
        felmue @eleonorafontana16
        last edited by

        Hello @eleonorafontana16

        Unfortunately M5Core2 and GoPlus2 are not compatible. From the GoPlus2 shop page:

        Note: This module has an I2C address conflict with the touch screen of the CORE2, so it cannot be used together.

        Thanks
        Felix

        GPIO translation table M5Stack / M5Core2
        Information about various M5Stack products.
        Code examples

        E 1 Reply Last reply Reply Quote 0
        • E
          eleonorafontana16 @felmue
          last edited by

          Hello @felmue,
          Oh, I didn’t know that, thanks for pointing it out! Do you think this incompatibility only affects the touchscreen, or could it also impact other aspects, like the long-term control of two servo motors?

          Also, if I wanted to get another component that allows me to build a GUI to interact with, is there a particular product you would recommend?

          Thanks a lot for your help!
          Eleonora

          felmueF 1 Reply Last reply Reply Quote 0
          • felmueF
            felmue @eleonorafontana16
            last edited by

            Hello @eleonorafontana16

            I don't know whether it will affect one or the other or both long term. The fact that both use the same I2C address is like talking to two people with the same name. Some answers might get lost due to both people responding at the same time with different answers.

            Thanks
            Felix

            GPIO translation table M5Stack / M5Core2
            Information about various M5Stack products.
            Code examples

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