Page 1 of 1

Standard Serial with the Raspberry Pi 3 Tutorial

Posted: Fri Jun 28, 2019 5:51 am
by florian
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

Re: Standard Serial with the Raspberry Pi 3 Tutorial

Posted: Mon Jul 01, 2019 9:41 am
by Basicmicro Support
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.