简体   繁体   English

通过串行控制电机和伺服(Arduino)

[英]Control motor and servo over serial (Arduino)

I would like to set up two arduino's that will talk to each other over serial. 我想设置两个arduino,它们将通过串行相互通信。 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 远程代码= http://pastebin.com/JCq7sNxT收件人代码= 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); 我不确定您的意思,但也许您需要尝试Serial.println(analogValue, DEC);

This print the line as an ASCII-encoded decimal. 这会将行打印为ASCII编码的十进制。 For more info see http://arduino.cc/en/Serial/Println#.UwHrRXVdVJw 有关更多信息,请参见http://arduino.cc/en/Serial/Println#.UwHrRXVdVJw

Or perhaps print() suits your needs better ( http://arduino.cc/en/Serial/Print#.UwHtKXVdVJw ). 或者,也许print()适合您的需求( 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. 由于波特率非常低(9600波特/秒),并且每次在主循环中模拟值发生变化时都发送字符,这可能是因为您尝试发送的数据超出了连接的处理能力。

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 :). 我不确定这是否会造成问题,但是我的建议是通过不断摇动操纵杆来确保您的系统压力:)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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