Skip to content

rover project – part 3

Since the last post, I have set up a raspberry pi and connected it to the arduino over usb. I configured wifi on the raspberry pi and I’ve written a simple python script to control the rover.

Now, I can ssh into the raspberry pi, launch the python script and I can remotely control the rover using the same keys from the arduino sketch (‘l’ for left, ‘r’ for right, etc.).



Here is the python script to control the arduino.

#!/usr/bin/env python3

import serial
import time

with serial.Serial('/dev/ttyACM0', 115200, timeout=2) as ser:
    time.sleep(2) # wait for arduino to boot
    while True:
        x = input("cmd:> ")
        if x in ['l', 'r', 'c', 'f', 'b', 'k']:
            ser.write(bytes(x, 'utf-8'))

The code is pretty simple. It opens a connection to the arduino (/dev/ttyACM0) and loops forever. When a valid key is entered, (l, r, c, f, b, k), it sends it to the arduino and the arduino processes the command. Then the loop repeats.

Next, I will start adding sensors and possibly a camera.

Comments are closed, but trackbacks and pingbacks are open.