I have a couple of servos connected to an Arduino board, which is in turn connected to a Raspberry Pi (4) using an ethernet cable. enter image description here

Just wondering, in what ways can I control the servos on Raspian.

Currently I could access Arduino from rPi like this:

import serial
ser = serial.Serial("/dev/ttyUSB0", 115200)
while True:
        count = ser.in_waiting
        if count > 2:
            inputVal = ser.read(count-1)

And I can send value the same way. But how do I control the servos connected to the pins on Arduino?

  • Do want Rpi to control the Arduino's, or do you want to throw away the stupid Arduinos, and let the much more intelligent, beside more powerful, Rpi to take care of everything? If you are not very sure how Rpi can control servos, I would suggest to search AdaFruit's PWM/Servo breakout/module which can control as many as 16 DC/BLDC/Stepper, and also Servos. (1) learn.adafruit.com/16-channel-pwm-servo-driver, (2) adafruit.com/product/815. AdaFruit usually has newbie friendly tutorials. Of course you can also google SparkFun/eBay/AliExpress/Amazon for cheaper versions.
    – tlfong01
    Oct 1, 2019 at 5:06
  • @tlfong01 I already know how to use a servo driver to interface between rPi and servos. But this time I have a working system of rPi and sensor and another working setup of arduino and servos. It would save a lot of work if I could getting rPi to control the servos, similar to that of servo driver.
    – TelKitty
    Oct 1, 2019 at 5:28
  • I see, so your user requirement boils down to "How can one Rpi talk to multiple Arduino's through Ethernet". What you do NOT want include the following: (1) WiFi, (2) UART (RS232/485) , (3) I2C, (SPI). (4) 433/900Mhz, ... Then you may like to consider the following: (1) http, (2) ftp, (3) tcp, (4) udp, I am using Rpi4B python 3.7.3 which has newbie friendly TCP socket / UDP modules. I assume you don't use Android devices at the front end, ...
    – tlfong01
    Oct 1, 2019 at 6:15
  • @tlfong01 Would consider other communication methods, but pins on rPi and arduino are used for sensors and actuators. I already know how to access arduino from rPi. Ideally, I would like to use the same program to capture data on rPi sensors to decide what the servos on arduino should be doing.
    – TelKitty
    Oct 1, 2019 at 6:44
  • I don't understand what you are saying: "I already know how to access arduino from rPi". Do you used Ethernet cable as mentioned in your question, and if yes, is it at http/ftp/tcp/udp level? Or as you comment: " Would consider other communication methods". What "other" methods have you in your mind? I don't understand what your "program" is doing, read/write GPIO pins for sensors? Are you using C++ or python? For rpi python, which modules do you import, GPIO or GPIOzero?
    – tlfong01
    Oct 1, 2019 at 7:14


Browse other questions tagged or ask your own question.