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!