Thursday, 29 August 2024

ARP - Driving the Motors

The next step with the Kitronik Autonomous Robotics Platform is to get the motors working.

I am following the instructions at https://kitronik.co.uk/blogs/resources/online-tutorial-autonomous-robotics-platform-for-pico-motors for this step.

The code copied into Thonny is as follows;

from PicoAutonomousRobotics import KitronikPicoRobotBuggy
from time import sleep
from machine import Timer
buggy = KitronikPicoRobotBuggy()
run = False
buttonState = 0 
def checkButton(p):
    global buttonState
    global run
    buttonState = buttonState <<1 | buggy.button.value() |0xE000
    buttonState &=0xFFFF
    if buttonState == 0xEFFF: #button has been pressed and passes the debouncing test
        if run == True:
            run = False
        else:
            run = True
debounceTimer = Timer(-1)
debounceTimer.init(period=2, mode=Timer.PERIODIC, callback=checkButton)
while True:
    if(run):
        buggy.motorOn("l","f",100)
        buggy.motorOn("r","f",100)
    else:
        buggy.motorOff("r")
        buggy.motorOff("l")

This senses a button press and turns the motors on or off when the button is pressed.



CH32V203 Big Round Button

Having successfully uploaded the Blink code to the  CH32V203 , the next task is to try the HID button demo. The circuit I’m using has two bu...