1

I'm trying to connect an Arduino to my Raspberry Pi using a USB-to-serial cable. The goal is to be able to control a robotic arm using Firmata. I'm using Node.js' Johnny-Five module which allows me to control all sorts of components very easily. On my Mac, the program runs absolutely fine (very well actually), however, when ran on the Raspberry Pi, it acts (not so) funny.

I've created a comparison video which shows how the exact same program runs on both my Mac and the Raspberry Pi, you can view it here. If you watch the video, you'd notice that on the Raspberry Pi the test seems corrupted and very glitchy compared to the Mac version. However, at the end of the video, you'd notice that it suddenly eases out and starts to run the program properly, but it only does so in the last couple of seconds of the test.

The test runs a servos angle change every 50 ms (that can include more than one servo per interval, e.g. every 50 ms, it can change 2, 3 or 4 servos depending on the demand), so I understand this can be an intensive task for the Raspberry Pi to handle.

I've came across this GitHub issue which basically says that using USB for serial communications is bad in such a situation. I can also confirm the high CPU usage mentioned in there.

How do I fix this problem?

The serial port runs at a 57600 baud rate (also tested on 115200, same problem). Also, I've tried to connect to the serial port using the GPIO pins, but I had no luck with that as Johnny-Five doesn't support it (yet, and more accurately it's node-firmata that lacks the GPIO pins support, which is a dependency of Johnny-Five).

2 Answers 2

1

Your issue is likely an issue with either not enough power, or "dirty" fluctuating power.

I had this exact issue when working with an Arduino and a nettop computer. We kept seeing random corruption and the Arduino randomly disappearing from USB. It turned out that a water pump plugged in on the same power circuit was introducing electrical line noise and the USB-to-serial converter was getting confused.

In your case, it could be noise from motors, or it could be power fluctuations in general (which the Raspberry Pi is very prone to have unless you use a good high-quality power supply).

Try supplying power to the USB-to-serial converter by plugging it into a powered hub instead of directly into the Raspberry Pi.

4
  • That's exactly what I'm doing. Both Arduino and Raspberry Pi are running of a powered USB hub Belkin F5U233. Also, servos are running of a separate 6V battery.
    – Taha
    Jan 29, 2014 at 15:04
  • @Taha but is the USB to serial converter in between them getting enough power? That's what my answer is concerned about. If you have a second powered hub, put it between the RasPi and the USB-serial cable and see if that helps.
    – Moshe Katz
    Jan 29, 2014 at 15:31
  • It's really unlikely that a reasonably designed USB serial converter would draw enough power to cause a significant voltage drop on the pi's polyfuse. Jan 29, 2014 at 20:40
  • @ChrisStratton It's also really unlikely that a reasonably designed converter would be affected by the issue that I experienced - but it did, so "likely" has nothing to do with it.
    – Moshe Katz
    Jan 30, 2014 at 3:01
0

You should rethink your architecture. Constantly sending angle over a serial connection is a very bad idea. You should send (time + angular velocity) pair or (time + final position) pair and let your robot figure out the motion details by itself. This should reduce the data stream by a magnitude of 10, maybe 100.

After that, you may easily reduce serial speed to the realistic 9600 or 4800 baud without any performance hit on your robot motions, and get the same performance from the simple Raspberry Pi or top-of-the-line multi-CPU computer.

2
  • 1
    Unfortunately I need to constantly send the angle to the servos, my system requires so as the servos should mirror sensor data, which is essentially real-time. Unless there is a better way to go about it?
    – Taha
    Jan 29, 2014 at 13:12
  • No, it's not a very bad idea, and no, the data rate is in no way unreasonable. Electric noise issues should be easily remedied in a compact system such as this, and if not, introducing an error detection/correction scheme is a wiser course than simple reducing baud rate. Note that the current scheme of repeatedly sending angle introduces a fair amount of fault tolerance anyway (as the servo can only move so far in a mistaken direction in 50ms), which your replacement may not have. Jan 29, 2014 at 20:44

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.