I have two arduinos that I want to communicate wirelessly. Each arduino has an Xbee pro attatched using the Xbee pro shield. I want to send analog input from a heart beat sensor from one arduino to the other using the Xbee pros. So far I have tried to use serialWrite and serialPrint to send heart beat data over with little success.
Transmitting Arduino code: (Arduino with heart beat)
void setup()
{
Serial.begin(9600);
}
void loop()
{
int heartValue = analogRead(A0); //read in heart beat data (between 0 and 1023)
int bitHundreds = heartValue / 100; //get value of hundreds place
int bitTens = (heartValue - bitHundreds * 100) / 10 //get value of tens place
int bitOnes = (heartValue - bitHundreds * 100 - bitTens * 10); //get value of ones place
Serial.write(bitHundreds);
Serial.write(bitTens); //send data in stream of bytes
Serial.write(bitOnes);
}
Receiving Arduino Code
void setup()
{
Serial.begin(9600);
}
void loop()
{
int newByte = Serial.read();
//not sure how to read in all of the Bytes and make sense of them
}
Can someone help me find an easier way to do this? Am I even on the right track? I just want to be able to send analog values wirelessly and store them in a variable on the other arduino.
I have two Xbees plugged into seperate arduino duemilanoves and an trying to send analog input from one to the other (values between 0 and 1023). What code do I use? Is there an easy way to do this?
Are you using the serial monitor to verify you are generating a the value you expect? Have you used the serial monitor to send a known value to the receiving arduino for testing purposes?
and an trying to send analog input from one to the other (values between 0 and 1023).
For what purpose? The receiving Arduino can't really do anything with the analog output without dividing by 4, first. The sender should do that, so that the values are all byte sized.
The Xbee analog input expects an analog voltage, not the PWM output of an Arduino analog pin.
The Xbee analog out on the XBee receiver is a PWM output.
Digital & Analog I/O
As discussed in the XBee pinout section, the modules have digital I/O, analog inputs, and PWM outputs that may be used in a variety of ways.
Direct digital output control: Through AT commands, the I/O may be set to be digital outputs and controlled as high or low. For example, the command ATD0 4 would set D0 to be a low output (0 V) and ATD0 5 would be a high output (3.3 V).
Digital and analog input for transmission: The inputs may also be set for digital input or 10-bit analog-to-digital input. Using sampling, the values of the inputs are sent as data to a receiving XBee in API Mode where the digital and ADC data is extracted.
PWM/analog output: The 10-bit PWM value of an output may be set and optionally filtered for analog output of the unit.
Line Passing: The digital inputs can control digital outputs on another node, and analog inputs can control PWM outputs on the other node.
cman6397:
Can someone help me find an easier way to do this? Am I even on the right track? I just want to be able to send analog values wirelessly and store them in a variable on the other arduino.