Robot with StickC, RoverC and TOF



  • I am trying to build a robot with roverC and UNIT TOF with UIFlow.
    When I am trying to start a Motors I am getting I2C-Error 19.
    After a reset I am getting " RoverC HAt may not be connected".
    Can anybody help me with the problem?



  • Hi @jhonnytank ,

    Can you show your blocks with us and which port do you connect the TOF unit?



  • @jhonnytank said in Robot with StickC, RoverC and TOF:

    I am trying to build a robot with roverC and UNIT TOF with UIFlow.
    When I am trying to start a Motors I am getting I2C-Error 19.
    After a reset I am getting " RoverC HAt may not be connected".
    Can anybody help me with the problem?

    Is the StickC securly fitted and is the rover C power switch set to ON?



  • Thanks for your reply! I think it was the power switch. I switched the rover only on when I realy want to drive it.



  • I have copied the blocks as Micropython code:
    I put the Tof to the grove port of the stickC.
    for a little time it has worked.
    Now it reads some values and then it produces an I2C (Error 19)

    from m5stack import *
    from m5ui import *
    from uiflow import *
    lcd.setRotation(0)
    import time
    from m5mqtt import M5mqtt
    import unit
    import hat

    setScreenColor(0x111111)
    tof0 = unit.get(unit.TOF, unit.PORTA)

    hat_roverc0 = hat.get(hat.ROVERC)

    m5mqtt = M5mqtt('MyBot', '192.168.178.39', 1883, '', '', 300)

    label0 = M5TextBox(10, 10, "Hello", lcd.FONT_Default,0xFFFFFF, rotate=1)
    label4 = M5TextBox(50, 24, "Text", lcd.FONT_Default,0xFFFFFF, rotate=0)
    label1 = M5TextBox(10, 24, "Text", lcd.FONT_Default,0xFFFFFF, rotate=0)
    label5 = M5TextBox(50, 41, "Text", lcd.FONT_Default,0xFFFFFF, rotate=1)
    label6 = M5TextBox(50, 56, "Text", lcd.FONT_Default,0xFFFFFF, rotate=0)
    label2 = M5TextBox(10, 41, "Text", lcd.FONT_Default,0xFFFFFF, rotate=0)
    label3 = M5TextBox(10, 56, "Text", lcd.FONT_Default,0xFFFFFF, rotate=0)

    import math
    from numbers import Number

    myStr = None
    steuerung = None
    geschwindigkeit = None
    richtung = None
    drehung = None
    dummy = None
    pwrTen = None
    zahl = None
    auto = None
    mySpeed = None
    myTime = None
    i = None
    backSpeed = None
    start = None
    myChar = None
    dist = None

    def toInt(myStr):
    global steuerung, geschwindigkeit, richtung, drehung, dummy, pwrTen, zahl, auto, mySpeed, myTime, i, backSpeed, start, myChar, dist
    pwrTen = 0
    zahl = 0
    i = 0
    while i < len(myStr):
    myChar = myStr[int(i - 1)]
    if myChar == '0':
    zahl = zahl * math.pow(10,pwrTen)
    else:
    if myChar == '1':
    zahl = zahl + 1 * math.pow(10,pwrTen)
    else:
    if myChar == '2':
    zahl = zahl + 2 * math.pow(10,pwrTen)
    else:
    if myChar == '3':
    zahl = zahl + 3 * math.pow(10,pwrTen)
    else:
    if myChar == '4':
    zahl = zahl + 4 * math.pow(10,pwrTen)
    else:
    if myChar == '5':
    zahl = zahl + 5 * math.pow(10,pwrTen)
    else:
    if myChar == '6':
    zahl = zahl + 6 * math.pow(10,pwrTen)
    else:
    if myChar == '7':
    zahl = zahl + 7 * math.pow(10,pwrTen)
    else:
    if myChar == '8':
    zahl = zahl + 8 * math.pow(10,pwrTen)
    else:
    if myChar == '9':
    zahl = zahl + 9 * math.pow(10,pwrTen)
    else:
    pass
    i = (i if isinstance(i, Number) else 0) + 1
    pwrTen = (pwrTen if isinstance(pwrTen, Number) else 0) + 1
    return zahl

    def fun_OmniBot_steuer_(topic_data):
    global steuerung, geschwindigkeit, richtung, drehung, dummy, pwrTen, zahl, auto, mySpeed, myTime, i, backSpeed, start, myChar, myStr, dist
    steuerung = topic_data
    label1.setText(str(steuerung))
    pass
    m5mqtt.subscribe(str('OmniBot/steuer'), fun_OmniBot_steuer_)

    def fun_OmniBot_geschwindigkeit_(topic_data):
    global steuerung, geschwindigkeit, richtung, drehung, dummy, pwrTen, zahl, auto, mySpeed, myTime, i, backSpeed, start, myChar, myStr, dist
    geschwindigkeit = topic_data
    label2.setText(str(geschwindigkeit))
    mySpeed = toInt(geschwindigkeit)
    backSpeed = -1 * mySpeed
    pass
    m5mqtt.subscribe(str('OmniBot/geschwindigkeit'), fun_OmniBot_geschwindigkeit_)

    def fun_OmniBot_richtung_(topic_data):
    global steuerung, geschwindigkeit, richtung, drehung, dummy, pwrTen, zahl, auto, mySpeed, myTime, i, backSpeed, start, myChar, myStr, dist
    richtung = topic_data
    label3.setText(str(richtung))
    pass
    m5mqtt.subscribe(str('OmniBot/richtung'), fun_OmniBot_richtung_)

    def fun_OmniBot_rotation_(topic_data):
    global steuerung, geschwindigkeit, richtung, drehung, dummy, pwrTen, zahl, auto, mySpeed, myTime, i, backSpeed, start, myChar, myStr, dist
    drehung = topic_data
    label4.setText(str(drehung))
    pass
    m5mqtt.subscribe(str('OmniBot/rotation'), fun_OmniBot_rotation_)

    def fun_OmniBot_auto_(topic_data):
    global steuerung, geschwindigkeit, richtung, drehung, dummy, pwrTen, zahl, auto, mySpeed, myTime, i, backSpeed, start, myChar, myStr, dist
    dummy = topic_data
    label5.setText(str(dummy))
    pass
    m5mqtt.subscribe(str('OmniBot/auto'), fun_OmniBot_auto_)

    auto = False
    myTime = 0
    mySpeed = 0
    start = (time.ticks_ms()) - myTime
    label0.setText('OmnibotRC V2-0-2')
    label4.setText('Hello M5')
    while True:
    dist = tof0.distance
    label6.setText(str(dist))
    wait_ms(50)
    if myTime == 0 or start > 300000:
    myTime = time.ticks_ms()
    m5mqtt.start()
    else:
    pass
    if dist > 50:
    M5Led.off()
    if richtung == 'stop' or steuerung == 'stop' or drehung == 'stop':
    hat_roverc0.SetAllPulse(0, 0, 0, 0)
    else:
    if richtung == 'forward':
    hat_roverc0.SetAllPulse(mySpeed, mySpeed, mySpeed, mySpeed)
    else:
    pass
    if richtung == 'back':
    hat_roverc0.SetAllPulse(backSpeed, backSpeed, backSpeed, backSpeed)
    else:
    pass
    if steuerung == 'left':
    hat_roverc0.SetAllPulse(mySpeed, backSpeed, backSpeed, mySpeed)
    else:
    pass
    if steuerung == 'right':
    hat_roverc0.SetAllPulse(backSpeed, mySpeed, mySpeed, backSpeed)
    else:
    pass
    if drehung == 'RotLeft':
    hat_roverc0.SetAllPulse(backSpeed, mySpeed, backSpeed, mySpeed)
    else:
    pass
    if drehung == 'RotRight':
    hat_roverc0.SetAllPulse(mySpeed, backSpeed, mySpeed, backSpeed)
    else:
    pass
    else:
    M5Led.on()
    wait_ms(2)