This is part three in my series of building a small robot car. You can find the previous articles below:
Part Two: My First Arduino Built Robot Car
I ended the last part wondering whether I should add some sensors to my robot, or replace the Arduino controller for a pyboard controller.
Because my initial idea for this project was to use the pyboard, I decided I would start by replacing the controller and then later I could add some sensors.
I've owned the pyboard for a few years now, but I've never really done much with it. I, therefore, suspected that the firmware might be out of date. So, the first item on the list was to update the firmware.
Once the pyboard was up to date, it was time to find out how to control one of the DC motors with it.
from pyb import Pin, Timer p1 = Pin('X1') tim2 = Timer(2, freq=1000) ch1 = tim2.channel(1, Timer.PWM, pin=p1) ch1.pulse_width_percent(50)
And this is how I connected it together, with the Maker Drive:
Based on the fact that I was using the X1 and X2 pins to run the first motor, and the layout, I reckoned I could use the X3 and X4 pins for the second motor.
So after adding the second motor, I made some changes to the code:
from pyb import Pin, Timer p1 = Pin('X1') tim2 = Timer(2, freq=1000) ch1 = tim2.channel(1, Timer.PWM, pin=p1) ch1.pulse_width_percent(50) p3 = Pin('X3') ch3 = tim2.channel(1, Timer.PWM, pin=p3) ch3.pulse_width_percent(50)
And voila! Both motors were running. What a beauty!
Once everything was working correctly, I put it together with the chassis and updated the code a bit to make it drive into a kind of a circle :D
You can see the current code and setup on my GitHub.
I'm really pleased how well this went and honestly thought it would take longer.
I'm going to put this project on to the side for a bit now. But the next item on the agenda for this project is to add some sensors to it and make them influence the driving.
Thank you for reading. For weekly updates from me, you can sign up to my newsletter.