Named by my flat mate, I've managed to interface an arduino with a robosapien v1 by tapping into the IR In line and pulsing a line to simulate commands (originally they would come from the remote control). I've set it up so you pass a number by serial and it converts this into binary, moves through the binary and pulses the appropriate code. Now to start making it do more! Will add some pictures later.
int outPin = 8; // digital pin 8
int code = 0;
char str1[3];
int count = 0;
char incomingByte;
void setup()
{
pinMode(outPin, OUTPUT); // sets the digital pin as output
Serial.begin(9600);
}
void lowBit()
{
digitalWrite(outPin, HIGH); // sets the pin off
delayMicroseconds(750);
}
void clockBit()
{
digitalWrite(outPin, LOW); // sets the pin off
delayMicroseconds(1150);
}
void startBit()
{
digitalWrite(outPin, LOW); // sets the pin on
delayMicroseconds(5000); // pauses for 50 microseconds
}
void highBit()
{
digitalWrite(outPin, HIGH); // sets the pin on
delayMicroseconds(2550);
}
void loop()
{
char str1[3];
count = 0;
while (Serial.available () > 0)
{
// read the incoming byte:
incomingByte = Serial.read ();
// Store it in a character array
str1[count] = incomingByte;
count++;
}
code = atoi(str1);
Serial.print("B");
Serial.println (code, BIN);
digitalWrite(outPin, HIGH);
delay(1000);
startBit();
if (code & B10000000)
{
highBit(); // 1
Serial.print("1");
clockBit();
}
else
{
lowBit(); // 0
Serial.print("0");
clockBit();
}
if (code & B01000000)
{
highBit(); // 1
Serial.print("1");
clockBit();
}
else
{
lowBit(); // 0
Serial.print("0");
clockBit();
}
if (code & B00100000)
{
highBit(); // 1
Serial.print("1");
clockBit();
}
else
{
lowBit(); // 0
Serial.print("0");
clockBit();
}
if (code & B00010000)
{
highBit(); // 1
Serial.print("1");
clockBit();
}
else
{
lowBit(); // 0
Serial.print("0");
clockBit();
}
if (code & B00001000)
{
highBit(); // 1
Serial.print("1");
clockBit();
}
else
{
lowBit(); // 0
Serial.print("0");
clockBit();
}
if (code & B00000100)
{
highBit(); // 1
Serial.print("1");
clockBit();
}
else
{
lowBit(); // 0
Serial.print("0");
clockBit();
}
if (code & B00000010)
{
highBit(); // 1
Serial.print("1");
clockBit();
}
else
{
lowBit(); // 0
Serial.print("0");
clockBit();
}
if (code & B00000001)
{
highBit(); // 1i
Serial.print("1");
clockBit();
}
else
{
lowBit(); // 0
Serial.print("0");
clockBit();
}
digitalWrite(outPin, HIGH);
delay(5000);
}
Useful links: http://evosapien.com/robosapien-hack/knitsu/html/basicx-24.html http://users.bigpond.net.au/robert_gatt/robosapien/robosapien.htm