Help with iPod board.

Hey guys i've been playing with a duemilanove for the past 2 years, nothing serious just learning as i go along, i've never had to ask for advice, i just searched and parsing pieces together i got around, but im stuck , I've pieced together some codes, and got the ipod nike serial board to comunicate with the arduino and also read some data on serial monitor, the problem is, its very unreliable, it would work one minute, than dead nothing , 3 hours later works then nothing.... heres the code..please help...ANY SIMILARITY TO YOUR CODE IS NOT COINCIDENTAL.. :wink:

*/
#include <SoftwareSerial.h>
const int rxpin = 2;
const int txpin = 3;
const int ledPin = 13; // status LED on the arduino
const int drivenPin = 9; // the number of the driven pin
SoftwareSerial ipod(rxpin, txpin);
int i = 0;
unsigned long timeCheck = 0;
uint8_t frame[32]; //Frames are 32 bytes long
uint32_t fob_id = 0;
int verbose = 1; //1 = enable serial prints for debug etc. 0 = disable

void setup()
{
//set up outputs
pinMode(ledPin, OUTPUT);
pinMode(drivenPin, OUTPUT);
pinMode(rxpin, INPUT);
pinMode(txpin, OUTPUT);

//NIKE works on 57600 baud... make sure your serial monitor is set accordingly!
Serial.begin(57600);
ipod.begin(57600);
//alive and ready to rock!
for(char i = 0; i < 15 ; i++)
{
digitalWrite(ledPin, HIGH); //Reset indicator
delay(50);
digitalWrite(ledPin, LOW);
delay(50);
}

//start comms
receiver_init();

}

void loop()
{

delay(10); // allow the buffer to fill? doesn't seem to work w/o it

// listen for reply
if (ipod.available() > 0)
{
if(ipod.read() == 0xFF) //Each frame starts with 0xFF55
{
if(ipod.read() == 0x55) //If second character is 0x55, then we have start of good frame
{
for(i = 0 ; i < 30 ; i++) //Capture 30 characters from the ~33 character frame returned by the iPod receiver
{
//while(Serial.available() == 0) ;
frame = ipod.read();

  • }*

  • //Now pull out the 4 ID bytes*

  • fob_id = frame[5]; //2 according to dmitry*

  • fob_id <<= 8;*

  • fob_id |= frame[6]; //3*

  • fob_id <<= 8;*

  • fob_id |= frame[7]; //4*

  • fob_id <<= 8;*

  • fob_id |= frame[8]; //5*

  • //show us the reply*

  • digitalWrite(ledPin, HIGH); //status*

  • if (verbose) {*

  • Serial.println();*

  • Serial.print("Fob ID HEX 0x");*

  • Serial.print(fob_id, HEX);*

  • Serial.print(" Fob ID ");*

  • Serial.print(fob_id);*

  • Serial.println();*

  • Serial.print("Frame: ");*

  • for(i = 0 ; i < 31 ; i++)*

  • {*

  • Serial.print(" 0x");*
    _ Serial.print(frame*, HEX); // prints value as string in hexadecimal (base 16)_
    _
    }_
    _
    } else {_
    _
    delay (50);_
    _
    }_
    _
    digitalWrite(ledPin, LOW);_
    _
    }_
    _
    }_
    _
    }_
    _
    //drive the pin*_
    * if (fob_id == 0000000000) { //this is my ID, get your own!
    _
    timeCheck = millis();_
    fob_id = 0;
    _
    digitalWrite(drivenPin, HIGH);_
    _
    } _
    _
    if ((millis() - timeCheck) > 5000) { // keep things lit constantly and for 5 seconds afterwards*_
    * digitalWrite(drivenPin, LOW);*
    * }*
    } // end void loop
    void receiver_init() {

* uint8_t i;*

* //init strings*
* uint8_t init1[8] = {0xFF, 0x55, 0x04, 0x09, 0x07, 0x00, 0x25, 0xC7};
uint8_t init2[6] = {0xFF, 0x55, 0x02, 0x09, 0x05, 0xF0};*

* digitalWrite(ledPin, HIGH);*
* delay(1000);*
* digitalWrite(ledPin, LOW);*
* delay(50);*
* if (verbose) {*
* Serial.println();*
* Serial.println("Serial init string to NIKE:");*
* }*
* for(i = 0 ; i < 8 ; i++)*
* {*
* loop_until_bit_is_set(UCSR0A, UDRE0);
_ UDR0 = init1;
}*_

* delay(50);*
* for(i = 0 ; i < 32 ; i++) //Capture 32 characters from the ~33 character frame returned by the iPod receiver*
* {*
_ frame = ipod.read();
* }
if (verbose) {
Serial.println();
Serial.println("Response Frame:");
for(i = 0 ; i < 31 ; i++)
{
Serial.print(" 0x");
Serial.print(frame, HEX); // prints value as string in hexadecimal (base 16)
}
Serial.println();
Serial.println("Should match:");
Serial.println(" 0xFF 0x55 0x4 0x9 0x0 0x0 0x7 0xEC 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF");
Serial.println("Serial init string to NIKE:");
}
for(i = 0 ; i < 6 ; i++)
{_

loop_until_bit_is_set(UCSR0A, UDRE0);
_ UDR0 = init2;
}
delay(50);
for(i = 0 ; i < 32 ; i++) //Capture 32 characters from the ~33 character frame returned by the iPod receiver*

* {
//while(Serial.available() == 0) ;
frame = ipod.read();
}
if (verbose) {
Serial.println();
Serial.println("Response Frame:");
for(i = 0 ; i < 31 ; i++)
{
Serial.print(" 0x");
Serial.print(frame, HEX); // prints value as string in hexadecimal (base 16)
}
Serial.println();
Serial.println("Should match:");
Serial.println(" 0xFF 0x55 0x4 0x9 0x6 0x0 0x25 0xC8 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF");
Serial.println("Receiver is Init if strings match - Tap pod for further response!");
Serial.println("If the strings do not match, check connections.");
}
//flash status*

* for(char i = 0; i < 3 ; i++)
{
digitalWrite(ledPin, HIGH); //Reset indicator*

* delay(50);
digitalWrite(ledPin, LOW);
delay(50);
}_

} //end receiver_init*

  // listen for reply
  if (ipod.available() > 0)
  {
    if(ipod.read() == 0xFF) //Each frame starts with 0xFF55
    {
      if(ipod.read() == 0x55) //If second character is 0x55, then we have start of good frame
      {
        for(i = 0 ; i < 30 ; i++) //Capture 30 characters from the ~33 character frame returned by the iPod receiver
        {
          //while(Serial.available() == 0) ;
          frame[i] = ipod.read();
        }

I bet part of your problem is that you check for >0 bytes available and then read 32 bytes without further checking.

Sorry, my coding s not that advance, coul you elaborate, from what i gather the software serial isnt sending the init string to the board...but thats about it..

I'm wondering if somehow the read pointer is getting advanced so when there's some actual real data there, the part where it checks for the beginning of the fame is 2 bytes ahead. So on the off chance after a few hours it lines up again it appears to start working.

Just a guess. I'm more of an understand the logic guy than a programmer.

Try changing:

  if (ipod.available() > 0)

to:

  if (ipod.available() >= 32)

stonent:
I'm wondering if somehow the read pointer is getting advanced so when there's some actual real data there, the part where it checks for the beginning of the fame is 2 bytes ahead. So on the off chance after a few hours it lines up again it appears to start working.

Just a guess. I'm more of an understand the logic guy than a programmer.

Thanks for taking the time to help, but that and a chinese menu, looks the same to me :roll_eyes:, but from what i can gather is , retard the read pointer by means of a buffer?

johnwasser:
Try changing:

  if (ipod.available() > 0)

to:

  if (ipod.available() >= 32)

Thanks for the help, but still nothing, i can read serial data trough the usb into a python script no problem, but just cant seem to get it working again....

Is the code sending the init string to the board, trough the software serial pins ?

OK guys, thanks for all the help, i got working by sending the init string in a different manner (That's code for: i have no idea what i did, i just started messing with the code while reading David Chattings example and arduinos library).... :wink: