Uncategorized

servo notes

Asked 
Viewed 41 times
1

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?

 New contributor

put on hold as primarily opinion-based by MilliwaysjoanFredIngoDmitry Grigoryev 13 hours ago

Many good questions generate some degree of opinion based on expert experience, but answers to this question will tend to be almost entirely based on opinions, rather than facts, references, or specific expertise.If this question can be reworded to fit the rules in the help center, please edit the question.

  • 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 20 hours ago    
  • @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 19 hours ago
  • 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 18 hours ago   
  • @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 18 hours ago
  • 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 17 hours ago   
  • I saw your picture and know why I got confused. What you said “Ethernet” cable is actually an USB cable. So you are trying to use USB to serial on both sides. But I think you need an USB to serial adapter/cable on both sides, otherwise it won’t work! I suggest you to google “AdaFruit”, “USB” , “USB to TTL” to know more of what I am talking about. But in case you can really do Rpi to Adruino serial communication WITHOUT the USB to serial cable, I will be very grateful to know more. – tlfong01 12 mins ago    
  • Now your problem can be solved this way: Add sensors such as ultrasonic sensor, track detection optical sensor, camera (a bit advanced, not recommended to newbies) etc to detect the (blocking) object or line tracking black line, object robot arm wants to grap, block to avoid collision, etc . IF your wheels are controlled by 360 degrees forever turning servos, then you can get data from the above sensors and control both the robot arm, and the wheels (to trace the line, say). If four wheels are controlled by 4 (modified) servos, your have a 4WD, and the project will be very interesting. – tlfong01 1 min ago   Edit   

Categories: Uncategorized

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: