Computer and Arduino controlled car (1:18)
So I decided to make something with RC-servos using the Arduino board and the sensor shield which I recently purchased.
I went ahead figuring out how to send arrow signals from my computer to Arduino using USB interface.
Using void setup() { Serial.begin(9600); } on Arduino and screen /dev/ttyUSB0 9600 on my computer, I managed to send commands back and forth. I hooked up the standard servo library and write some code before I mounted the Arduino board on my mini rock crawler. I now had a computer controlled car. Because of Arduino`s simple interface I had it all up and running around an hour. Check the small video and code below.
You can view and or use the code as you like below. (Sorry about the indention, WordPress messes it up).
// LIBRARY
//
#include <Servo.h>
//
// OBJ
//
Servo servo1;
Servo servo2;
// VARS
int readByte;
int servo1Angle = 90; //default servo angle
int servo2Angle = 90;
int minPulse = 700; // minimum servo position
int maxPulse = 2300; // maximum servo position
void setup()
{
servo1.attach(2, minPulse, maxPulse); //connect servo
servo2.attach(3, minPulse, maxPulse);
Serial.begin(9600); // start serial
Serial.println(“Ready\n”);
}
void loop()
{
if (Serial.available() > 1) // procced when two bytes is avaiable
{
readByte; = Serial.read(); //read first byte
if (readByte; == 91)
{
readByte; = Serial.read(); //read second byte to determine arrow type
if (readByte; == 65 && servo1Angle <= 180) //UP
{
servo1Angle += 5;
}
else if(readByte; == 66 && servo1Angle >= 0) //DOWN
{
servo1Angle -= 5;
}
else if(readByte; == 67 && servo2Angle <= 180) //RIGHT
{
servo2Angle += 5;
}
else if(readByte; == 68 && servo2Angle >= 0) //LEFT
{
servo2Angle -= 5;
}
}
}
// set servo positions
servo1.write(servo1Angle);
servo2.write(servo2Angle);
delay(15);
}
Tags: /dev/ttyUSB0, 1:18, arduino, c++ish, car, Computer, controlled, linux, RC, usb



March 1st, 2010 at 12:09 pm
Bare å melde seg på
http://www.sparkfun.com/commerce/news.php?id=332
March 24th, 2010 at 8:42 pm
I am using arduino IDE on ubuntu 9.10 x64 it works fine, I am also using the /dev/ttyUSB0 9600 command to read the data. My problem is that i cant make it stop (Serial connection arduino-pc using screen) and because the serial communication keeps busy i cant upload anything to the arduino (again using arduino IDE) unless i unplug and plug the arduino card. Do you have any idea on how to resolve this problem
Thank You
March 24th, 2010 at 11:54 pm
Yeah, I`m now using the “new” arduino IDE 0018 version and serial connection works great.
To answer your question do this: dettach screen by pressing
CTRL+A+D. Now usekill> or killall screenif you don`t have any other screens.Hope this helps.