Hi All,
I'm new to XBee and working on a project at the moment where i'm using the BME680 sensor (Temperature, Humidity, Pressure, Gas and Altitude) connected to an arduino uno and then sending that data to another arduino uno via XBee.
I'm using the Arduino IDE
The XBee at the sensor end is connected to 5v, Ground and DIN to Tx.
The XBee at the Coordinater end (connected to mac) is 5v, Ground and DOUT to Rx.
I'm able to transfer the data from the sensor (I don't need altitude) over the XBee network and display it on the recieving arduino's serial monitor (See attachements).
What i would like to do is be able to store each of the data points (temp, humidity etc) into variables to then allow me to send them as individual data points on ThingSpeak ie produce a graph for each.
My Transmitting code is
#include <Wire.h>
#include <SPI.h>
#include <Adafruit_Sensor.h>
#include "Adafruit_BME680.h"
#define BME_SCK 13
#define BME_MISO 12
#define BME_MOSI 11
#define BME_CS 10
#define SEALEVELPRESSURE_HPA (1013.25)
Adafruit_BME680 bme; // I2C
//Adafruit_BME680 bme(BME_CS); // hardware SPI
//Adafruit_BME680 bme(BME_CS, BME_MOSI, BME_MISO, BME_SCK);
void setup() {
Serial.begin(9600);
while (!Serial);
Serial.println(F("BME680 test"));
if (!bme.begin(0x76)) {
Serial.println("Could not find a valid BME680 sensor, check wiring!");
while (1);
}
// Set up oversampling and filter initialization
bme.setTemperatureOversampling(BME680_OS_8X);
bme.setHumidityOversampling(BME680_OS_2X);
bme.setPressureOversampling(BME680_OS_4X);
bme.setIIRFilterSize(BME680_FILTER_SIZE_3);
bme.setGasHeater(320, 150); // 320*C for 150 ms
}
void loop() {
if (! bme.performReading()) {
Serial.println("Failed to perform reading :(");
return;
}
float temperature = bme.temperature;
float pressure = bme.pressure /100.0;
float humidity = bme.humidity;
float gas = bme.gas_resistance / 1000.0;
Serial.print("Temperature: ");
Serial.print(temperature);
delay(1000);
Serial.print("Pressure: ");
Serial.print(pressure);
delay(1000);
Serial.print("Humidity: ");
Serial.print(humidity);
delay(1000);
Serial.print("Gas: ");
Serial.print(gas);
delay(2000);
}
My Recieving Code is
#include <Wire.h>
#include <SPI.h>
#include <Adafruit_Sensor.h>
#include "Adafruit_BME680.h"
#include <SoftwareSerial.h>
SoftwareSerial XBee(2, 3);
char incomingByte;
bool started = false;
bool ended = false;
char msg[3];
byte index;
void setup() {
Serial.begin(9600);
XBee.begin(9600);
}
void loop() {
delay(1000);
while (XBee.available() >0)
{ // If data comes in from XBee, send it out to serial monitor
Serial.write(XBee.read());
}
}
As mentioned, i can recieve the data fine and print out the data on the revieving arduino's serial monitor. I'm just unsure how the data is being transmitted and whether it can indeed be broken up to get each data point.
I've tried transmitting a starting and end variable such as '<' and '>' and then in the recieving end trying this but to no avail.
incomingByte = Serial.write(XBee.read());
//Start the message when the '<' symbol is received
if(incomingByte == '<')
(seudo code) add this to a variable etc
{
I appreciate any advice.
