Series 1 - ADC to second Xbee connected to Arduino help

Hey,

I would like to ADC a value at pin D02, send it to another Xbee that’s sitting in a wireless shield connected to an Arduino Uno. I’m trying to do the ‘Romantic light’ example from the Wireless Sensor Networks book (O’Reilly). Unfortunately the book uses a Series 2 and it seems it’s not 100% the same.

Can anyone explain to me what parameters I have to set in the Xbee’s? Currently one is set to use API and be a coordinator while the other is still in AT mode and has DO2 pin on ADC with 100ms sampling rate.

With the sample code from the book the receiving Xbee picks up the frames and sends them to the Arduino (LED is flashing when the start byte is detected/read) but unfortunately I have no idea how to output the whole frame to the terminal as to check what is received.

Using the datasheet I also tried to understand the content of frames sent but it isn’t quite clear to me.

Could anyone using series 1 Xbees explain how this works? Or at least tell me the difference between S1 and S2.

Thanks in advance!

see the following links:
major difference in series 1 vs series 2:
http://www.digi.com/support/kbase/kbaseresultdetl?id=2213

ADC conversion on series 1:
http://www.digi.com/support/kbase/kbaseresultdetl?id=2180

AT commands to toggle an IO on a remote Xbee 802.15.4 radio:
http://www.digi.com/support/kbase/kbaseresultdetl?id=3222

802.15.4 digital input/output line passing:
http://www.digi.com/support/kbase/kbaseresultdetl?id=2188

I tried an ADC example but it didn’t seem to work properly. The MSB and LSB of the ADC just gave the same result when I hooked up Vref = 3.3V and put the ADC pin to 0 and 3.3V

Is it possible to tell me what pins exactly that need to be connected at the transmitter Xbee? Does anyone have any arduino examples for a simple ADC pin readout?

EDIT:

I messed around a bit more and I got it to work completely :slight_smile: Just for my own convenience I wrote my own “Input Line Frame analyzer” so I can easily read all values on all pins whenever I like.

Here’s the code (note that [ i ] seems to have converted into italic instead of just showing that bit of code so you’ll need to remove the spaces):


float vref = 3.3;
int resolution = 1024;
float result = 0;

byte join[2] = {0,0};
int numOfBytes = 0;
int sourceAddr = 0;
int numOfSamples = 0;
int data = 0;

byte adcStatus = 0x0;
float adcVal[6] = {0,0,0,0,0,0};

byte dioStatus = 0x0;
byte dioVal = 0x0;

void setup() {
  Serial.begin(9600);
}

void loop()
{
  numOfBytes = 0;
  sourceAddr = 0;
  numOfSamples = 0;
  data = 0;
  
  adcStatus = 0x0;
  for(int i = 0; i < 6; i++)
    adcVal[ i ] = 0;
    
  dioStatus = 0x0;
  
  if(Serial.available() >= 28) // Check for at least one complete frame
     if(Serial.read() == 0x7E) // Start at beginning of frame
     {
       Serial.print("Start Byte: 0x7E");
       
//-------------- Number of Bytes in Frame ---------//       
       
       Serial.print("
Nr Of Bytes: ");
       join[0] = Serial.read();     
       Serial.print(join[0], HEX); // MSB length
       Serial.print(" ");
       join[1] = Serial.read();
       Serial.print(join[1], HEX); // LSB length      
       numOfBytes = join[1] + (join[0] << 8);
       Serial.print(" --> DEC Value: ");
       Serial.print(numOfBytes);      
       
//-------------- Source Address Checking ---------//       
       
       Serial.print("
Address Mode: ");
       Serial.print(Serial.read(), HEX); // 83 = 16bit address      
       Serial.print("
Source Address: ");     
       join[0] = Serial.read();
       Serial.print(join[0], HEX); // MSB Address
       Serial.print(" ");
       join[1] = Serial.read();
       Serial.print(join[1], HEX); // LSB Address      
       sourceAddr = join[1] + (join[0] << 8);       
  
//-------------- RSSI Checking ---------//  
       
       Serial.print("
RSSI (signal strength in -dBm): ");
       Serial.print(Serial.read(), DEC); 
   
//-------------- Number of Samples in Frame ---------//   
       
       Serial.print("
Nr of Samples: ");
       join[0] = Serial.read();     
       Serial.print(join[0], HEX); // MSB length
       Serial.print(" ");
       join[1] = Serial.read();
       Serial.print(join[1], HEX); // LSB length            
       numOfSamples = join[1] + (join[0] << 8); 
       Serial.print(" --> DEC Value: ");
       Serial.print(numOfSamples);       

//-------------- Chanel Indicator  ---------//
       
       Serial.print("
Channel Bitfield: ");       
       adcStatus = Serial.read();
       Serial.print(adcStatus, BIN); // Neglecting D8    
       Serial.print(" ");
       dioStatus = Serial.read();       
       Serial.print(dioStatus, BIN);              

//-------------- Fetching Data word DIO ---------//     

       if(dioStatus > 0x0)
       {
         Serial.print("
Data DIO: ");       
         Serial.print(Serial.read(), BIN);       
         Serial.print(" ");
         dioVal = Serial.read(); // Neglecting D8       
         Serial.print(dioVal, BIN);              
         Serial.print(" --> ");
         
         for(int i = 0; i <= 7; i++)
         {
           Serial.print("D");
           Serial.print(i);           
           if(bitRead(dioVal, i))
             Serial.print("H");
           else
             Serial.print("L");
           Serial.print("  ");
         } 
         
       }
       else
         Serial.print("
No DIO data in frame");         

//-------------- Fetching Data word ADC ---------//

       if(adcStatus > 0x0)
       {
         for(int i = 1; i <= 6; i++)
         {
           if(bitRead(adcStatus, i))
           {         
             //Serial.print("
Data ADC #");
             //Serial.print(i);
             //Serial.print(": ");         
             join[0] = Serial.read();     
             //Serial.print(join[0], BIN); // MSB Data
             //Serial.print(" ");
             join[1] = Serial.read();
             //Serial.print(join[1], BIN); // LSB Data               
             data = join[1] + (join[0] << 8); 
             //Serial.print(" --> DEC Value: ");
             //Serial.print(data);          
             result = (vref/resolution)*data;
             adcVal[i-1] = result;
             //Serial.print(" - Voltage: ");
             //Serial.print(result);
           }
         }
         Serial.print("
Data ADC: ");         
         for(int i = 0; i < 6; i++)
         {
           if(adcVal[ i ] > 0)
           {
             Serial.print("ADC");
             Serial.print(i);
             Serial.print(": ");
             Serial.print(adcVal[ i ]);
             Serial.print("  ");
           }
         }
       }
       else
         Serial.print("
No ADC data in frame");          
      
      
       
       Serial.print("
------------------
");        
     }
      
}

which outputs, for example:


Start Byte: 0x7E
Nr Of Bytes: 0 10 --> DEC Value: 16
Address Mode: 83
Source Address: 50 0
RSSI (signal strength in -dBm): 34
Nr of Samples: 0 1 --> DEC Value: 1
Channel Bitfield: 100110 11101000
Data DIO: 0 10001000 --> D0L  D1L  D2L  D3H  D4L  D5L  D6L  D7H  
Data ADC: ADC0: 2.31  ADC1: 1.80  ADC4: 1.42  
------------------

I’m open to feedback and suggestions :slight_smile: