Go Down

Topic: fio+xbee -> uno xbee = sensor values are not showing correctly? (Read 969 times) previous topic - next topic

heller

I have two xbees wich are sitting on FIO and UNO. I want to send few sensor values from FIO to UNO.

If i use serial monitor on FIO it will print all values just fine like this:
Kaikki anturit loytyi
anturi1: 26.19
anturi2: 26.12
anturi3: 26.25
valo: 466
h
l
anturi1: 26.25
anturi2: 26.06
anturi3: 26.25
valo: 448
h
l
anturi1: 26.25
anturi2: 26.06
anturi3: 26.25
valo: 439


But over the XBEE when monitoring UNO's :

anturi1: 26.37
anturi2: 26.37
anturi3: 26.50
val
o: 423
h

l

anturi1: 26.44
anturi2: 26.31
anturi3: 26.44
val
o: 445
h

l


Im using Series1 xbee's so they are just a transparent bridge. Code follows:

RECEIVER
Code: [Select]
char data;
const int ledpin = 13;

void setup() {
  Serial.begin(9600);
  pinMode(ledpin, OUTPUT);
}

void loop(){

  if(Serial.available() > 0){

    data = Serial.read();

    if(data == 'h'){
      digitalWrite(ledpin, HIGH);
      Serial.println(data);
    }

    else if(data == 'l'){
      digitalWrite(ledpin, LOW);
      Serial.println(data);
    }

    else{
      Serial.print(data); 
      delay(50);
    }
  }
}


TRANSMITTER
Code: [Select]
#include <DallasTemperature.h>
#include <OneWire.h>
//#include <LiquidCrystal.h>
//LiquidCrystal lcd(12, 11, 10, 9, 8, 7);

/*
#include <DHT.h>
#define DHTPIN 13
#define DHTTYPE DHT22
DHT dht(DHTPIN, DHTTYPE);
*/

// 1-WIRE
// anturin data-jalka
#define ONE_WIRE_BUS 6
OneWire oneWire(ONE_WIRE_BUS);
// Pass our oneWire reference to Dallas Temperature.
DallasTemperature sensors(&oneWire);
float temparray[3]; // define array for sensors
int i = 0; // int for anturilkm
int anturilkm;

const int ledpin = 13;
const int ldrpin = 6;

void setup() {
  Serial.begin(9600);
//  lcd.begin(16, 2);
  sensors.begin();

  pinMode(ledpin, OUTPUT);
  pinMode(ldrpin, INPUT);
//  dht.begin();


  anturilkm = sensors.getDeviceCount();
  if (anturilkm = 3)
  {
    Serial.println("Kaikki anturit loytyi");
  }
  else
  {
    Serial.println("virhe: anturit hukassa!");
    delay(3000);
  }
 
}


void loop(){

  sensors.requestTemperatures();
  for(i=0; i < anturilkm; i++)
  {
    temparray[i] = sensors.getTempCByIndex(i);
  }

Serial.print("anturi1: ");
Serial.println(temparray[0]);

Serial.print("anturi2: ");
Serial.println(temparray[1]);

Serial.print("anturi3: ");
Serial.println(temparray[2]);
delay(1000);

  //  float anturi1 = sensors.getTempCByIndex(0);
  //  float anturi2 = sensors.getTempCByIndex(1);
/*
   float t = dht.readTemperature();
   float h = dht.readHumidity();
   Serial.println(t);
   Serial.println(h);
  */

  int valo = analogRead(ldrpin);
  Serial.print("valo: ");
  Serial.println(valo);

  digitalWrite(ledpin, HIGH);
  Serial.println("h");
  delay(500);

  digitalWrite(ledpin, LOW);
  Serial.println("l");
 
  delay(1000);
}



PaulS

Code: [Select]
  if (anturilkm = 3)
What is the purpose of assigning the value 3 to the variable in an if statement? You want ==, there, don't you?

Code: [Select]
  Serial.begin(9600);
Stone age speed. Pick up the pace.

You appear to be mixing data that the XBee should broadcast with data that you want on the Serial Monitor. Make up your mind which you want to use Serial for. It can't be both.
The art of getting good answers lies in asking good questions.

heller

Quote
What is the purpose of assigning the value 3 to the variable in an if statement? You want ==, there, don't you?


Oops.

Quote
Stone age speed. Pick up the pace.

Ill take note on that, speed is not the issue here though. I might try it someday.

Quote
You appear to be mixing data that the XBee should broadcast with data that you want on the Serial Monitor. Make up your mind which you want to use Serial for. It can't be both.


Mixing? My point is to make UNO receive data from FIO and save it to a computer via serial monitor. So i need to read serial from UNO too. Why does it brake with the "valo" but not with the "anturiX"?

Go Up