TTL Python example for Raspberry?

General discussion of using Roboclaw motor controllers
Post Reply
orobotics
Posts: 6
Joined: Wed May 03, 2017 12:09 pm
TTL Python example for Raspberry?

Post by orobotics »

I'm using 3 Roboclaws now in Windows over USB but Windows com port support is horrible (frequently have to reboot after a com port has been closed to reopen it). I'm thinking of moving the Roboclaws to a Raspberry Pi and talking to them over TTL and then doing a websockets connection back to Windows where I can receive encoder data and send position commands.

I see the sample Python code but that's for serial/USB. Does anyone have any Python code for connecting to Roboclaws over TTL? Is any level shifting needed to deal with Raspberry PIs 3.3V signaling?
User avatar
Basicmicro Support
Posts: 1594
Joined: Thu Feb 26, 2015 9:45 pm
Re: TTL Python example for Raspberry?

Post by Basicmicro Support »

On the Raspberry Pi there, its serial port is already 3.3v so you can connect it straight to the Roboclaw S1/S2 pins. Roboclaw is a 5v tolerante device but it outputs 3.3v signalling so it is safe to use it directly with the PI.

The Python examples work with the Raspberry Pi serial port. You just have to change the device name from /dev/ttyACM0 to the serial ports device name(usually /dev/ttyAMA0 IIRC). Note you need to enable the Pi's serial port for user programs. Normally its either disabled or is enabled for the Linux console. Use raspi-config to change the settings. Disable the console but enable the port.
orobotics
Posts: 6
Joined: Wed May 03, 2017 12:09 pm
Re: TTL Python example for Raspberry?

Post by orobotics »

I ran raspi-config and enabled it and disabled for console. I then ran the simplepwm example but had just the first command for 25% power to keep it simple. No voltage showing on M1A, M1B.

I then tried adding

dtoverlay=pi3-disable-bt
enable_uart=1

to /boot/config.txt and same result. I also tried /dev/serial0 and /dev/ttyAMA0. Both are present in /dev, I checked.

Pin 8 is connected to S1 and Pin 10 is connected to S2. This is a 2x15A, V5E. I connected via USB to Windows and verified it works. As soon as I connect pin 8/10 to S1/S2 the green LED starts to pulse on the roboclaw.

Anything else I can check?
orobotics
Posts: 6
Joined: Wed May 03, 2017 12:09 pm
Re: TTL Python example for Raspberry?

Post by orobotics »

I just tried connecting the roboclaw via USB to the Raspberry PI and that works successfully. But prefer to use the Raspberry UART for reliability reasons.
User avatar
Basicmicro Support
Posts: 1594
Joined: Thu Feb 26, 2015 9:45 pm
Re: TTL Python example for Raspberry?

Post by Basicmicro Support »

Run a loopback test. I found an example online(not I have not tried this but it looks correct).

https://medium.com/@amitasinghchauhan/s ... 7e40da9055

Alos when using the TTL serial you need to make sure the baudrate the Roboclaw is set to matches the erial port baudrate. USB to Serial doesnt care what the baudrate it since it is virtual but the TTL serial does.
orobotics
Posts: 6
Joined: Wed May 03, 2017 12:09 pm
Re: TTL Python example for Raspberry?

Post by orobotics »

I installed minicom and ran it (mincom -D /dev/ttyAMA0) and I see what I type echoed back with no errors.

I went into Ion Studio and set it to 115200 from the default 38400. In the script I have
rc = Roboclaw("/dev/ttyAMA0",115200)

I also tried 38400.

I took a second Roboclaw (2x30A, V4). Updated the firmware, set it to 115200, saved. Ran the same script and the same thing. I'm trying to attach a screenshot, it's only 400kb but the forum is saying it's too big to attach.
User avatar
Basicmicro Support
Posts: 1594
Joined: Thu Feb 26, 2015 9:45 pm
Re: TTL Python example for Raspberry?

Post by Basicmicro Support »

Then I will need your code to see if there is some problem with it.

Also double check you have the TX and RX pins from the RPi wired correctly to the Roboclaw. TX to S1 and RX to S2 and GND to GND.

Are you powering the RPi from the Roboclaw or separately?
orobotics
Posts: 6
Joined: Wed May 03, 2017 12:09 pm
Re: TTL Python example for Raspberry?

Post by orobotics »

I was missing the GND from the Raspberry Pi to the Roboclaw. As soon as I added that it started working. Thanks!

Post Reply