mapping/wireless transmitting/lcd help
i'm having difficulties trying transmit battery voltage measurement data. i've created external voltage divider in order create necessary 5v max analog input. want transmit data arduino board (via xbee) create remote battery monitor. below code have right (not of it, parts pertain problem.
the transmitter code:
the code receiver:
when run code, know value transmitted 169, received value 28. suggestions?
the transmitter code:
code: [select]
int b_volt = 3;
byte batvolt;
void setup() {
serial.begin(19200);
}
void loop() {
batvolt = map(analogread(b_volt), 0, 1023, 0, 245);
serial.print(250, byte); // ------------------------sync
serial.print(batvolt, byte); //battery voltage reading
}
the code receiver:
code: [select]
byte rembatvolt;
void setup() {
serial.begin(19200);
}
void loop() {
if (serial.available() > 0) {
incoming = serial.read();
if (int(incoming) == 250) {
rembatvolt = serial.read();
rembatvolt = map(rembatvolt, 0, 245, 0, 1023);
}
}
lcd.setcursor(0,0);
lcd.print("remote batt.: ");
lcd.print((int(rembatvolt) / 83),dec);
lcd.print(".");
lcd.print((int(rembatvolt) % 83),dec);
lcd.print("v");
}
when run code, know value transmitted 169, received value 28. suggestions?
code: [select]
if (serial.available() > 0) {
incoming = serial.read();
if (int(incoming) == 250) {
rembatvolt = serial.read();
you check @ least 1 byte, , read 2 (if first 250).
you need make sure second byte has arrived before trying read it.
quote
when run code, know value transmitted 169
which one? sending 2 values.
quote
but received value 28
which one? receiving 2 values.
code: [select]
lcd.print((int(rembatvolt) / 83),dec);
lcd.print(".");
lcd.print((int(rembatvolt) % 83),dec);
83? did come from?
Arduino Forum > Forum 2005-2010 (read only) > Software > Syntax & Programs > mapping/wireless transmitting/lcd help
arduino
Comments
Post a Comment