Pages: [1]   Go Down
Author Topic: Robosapien IR problem  (Read 397 times)
0 Members and 1 Guest are viewing this topic.
0
Offline Offline
Newbie
*
Karma: 0
Posts: 7
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi,

I want to hack a Robosapien from WowWee.
So I found these 2 links
http://playground.arduino.cc//Main/RoboSapienIR
http://playground.arduino.cc/Main/RoboSapienServer

I followed the 2nd link for the wiring and the first one for the code.
Here're 2 pic's of my wiring.

I've added the white wire to the red 3.3V one on the cable and the brown one to GND.
The white IR signal cable I've split in 2. I soldered the yellow wirre to top part connected to the plug and the green wire to the bottom part of the white cable, going to the Robosapien's head.


This is how I wired it up to my arduino, which is powered by USB.
I've used a 1K Ohm and 1.5K Ohm resistor to level from 5V to 3.3V.
I don't really need/use the green cable that's wired to pin 2.


I made a few changes to the RoboSapienIR code.
I've added some debugging code and I had to set RSEcho & RSUsed both to false, otherwise it wouldn't send the commands.
Code:
int IRIn = 2;            // We will use an interrupt
int IROut= 3;            // Where the echoed command will be sent from

// Some but not all RS commands are defined
#define RSTurnRight       0x80
#define RSRightArmUp      0x81
#define RSRightArmOut     0x82
#define RSTiltBodyRight   0x83
#define RSRightArmDown    0x84
#define RSRightArmIn      0x85
#define RSWalkForward     0x86
#define RSWalkBackward    0x87
#define RSTurnLeft        0x88
#define RSLeftArmUp       0x89
#define RSLeftArmOut      0x8A
#define RSTiltBodyLeft    0x8B
#define RSLeftArmDown     0x8C
#define RSLeftArmIn       0x8D
#define RSStop            0x8E
#define RSWakeUp          0xB1
#define RSBurp            0xC2
#define RSRightHandStrike 0xC0
#define RSNoOp            0xEF
boolean RSEcho=false;      // Should Arduino Echo RS commands
boolean RSUsed=false;      // Has the last command been used
volatile int RSBit=9;     // Total bits of data
volatile int RSCommand;   // Single byte command from IR
int bitTime=516;          // Bit time (Theoretically 833 but 516)
                          // works for transmission and is faster
int last;                 // Previous command from IR

void setup()                   
{
  pinMode(IRIn, INPUT);     
  pinMode(IROut, OUTPUT);
  pinMode(10,OUTPUT);
  digitalWrite(IROut,HIGH);
  attachInterrupt(0,RSReadCommand,RISING);
  last=RSNoOp;
 
  // open the serial port at 9600 bps:
  Serial.begin(9600);
}

// Receive a bit at a time.
void RSReadCommand() {
  delayMicroseconds(833+208);  // about 1 1/4 bit times
  int bit=digitalRead(IRIn);
  if (RSBit==9) { // Must be start of new command
    RSCommand=0;
    RSBit=0;
    RSUsed=true;
  }
  if (RSBit<8) {
    RSCommand<<=1;
    RSCommand|=bit;
  }
  RSBit++;
  if (RSBit==9) RSUsed=false;
}

// send the whole 8 bits
void RSSendCommand(int command) {
  Serial.print("RSSendCommand = ");
  Serial.println(command);
  digitalWrite(IROut,LOW);
  delayMicroseconds(8*bitTime);
  for (int i=0;i<8;i++) {
    digitalWrite(IROut,HIGH); 
    delayMicroseconds(bitTime);
    if ((command & 128) !=0) delayMicroseconds(3*bitTime);
    digitalWrite(IROut,LOW);
    delayMicroseconds(bitTime);
    command <<= 1;
  }
  digitalWrite(IROut,HIGH);
  delay(250); // Give a 1/4 sec before next
}

void loop()
{
 
  Serial.print("RSUsed = ");
  Serial.println(RSUsed);
  if (!RSUsed) {
    Serial.print("RSCommand = ");
    Serial.println(RSCommand);
    Serial.print("RSEcho = ");
    Serial.println(RSEcho);
    Serial.print("last = ");
    Serial.println(last);
    if (RSCommand==RSStop && last==RSStop) RSEcho=!RSEcho;
    last=RSCommand;
    Serial.print("RSEcho = ");
    Serial.println(RSEcho);
    if (!RSEcho){
      digitalWrite(10,HIGH);  // Turn on LED let us know
                              //  we have control our wedge
      RSSendCommand(RSRightArmOut);
      RSSendCommand(RSTiltBodyRight);
      RSSendCommand(RSRightArmDown);

      RSSendCommand(RSLeftArmOut);
      RSSendCommand(RSTiltBodyLeft);
      RSSendCommand(RSLeftArmDown);

      RSSendCommand(RSWalkForward);
      RSSendCommand(RSStop);
    } else {
      digitalWrite(10,LOW);   // No longer in control
      RSSendCommand(RSCommand);
    }
    RSUsed=true;
  }
  delay(1000);
}

I've checked all the connections with a multimeter and all were fine.
But when I run the code, nothing happens.

Does any one have a hint for me?
Thanks,
mezelve
Logged

Pages: [1]   Go Up
Jump to: