Standard Serial with the Raspberry Pi 3 Tutorial

General discussion of using Roboclaw motor controllers
Post Reply
florian
Posts: 1
Joined: Fri Jun 28, 2019 5:42 am

Standard Serial with the Raspberry Pi 3 Tutorial

Post by florian » Fri Jun 28, 2019 5:51 am

Hi we try to do the Standard Serial with the Raspberry Pi 3 Tutorial but it doesn't work.

from serial import Serial
from time import sleep

if __name__ == "__main__":

serial_port = "/dev/ttyS0"
baudrate = 38400

roboclaw = Serial(serial_port, baudrate, timeout=1)

while True:

roboclaw.write(chr(94))
sleep(2)
roboclaw.write(chr(64))
sleep(2)
roboclaw.write(chr(32))
sleep(2)
roboclaw.write(chr(64))
sleep(2)

roboclaw.write(chr(223))
sleep(2)
roboclaw.write(chr(192))
sleep(2)
roboclaw.write(chr(160))
sleep(2)
roboclaw.write(chr(192))
sleep(2)

We have this error message :

Traceback (most recent call last):
File "/home/pi/Desktop/moteur.py", line 13, in <module>
roboclaw.write(chr(94))
File "/usr/lib/python3/dist-packages/serial/serialposix.py", line 518, in write
d = to_bytes(data)
File "/usr/lib/python3/dist-packages/serial/serialutil.py", line 63, in to_bytes
raise TypeError('unicode strings are not supported, please encode to bytes: {!r}'.format(seq))
TypeError: unicode strings are not supported, please encode to bytes: '^'

We think it's beacause we use Python 3 but we don't know how resolve that.
Do you have a solution to help us ?
Thanks

User avatar
Basicmicro Support
Posts: 1259
Joined: Thu Feb 26, 2015 9:45 pm

Re: Standard Serial with the Raspberry Pi 3 Tutorial

Post by Basicmicro Support » Mon Jul 01, 2019 9:41 am

The examples are all using roboclaw.py which is written for Python 2.7. Switch to using roboclaw_3.py to use them with Python 3.

Post Reply