xbee does not send without arduino reset

XBee projects like the adapter, xBee tutorials, tweetawatt/wattcher, etc. from Adafruit

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
User avatar
roherman00
 
Posts: 25
Joined: Thu Apr 26, 2012 7:00 pm

xbee does not send without arduino reset

Post by roherman00 »

Hello,

I got some help on another question about a softSerial array and I finally got arduino to send data over the usb to Matlab. I just uploaded the sketch to transmit the data wirelessly through xbee (series 1) and it seemed to be working great i.e. no corruption except only when I reset the arduino. I have only the rx, tx, +5v, and gnd (from the adafruit xbee adapter kit) connected to the arduino but I always get an empty array from Matlab unless I press the reset button on the arduino and then run the Matlab program. I don't have to do this when I use a usb cable but I have to every time I send data wirelessly. Does the xbee need a power cycle to be able to start transmitting again? If so is it possible to wire a pin to the arduino reset to have it reset itself?

Thanks for any help.

User avatar
Franklin97355
 
Posts: 23912
Joined: Mon Apr 21, 2008 2:33 pm

Re: xbee does not send without arduino reset

Post by Franklin97355 »

Could we see your code? And how you have things connected.

User avatar
roherman00
 
Posts: 25
Joined: Thu Apr 26, 2012 7:00 pm

Re: xbee does not send without arduino reset

Post by roherman00 »

Do I just copy and paste the code or do I add it as an attachment? There isn't much with the xbee except:
SoftwareSerial xbee(6,7)
xbee.begin(38400);
xbee.write(value);
That is literally all I added to the prior code I had
I don't have a camera to take a picture but the 4 wires from the xbee go like this:
xbee --> arduino
+5v +5v
Gnd Gnd
rx pin 7 (tx of the softwareSerial)
tx pin 6 (rx of the softwareSerial)

I am not reading from the xbee it is only writing.

User avatar
adafruit_support_bill
 
Posts: 88093
Joined: Sat Feb 07, 2009 10:11 am

Re: xbee does not send without arduino reset

Post by adafruit_support_bill »

To submit code, use the "Code" button above the message edit box and paste your code between the tags.

User avatar
roherman00
 
Posts: 25
Joined: Thu Apr 26, 2012 7:00 pm

Re: xbee does not send without arduino reset

Post by roherman00 »

Code: Select all

#include <SoftwareSerial.h>
//softSerial(rx, tx);
SoftwareSerial softSerial[2] = { SoftwareSerial(3, 2), SoftwareSerial(5, 4) };
SoftwareSerial xbee(6, 7);
//int resolution = 0x11; //320*240
//int resolution = 0x00; //640*480
//int resolution = 0x22; //160*120
byte jpegSize[9];
byte hdrChk[5];
byte incomingByte;
byte incomingByte1;
byte incomingByte2;
int address = 0x0000;
int skipFooter;
int inc = 0;
int choose = 0;
int counter;
int KH;
int KL;
boolean endImage = 0;
uint8_t MH;
uint8_t ML;

void setup(){
  Serial.begin(38400);
  softSerial[0].begin(19200);
  softSerial[1].begin(19200);
  xbee.begin(38400);
  delay(20);
  resetCamera();
  delay(10);
  softSerial[0].end();
  softSerial[1].end();
  delay(10);
  softSerial[0].begin(38400);
  softSerial[1].begin(38400);
  delay(10);
  setBaudrate();
  delay(15);
  softSerial[0].end();
  softSerial[1].end();
  delay(10);
  softSerial[0].begin(19200);
  softSerial[1].begin(19200);
  delay(10);
  setResolution(0x11);
  delay(25);
  for (int i=0; i<2; i++){
  while (softSerial[choose].available() > 0){
    incomingByte = softSerial[choose].read();
  }
  }
  delay(3000);
  delay(25);
  for (int i=0; i<2; i++){
  while (softSerial[choose].available() > 0){
    incomingByte = softSerial[choose].read();
  }
  }
  takePicture();
  delay(25);
  for (int i=0; i<2; i++){
  while (softSerial[choose].available() > 0){
    incomingByte = softSerial[choose].read();
  }
  }
  readPictureSize();
  delay(25);
  for (int i=0; i<2; i++){
  while (softSerial[choose].available() > 0){
    incomingByte = softSerial[choose].read();
    jpegSize[inc] = incomingByte;
    inc++;
  }
  }
  inc = 0;
  KH = jpegSize[7];
  KL = jpegSize[8];
  softSerial[0].flush();
  softSerial[1].flush();
  //byte address[80];
  //start reading the image
  delay(10);
}
void loop(){
  for (int i=0; i<2; i++){
    choose = i;
    softSerial[choose].listen();
    while(endImage != 1){
      readPictureData(choose);
      delay(50);
      counter = softSerial[choose].available();
      for (int i=0; i<5; i++){
        hdrChk[i] = softSerial[choose].read();
      }
      for (int i=0; i<(counter-10)/2; i++){
        incomingByte1 = softSerial[choose].read();
        incomingByte2 = softSerial[choose].read();
        //Serial.print(incomingByte1);
        //Serial.print(" ");
        //Serial.print(incomingByte2);
        //Serial.print(" ");
        //Serial.write(incomingByte1);
        //Serial.write(incomingByte2);
        xbee.write(incomingByte1);
        xbee.write(incomingByte2);
        if ((incomingByte1 == 255)&(incomingByte2 == 217)){
          endImage = 1;
        }
      }
      while(softSerial[choose].available()>0){
        incomingByte1 = softSerial[choose].read();
      }
      //Serial.println(" ");
      //softSerial.flush();
    }
    address = 0x0000;
    endImage = 0;
  }
  while(1);
}
void resetCamera(){
  unsigned char resetCam[4] = { 0x56, 0x00, 0x26, 0x00 };
  for (int i=0; i<4; i++){
    softSerial[0].write(resetCam[i]);
    softSerial[1].write(resetCam[i]);
  }
}
void takePicture(){
  unsigned char takePic[5] = { 0x56, 0x00, 0x36, 0x01, 0x00 };
  for (int i=0; i<5; i++){
    softSerial[0].write(takePic[i]);
    softSerial[1].write(takePic[i]);
  }
}
void readPictureSize(){
  unsigned char readSize[5] = { 0x56, 0x00, 0x34, 0x01, 0x00 };
  for (int i=0; i<5; i++){
    softSerial[0].write(readSize[i]);
    softSerial[1].write(readSize[i]);
  }
}
void readPictureData(int camera){
  MH = address/0x100;
  ML = address%0x100;
  unsigned char readData[16] = { 0x56, 0x00, 0x32, 0x0c, 0x00, 0x0a, 0x00, 0x00, MH, ML, 0x00, 0x00, 0x00, 0x20, 0x00, 0x0a };
  for (int i=0; i<16; i++){
    softSerial[camera].write(readData[i]);
  }
  address = address + 0x20;
}
void setResolution(int res){
  unsigned char resPic[9] = { 0x56, 0x00, 0x31, 0x05, 0x04, 0x01, 0x00, 0x19, res };
  for (int i=0; i<9; i++){
    softSerial[0].write(resPic[i]);
    softSerial[1].write(resPic[i]);
  }
}
void setBaudrate(){
  unsigned char baud[7] = { 0x56, 0x00, 0x24, 0x03, 0x01, 0x56, 0xE4  };
  for (int i=0; i<7; i++){
    softSerial[0].write(baud[i]);
    softSerial[1].write(baud[i]);
  }
}

User avatar
adafruit_support_bill
 
Posts: 88093
Joined: Sat Feb 07, 2009 10:11 am

Re: xbee does not send without arduino reset

Post by adafruit_support_bill »

Once you hit this line:

Code: Select all

   while(1);
You loop forever (or until the board is reset).

User avatar
roherman00
 
Posts: 25
Joined: Thu Apr 26, 2012 7:00 pm

Re: xbee does not send without arduino reset

Post by roherman00 »

I know that. I put that line in so that once the data is sent from both devices then that would be it until matlab sends a reset serial command which causes the arduino to "reset" and rerun the program. The problem i am having is I think that because I am using the arduino UNO board the integrated serial must cause a reset on the arduino whereas when I switch over to using the xbee even though matlab sends a reset serial, because it is not physically connected to the arduino nothing happens. That might explain why I have to physically hit the reset button on the UNO before the arduino can send data again.
Two possible solutions I'm thinking about that you bring up:
1) is there a way to wire the xbee to reset the arduino. I have seen it done on the ladyada tutorials.
2) the better way which you mention would probably be after arduino sends its data, instead of while(1) do something like
while(xbee does not receive a resend data command from matlab)

Any thoughts on this. Thank you though for pointing out the while command because that might definitely be causing an issue I didn't think it would.

User avatar
adafruit_support_bill
 
Posts: 88093
Joined: Sat Feb 07, 2009 10:11 am

Re: xbee does not send without arduino reset

Post by adafruit_support_bill »

This tutorial shows how to wire the XBee to do a reset.
Waiting for a command should work too. That approach would likely be easier to expand upon if you decide to add more functionality later.

User avatar
roherman00
 
Posts: 25
Joined: Thu Apr 26, 2012 7:00 pm

Re: xbee does not send without arduino reset

Post by roherman00 »

Yes that is the tutorial I was using except I used the point to point section. I guess I will use the second approach. Is there a way to open the serial monitor while matlab is sending serial data so I can see what type of characters are going through? I can attach an lcd shield (I would have to unplug everything) but I was hoping there might be a workaround considering there were plenty of times it could have helped to see how arduino is interpreting the data being sent to it so I can use the appropriate comparison test. Either way I'm glad another solution has presented itself.

User avatar
adafruit_support_bill
 
Posts: 88093
Joined: Sat Feb 07, 2009 10:11 am

Re: xbee does not send without arduino reset

Post by adafruit_support_bill »

Is there a way to open the serial monitor while matlab is sending serial data so I can see what type of characters are going through?
Unfortunately, no. Only one application can have the com port open at a time.

User avatar
roherman00
 
Posts: 25
Joined: Thu Apr 26, 2012 7:00 pm

Re: xbee does not send without arduino reset

Post by roherman00 »

Ok that's what I figured. Well thank you for the help.

Locked
Please be positive and constructive with your questions and comments.

Return to “XBee products (discontinued)”