Show Posts
Pages: [1] 2
1  Topics / Robotics / Sending IR commands to Robosapien from Arduino on: October 11, 2012, 10:20:43 pm
Hello,

I am trying to send IR commands to a Robosapien (first generation) but I am unable to get any response from the toy.

I read that in order to send a code like 0x85 (right-arm-in), you have to send:

Binary: 1 0 0 0 0 1 0 1
IR Code: 1110 10 10 10 10 1110 10 1110

(ie., a '1110' for a '1' and '10' for a '0')

Also, I read that you have hold the input high and send a string of five '0' pulses before sending a command.

So accordingly, I tried the following code:

Code:
int bitTime=833;
int IROut =  4;
 
// The setup() method runs once, when the sketch starts
 
void setup()   {               
  // initialize the IR digital pin as an output:
  pinMode(IROut, OUTPUT);     
 
  Serial.begin(9600);
}

 
// This procedure sends a 38KHz pulse to the IRledPin
// for a certain # of microseconds. We'll use this whenever we need to send codes
void pulseIR(long microsecs) {
  // we'll count down from the number of microseconds we are told to wait
 
  cli();  // this turns off any background interrupts
 
  while (microsecs > 0) {
    // 38 kHz is about 13 microseconds high and 13 microseconds low
   digitalWrite(IROut, HIGH);  // this takes about 3 microseconds to happen
   delayMicroseconds(10);         // hang out for 10 microseconds, you can also change this to 9 if its not working
   digitalWrite(IROut, LOW);   // this also takes about 3 microseconds
   delayMicroseconds(10);         // hang out for 10 microseconds, you can also change this to 9 if its not working
 
   // so 26 microseconds altogether
   microsecs -= 26;
  }
 
  sei();  // this turns them back on
}

void test()
{
  // send high
  //pulseIR(
  pulseIR(1000*bitTime);
 
  for(int i = 0; i < 4; i++) {
    delayMicroseconds(bitTime);
    pulseIR(bitTime);
  }
  delayMicroseconds(bitTime);
   
  // burp: C2
  // 1 1 0 0 0 0 1 0
  // send 1110 1110 10 10 10 10 1110 10
  pulseIR(3*bitTime);
  delayMicroseconds(bitTime);
  pulseIR(3*bitTime);
  delayMicroseconds(bitTime);
  pulseIR(bitTime);
  delayMicroseconds(bitTime);
  pulseIR(bitTime);
  delayMicroseconds(bitTime);
  pulseIR(bitTime);
  delayMicroseconds(bitTime);
  pulseIR(bitTime);
  delayMicroseconds(bitTime);
  pulseIR(3*bitTime);
  delayMicroseconds(bitTime);
  pulseIR(bitTime);
  delayMicroseconds(bitTime);
   
  pulseIR(1000*bitTime);
 
  // wait for 1 sec
  delay(1000);
}

void loop()                     
{
  test();
}


But I don't get any response. I'd appreciate any helping in sending the IR codes to the robot.

Thanks
2  Forum 2005-2010 (read only) / Troubleshooting / Re: Book/docs for advanced Arduino programming on: July 15, 2009, 08:25:10 pm
Thanks!
3  Forum 2005-2010 (read only) / Troubleshooting / Book/docs for advanced Arduino programming on: July 14, 2009, 10:57:15 am
Hello,

I am relatively new to Arduino, and was wondering if someone could suggest books or documentation on AVR programming. In my search for some PCM ideas, I came across Arduino code that uses direct port manipulation, and code that sets up timers/interrupts. I'd appreciate pointers to any books or online docs that would help me understand the AVR architecture and the C API calls.

Thanks

MV
4  Forum 2005-2010 (read only) / Interfacing / String sounds with Karplus-Strong Algorithm on: August 02, 2009, 01:16:35 am
Hi Folks,

As part of my sound experiments with Arduino, I ran into the Karplus-Strong algorithm to generate plucked string sounds. Although I haven't implemented this yet in the Arduino (there are limitations on memory and speed which I am not sure how to overcome), I did write some simple code in python that generates sounds using the above. I think it can be used to generate sound samples for the Arduino, if nothing else.

http://electro-nut.blogspot.com/2009/08/karplus-strong-algorithm.html

Best Regards
5  Forum 2005-2010 (read only) / Interfacing / Re: A 12-bit R/2R serial DAC on: August 03, 2009, 09:38:51 pm
Thanks for the comments.

So is the measured response graph linear only because of the spacing between the readings?
6  Forum 2005-2010 (read only) / Interfacing / A 12-bit R/2R serial DAC on: August 03, 2009, 11:58:00 am
Hi folks,

Just wanted to post a 12-bit R/2R serial DAC I built. I couldn't get hold of a DAC IC, so I decided to try and build one:

http://electro-nut.blogspot.com/2009/08/making-12-bit-serial-dac.html

Thanks to the forum for helpful discussions.

Best Regards
7  Forum 2005-2010 (read only) / Interfacing / Re: Shifting out 10 bit data to a shift register on: July 27, 2009, 05:30:45 am
I switched to digitalWrite(), removed all the delays and now it works fine. I can send 0-1023 without problems. I am using the same shiftOut10 method, so that part is fine. I wonder if it was a loose contact that was the problem.

Thanks for your suggestions - the fastWrite code will come in handy later.
8  Forum 2005-2010 (read only) / Interfacing / Re: Shifting out 10 bit data to a shift register on: July 26, 2009, 08:36:19 pm
Quote
I posted some code in this thread that is as fast as the code you are using but much easer to read: http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1226290298

Thanks for the code.

Quote
But if you have 100us delays then you would be no worse of using digitalWrite

Any idea what the minimum pulse width (delay) should be to make the shift register work? I was seeing some glitches even with this delay.
9  Forum 2005-2010 (read only) / Interfacing / Re: Shifting out 10 bit data to a shift register on: July 26, 2009, 10:16:05 am
Quote
Is there a reason you are writing to the low level registers instead of using digitalWrite. It makes that code difficult to follow.

This is going to be an input to a DAC, and I will need to do the shifting from a high frequency timer callback. The opinion in the forums seems to be that digitalWrite() will be too slow for that purpose.
10  Forum 2005-2010 (read only) / Interfacing / Shifting out 10 bit data to a shift register on: July 26, 2009, 08:23:37 am
Hi folks,

I am trying to shift 10 bit data out to 2 x 74HC595 ICs configured as in the page below:

http://www.arduino.cc/en/Tutorial/ShiftOut

The code I am using is posted below. I am trying to light the LEDs one by one, by sending only powers of 2, and it seems to work most of the time. However, at times, I see an LED being skipped, or 2 adjacent LEDs being lit. I am not sure about the delays() I have put in - how much time should SH_CP and ST_CP be kept high?. I'd appreciate any feedback on the code below:

Code:
/*
 * ShiftOutTest
 *
 */

// 74HC595 pins
int pin_SH_CP = 6;
int pin_ST_CP = 7;
int pin_DS = 5;

// values
int vals[] = {
  1, 2, 4, 8, 16, 32, 64, 128, 256, 512};

void setup()
{
  pinMode(pin_SH_CP, OUTPUT);
  pinMode(pin_ST_CP, OUTPUT);
  pinMode(pin_DS, OUTPUT);
}

void loop()
{
  for(int i = 0; i < 10; i++) {

    // ST_CP low
    PORTD &= ~(1<<7);

    // shift 10 LSB bits of data to shift register
    shiftOut10(vals[i]);

    // ST_CP high
    PORTD |= (1<<7);
    // delay needed?
    delayMicroseconds(100);
    // ST_CP low
    PORTD &= ~(1<<7);

    delay(500);
  }

}

// shift out 10 bits of data
void shiftOut10(int data)
{
  for(int i = 0; i < 10; i++) {
    // delay needed?
    delayMicroseconds(100);
    
    // SH_CP low
    PORTD &= ~(1<<6);
    // DS
    // is i-th bit of data high?
    if(data & (1<<i)) {
      PORTD |= (1<<5);
    }
    else {
      PORTD &= ~(1<<5);
    }
    // SH_CP high
    PORTD |= (1<<6);

    // delay needed?
    delayMicroseconds(100);
  }
  // SH_CP low
  PORTD &= ~(1<<6);
}
11  Forum 2005-2010 (read only) / Interfacing / Re: LM741 based 4-bit DAC on: July 22, 2009, 08:24:15 pm
Thanks.

But I am not sure if these ICs are easily available here in Bangalore.

How about LM358? Is it a good choice for an R/2R DAC?

http://www.datasheetcatalog.org/datasheet/fairchild/LM358.pdf
12  Forum 2005-2010 (read only) / Interfacing / LM741 based 4-bit DAC on: July 22, 2009, 09:56:16 am
Hi Folks,

As an attempt to understand R/2R DACs, I tried building a 4-bit DAC using an LM741. The circuit and the measured response are in the links below:

http://picasaweb.google.com/glman74/NutsAboutElectronics#5361295651529113874

http://picasaweb.google.com/glman74/NutsAboutElectronics#5361295658833572610

My 9V battery was only giving 8.4 V. Is this why the Vout for the last point (1111) in error, since Vref is only 4.1 V?

I realize that 741 may not be the best choice for a DAC, but I am just experimenting, and am curious to find out if I can build a 10-bit DAC this way.

I'd appreciate any suggestions on improving this circuit.

Thanks
13  Forum 2005-2010 (read only) / Interfacing / Re: Sending shiftOut() data with a fixed frequency on: July 19, 2009, 09:42:44 pm
Quote
It shouldn't be out of the question for speed -- 10 bits @ 20 kHz is still 80 cycles per bit and that really ought to be enough...

I am trying to send a PCM signal, so to support the full audio range, I'd try for 44,100 Hz. But I could do with much less to start with.

Quote
If you're using 595s, the contents of the shift register only get transferred to the output latches on a rising edge applied to RCK (pin 12). Therefore, if you connect pin 12 of your 595s to one of the timer output pins, you can cycle its output only on your desired frequency and shift in the data more or less at leisure.

I am not sure if I fully understand the above. Is that assuming you can shift out much faster than the frequency at which you need to update pin 12? Or should I have 2 timers?

Quote
Also, if you end up interfacing directly to the shift registers rather than using ShiftOut(), you can only shift the ten bits you care about and ignore the top six bits...

Good idea - I'll try that.

Thanks

14  Forum 2005-2010 (read only) / Interfacing / Re: Sending shiftOut() data with a fixed frequency on: July 19, 2009, 07:15:10 am
Grumpy_Mike:
Quote
Shift registers work in groups of 8, check that you can shift out 10 bits.

I was thinking of using 2 x 74HC595 8-bit shift registers, I thought I'd shift out 16 bits via 2 calls to shiftOut() and ignore the higher order bits.

Mike MC:
Quote
I use the TimerOne library myself which is nice and simple to use. However, for very high frequencies you'd probably need to do direct port manipulation. Like Mike says, it sounds like the frequency you are thinking about would be well above the Arduino's capabilities. Maybe a few thousand Hz tops, but I may be wrong.

Is there a standard way of replacing shiftOut() with port manipulation calls?  

Despite the limitations, I thought I'd give this a try. If I can get something going, I would consider moving to the ATMega644 based Sanguino.

Thank you for all the advice.
15  Forum 2005-2010 (read only) / Interfacing / Sending shiftOut() data with a fixed frequency on: July 16, 2009, 11:16:50 pm
Hi Folks,

If I want to send out say, 10 bit data serially via shiftOut() (To a shift register), how can I make sure that the data is sent out at a precise frequency?

I am guessing that if I do it in loop() with delay*() calls, it won't be accurate? Will I have look into using a timer?

The frequency I am interested is in the audio range: 20-20,000 Hz.

Thanks
Pages: [1] 2