简体   繁体   中英

Control motor and servo over serial (Arduino)

I would like to set up two arduino's that will talk to each other over serial. One will act as a remote the other as a receiver. I have two buttons already setup that are working but i am having trouble with the servo and motor.

val = analogRead(potPin1); 
if (val1 != val ){ 
  val = map(val, 0, 1023, 5, 150);
  Serial.println("3/2/10/" + val );   //Write steering val
  val1 = val;

This is the code that is acting up. It prints characters continuously instead of integers and only when the pot changes. Also if possible i would like to control the two with one joystick but i thought it would be better to get it working separately first. The remote code = http://pastebin.com/JCq7sNxT The reciever code = http://pastebin.com/KiyYJMFT

Thanks in advance.

What do you mean with "acting up"? I'm not sure what you mean, but perhaps you need to try Serial.println(analogValue, DEC);

This print the line as an ASCII-encoded decimal. For more info see http://arduino.cc/en/Serial/Println#.UwHrRXVdVJw

Or perhaps print() suits your needs better ( http://arduino.cc/en/Serial/Print#.UwHtKXVdVJw ).

Also, there is a chance you will overwrite your send buffer. Since your baudrate is pretty low (9600 baud/s), and you send characters every time an analogue value changes in your main loop, it could be you try to send more data than the connection can handle.

I'm not sure if this will pose a problem, but my suggestion is to stress test your system by continuously wiggling your joystick to be sure :).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM