Compare commits
6 Commits
9f899a4802
...
955aa7a8dd
Author | SHA1 | Date | |
---|---|---|---|
955aa7a8dd | |||
201819f2ef | |||
e7325a04a3 | |||
a86ed2d318 | |||
d958d5f8c2 | |||
797353a511 |
2
.gitignore
vendored
2
.gitignore
vendored
@ -36,3 +36,5 @@
|
|||||||
*.bin
|
*.bin
|
||||||
credentials.h
|
credentials.h
|
||||||
!schematic/KiCad/ATMEGA328PU_lowPower_weather_station/*
|
!schematic/KiCad/ATMEGA328PU_lowPower_weather_station/*
|
||||||
|
src/app/*
|
||||||
|
!src/app/*.ino
|
||||||
|
117
src/app/app.ino
Normal file
117
src/app/app.ino
Normal file
@ -0,0 +1,117 @@
|
|||||||
|
#include "definition.h"
|
||||||
|
#include "BoardConfig.h"
|
||||||
|
#include "WSPeripherals.h"
|
||||||
|
#include <LowPower.h>
|
||||||
|
|
||||||
|
BoardConfig defaultBC;
|
||||||
|
WSPeripherals WSP(defaultBC);
|
||||||
|
|
||||||
|
uint8_t sleepSlots(0), rCode(0);
|
||||||
|
DataPacket payload;
|
||||||
|
|
||||||
|
void setup()
|
||||||
|
{
|
||||||
|
#if SERIAL_DEBUG_ENABLED == 1
|
||||||
|
Serial.begin(SERIAL_BAUD_RATE);
|
||||||
|
Serial.println("Setup begin");
|
||||||
|
#endif
|
||||||
|
|
||||||
|
rCode = WSP.init();
|
||||||
|
memset(&payload, 0, sizeof(payload));
|
||||||
|
#if SERIAL_DEBUG_ENABLED == 1
|
||||||
|
Serial.print("Payload size : ");Serial.println(sizeof payload);
|
||||||
|
debugStruct(&payload);
|
||||||
|
#endif
|
||||||
|
payload.header = WEATHER_STATION;
|
||||||
|
|
||||||
|
#if SERIAL_DEBUG_ENABLED == 1
|
||||||
|
Serial.print("WSP init returned : ");Serial.println(rCode);
|
||||||
|
Serial.println("Setup end");
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
void loop()
|
||||||
|
{
|
||||||
|
if(sleepSlots == SLEEP_4_SEC_INTERVAL || !sleepSlots)
|
||||||
|
{
|
||||||
|
//We get all the measurements.
|
||||||
|
WSP.externalPeripherals(WSPeripherals::ON);
|
||||||
|
rCode = WSP.initExternalPeripherals();
|
||||||
|
|
||||||
|
#if SERIAL_DEBUG_ENABLED == 1
|
||||||
|
Serial.print("WSP peripheral init returned : ");Serial.println(rCode);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
payload.battery = WSP.batteryVoltage();
|
||||||
|
payload.ldr = WSP.sunlightMeasurement();
|
||||||
|
WSP.temperatureAndATMPressureFromBMP280(&payload.bmpTemp, &payload.bmpPress);
|
||||||
|
payload.humidity = WSP.humidity();
|
||||||
|
payload.compensatedHumidity = WSP.compensatedHumidity();
|
||||||
|
payload.htuTemp = WSP.temperatureFromHTU21();
|
||||||
|
|
||||||
|
#if SERIAL_DEBUG_ENABLED == 1
|
||||||
|
debugStruct(&payload);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
//We send it over the air.
|
||||||
|
if(WSP.getRadio().isChipConnected())
|
||||||
|
{
|
||||||
|
WSP.applyRadioConfig();
|
||||||
|
WSP.getRadio().setRetries(10,20);
|
||||||
|
WSP.getRadio().openWritingPipe((const uint8_t *)RADIO_NODE_ADDRESS);
|
||||||
|
//WSP.getRadio().setPayloadSize(sizeof payload);
|
||||||
|
bool result = WSP.getRadio().write(&payload, sizeof(payload));
|
||||||
|
#if SERIAL_DEBUG_ENABLED == 1
|
||||||
|
if(result)
|
||||||
|
Serial.println("Payload sent !");
|
||||||
|
else
|
||||||
|
Serial.println("Failed to send payload !");
|
||||||
|
delay(100);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
#if SERIAL_DEBUG_ENABLED == 1
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Serial.println("NRF missing !");
|
||||||
|
delay(100);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
WSP.externalPeripherals(WSPeripherals::OFF);
|
||||||
|
payload.id++;
|
||||||
|
sleepSlots = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
//Lets sleep for 4 secondes
|
||||||
|
LowPower.powerDown(SLEEP_4S, ADC_OFF, BOD_OFF);
|
||||||
|
sleepSlots++;
|
||||||
|
}
|
||||||
|
|
||||||
|
void debugStruct(DataPacket *p)
|
||||||
|
{
|
||||||
|
Serial.println("##############DATA##############");
|
||||||
|
Serial.print("ID : ");
|
||||||
|
Serial.println(p->id);
|
||||||
|
|
||||||
|
Serial.print("HEADER : ");
|
||||||
|
Serial.println(p->header);
|
||||||
|
|
||||||
|
Serial.print("BATT : ");
|
||||||
|
Serial.print(p->battery);
|
||||||
|
Serial.println(" V");
|
||||||
|
|
||||||
|
Serial.print("LDR : ");
|
||||||
|
Serial.println(p->ldr);
|
||||||
|
|
||||||
|
Serial.print("BMP TEMP : ");
|
||||||
|
Serial.print(p->bmpTemp);
|
||||||
|
Serial.println(" *C");
|
||||||
|
|
||||||
|
Serial.print("BMP PRESS : ");
|
||||||
|
Serial.print(p->bmpPress);
|
||||||
|
Serial.println(" Pa");
|
||||||
|
|
||||||
|
Serial.print("HUM : ");Serial.println(p->humidity);
|
||||||
|
Serial.print("COM HUM : ");Serial.println(p->compensatedHumidity);
|
||||||
|
Serial.print("HTU TEMP : ");Serial.println(p->htuTemp);
|
||||||
|
}
|
@ -10,7 +10,7 @@ uint8_t WSPeripherals::init()
|
|||||||
pinMode(_boardConfig.LDOEnable, OUTPUT);
|
pinMode(_boardConfig.LDOEnable, OUTPUT);
|
||||||
_3V3PowerRail(OFF);
|
_3V3PowerRail(OFF);
|
||||||
pinMode(_boardConfig.LDRVSensEnable, OUTPUT);
|
pinMode(_boardConfig.LDRVSensEnable, OUTPUT);
|
||||||
digitalWrite(_boardConfig.LDRVSensEnable, HIGH); //High means that it is disabled and low is active /!\
|
digitalWrite(_boardConfig.LDRVSensEnable, HIGH); //High means that it is disabled and low is active /!\/
|
||||||
pinMode(_boardConfig.BATVSensEnable, OUTPUT);
|
pinMode(_boardConfig.BATVSensEnable, OUTPUT);
|
||||||
digitalWrite(_boardConfig.BATVSensEnable, LOW);
|
digitalWrite(_boardConfig.BATVSensEnable, LOW);
|
||||||
|
|
||||||
@ -41,15 +41,15 @@ uint8_t WSPeripherals::init()
|
|||||||
uint8_t WSPeripherals::initExternalPeripherals()
|
uint8_t WSPeripherals::initExternalPeripherals()
|
||||||
{
|
{
|
||||||
uint8_t toReturn(0);
|
uint8_t toReturn(0);
|
||||||
_BMP280.setSampling( Adafruit_BMP280::MODE_FORCED,
|
|
||||||
Adafruit_BMP280::SAMPLING_X16,
|
|
||||||
Adafruit_BMP280::SAMPLING_X16,
|
|
||||||
Adafruit_BMP280::FILTER_X16,
|
|
||||||
Adafruit_BMP280::STANDBY_MS_4000);
|
|
||||||
|
|
||||||
toReturn |= _BMP280.begin(0x76);
|
toReturn |= _BMP280.begin(0x76);
|
||||||
toReturn |= _HTU21.begin() << 1;
|
toReturn |= _HTU21.begin() << 1;
|
||||||
toReturn |= _NRF.begin() << 2;
|
toReturn |= _NRF.begin() << 2;
|
||||||
|
|
||||||
|
//We disable the I2C internal pullups :
|
||||||
|
digitalWrite(SDA, LOW);
|
||||||
|
digitalWrite(SCL, LOW);
|
||||||
|
|
||||||
return toReturn;
|
return toReturn;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -73,14 +73,20 @@ int WSPeripherals::sunlightMeasurement()
|
|||||||
return rawSunlightMeasurement;
|
return rawSunlightMeasurement;
|
||||||
}
|
}
|
||||||
|
|
||||||
float WSPeripherals::temperatureFromBMP280()
|
void WSPeripherals::temperatureAndATMPressureFromBMP280(float *temperature, float *ATMPressure)
|
||||||
{
|
{
|
||||||
return _BMP280.readTemperature();
|
if(!temperature && !ATMPressure)return;
|
||||||
}
|
|
||||||
|
|
||||||
float WSPeripherals::ATMPressure()
|
_BMP280.setSampling( Adafruit_BMP280::MODE_FORCED,
|
||||||
{
|
Adafruit_BMP280::SAMPLING_X16,
|
||||||
return _BMP280.readPressure();
|
Adafruit_BMP280::SAMPLING_X16,
|
||||||
|
Adafruit_BMP280::FILTER_X16,
|
||||||
|
Adafruit_BMP280::STANDBY_MS_4000);
|
||||||
|
if(temperature)
|
||||||
|
*temperature = _BMP280.readTemperature();
|
||||||
|
|
||||||
|
if(ATMPressure)
|
||||||
|
*ATMPressure = _BMP280.readPressure();
|
||||||
}
|
}
|
||||||
|
|
||||||
float WSPeripherals::temperatureFromHTU21()
|
float WSPeripherals::temperatureFromHTU21()
|
||||||
@ -101,7 +107,15 @@ float WSPeripherals::compensatedHumidity()
|
|||||||
void WSPeripherals::_3V3PowerRail(State state)
|
void WSPeripherals::_3V3PowerRail(State state)
|
||||||
{
|
{
|
||||||
digitalWrite(_boardConfig.LDOEnable, state);
|
digitalWrite(_boardConfig.LDOEnable, state);
|
||||||
|
if(state) //We let some time for the voltage to stabilize on the rail.
|
||||||
|
delay(2);
|
||||||
}
|
}
|
||||||
|
|
||||||
const RF24 &WSPeripherals::getRadio(){return _NRF;}
|
const RF24 &WSPeripherals::getRadio(){return _NRF;}
|
||||||
void WSPeripherals::applyRadioConfig(uint8_t channel = RADIO_CHANNEL, uint8_t paLevel = RADIO_PA_LEVEL, rf24_datarate_e datarate = RADIO_DATARATE);
|
|
||||||
|
void WSPeripherals::applyRadioConfig(uint8_t channel, uint8_t paLevel, rf24_datarate_e datarate)
|
||||||
|
{
|
||||||
|
_NRF.setChannel(channel);
|
||||||
|
_NRF.setPALevel(paLevel);
|
||||||
|
_NRF.setDataRate(datarate);
|
||||||
|
}
|
||||||
|
@ -36,8 +36,7 @@ class WSPeripherals
|
|||||||
|
|
||||||
float batteryVoltage();
|
float batteryVoltage();
|
||||||
int sunlightMeasurement();
|
int sunlightMeasurement();
|
||||||
float temperatureFromBMP280();
|
void temperatureAndATMPressureFromBMP280(float *temperature = NULL, float *ATMPressure = NULL);
|
||||||
float ATMPressure();
|
|
||||||
float temperatureFromHTU21();
|
float temperatureFromHTU21();
|
||||||
float humidity();
|
float humidity();
|
||||||
float compensatedHumidity();
|
float compensatedHumidity();
|
||||||
@ -45,12 +44,7 @@ class WSPeripherals
|
|||||||
/*
|
/*
|
||||||
* Before calling this method, externalPeripherals(ON) and initExternalPeripherals() must be called respectively
|
* Before calling this method, externalPeripherals(ON) and initExternalPeripherals() must be called respectively
|
||||||
*/
|
*/
|
||||||
void applyRadioConfig(uint8_t channel, uint8_t paLevel, rf24_datarate_e datarate)
|
void applyRadioConfig(uint8_t channel = RADIO_CHANNEL, uint8_t paLevel = RADIO_PA_LEVEL, rf24_datarate_e datarate = RADIO_DATARATE);
|
||||||
{
|
|
||||||
_NRF.setChannel(channel);
|
|
||||||
_NRF.setPALevel(paLevel);
|
|
||||||
_NRF.setDataRate(rf24_datarate_e);
|
|
||||||
}
|
|
||||||
const RF24 &getRadio();
|
const RF24 &getRadio();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
@ -8,9 +8,10 @@
|
|||||||
|
|
||||||
#include <Arduino.h>
|
#include <Arduino.h>
|
||||||
#include <RF24.h>
|
#include <RF24.h>
|
||||||
|
#include "packet_format.h"
|
||||||
|
|
||||||
//Serial debug config part
|
//Serial debug config part
|
||||||
#define SERIAL_DEBUG_ENABLED 0
|
#define SERIAL_DEBUG_ENABLED 1
|
||||||
#define SERIAL_BAUD_RATE 115200
|
#define SERIAL_BAUD_RATE 115200
|
||||||
|
|
||||||
//Battery config part
|
//Battery config part
|
||||||
@ -23,6 +24,9 @@
|
|||||||
#define RADIO_PA_LEVEL RF24_PA_MAX
|
#define RADIO_PA_LEVEL RF24_PA_MAX
|
||||||
#define RADIO_DATARATE RF24_250KBPS
|
#define RADIO_DATARATE RF24_250KBPS
|
||||||
|
|
||||||
|
//Seep config part
|
||||||
|
#define SLEEP_4_SEC_INTERVAL 1//15
|
||||||
|
|
||||||
//Pin config part
|
//Pin config part
|
||||||
typedef enum
|
typedef enum
|
||||||
{
|
{
|
||||||
@ -40,4 +44,18 @@ typedef enum
|
|||||||
A1_LDR_V_SENS = A1,
|
A1_LDR_V_SENS = A1,
|
||||||
} Pin;
|
} Pin;
|
||||||
|
|
||||||
|
//Payload structure
|
||||||
|
typedef struct
|
||||||
|
{
|
||||||
|
uint16_t id;
|
||||||
|
HEADER_e header : 6;
|
||||||
|
unsigned int ldr : 10;
|
||||||
|
float battery;
|
||||||
|
float bmpTemp;
|
||||||
|
float bmpPress;
|
||||||
|
float humidity;
|
||||||
|
float compensatedHumidity;
|
||||||
|
float htuTemp;
|
||||||
|
} DataPacket __attribute__((__packed__));
|
||||||
|
|
||||||
#endif //DEFINITION_H
|
#endif //DEFINITION_H
|
||||||
|
6
src/tests/packet_format.h
Normal file
6
src/tests/packet_format.h
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
#ifndef PACKET_FORMAT_H
|
||||||
|
#define PACKET_FORMAT_H
|
||||||
|
|
||||||
|
enum HEADER_e {WEATHER_STATION = 0};
|
||||||
|
|
||||||
|
#endif //PACKET_FORMAT_H
|
@ -14,16 +14,17 @@
|
|||||||
|
|
||||||
BoardConfig defaultBC; //Default config is applied
|
BoardConfig defaultBC; //Default config is applied
|
||||||
WSPeripherals WSP(defaultBC);
|
WSPeripherals WSP(defaultBC);
|
||||||
|
float BMPTemperature(0), ATMPressure(0);
|
||||||
|
|
||||||
void setup()
|
void setup()
|
||||||
{
|
{
|
||||||
Serial.begin(SERIAL_BAUD_RATE);
|
Serial.begin(SERIAL_BAUD_RATE);
|
||||||
Serial.println("Setup begin");
|
Serial.println("Setup begin");
|
||||||
uint8_t code = WSP.init();
|
uint8_t code = WSP.init();
|
||||||
Serial.print("WSP init returned : ");Serial.print(code);
|
Serial.print("WSP init returned : ");Serial.println(code);
|
||||||
WSP.externalPeripherals(WSPeripherals::ON);
|
WSP.externalPeripherals(WSPeripherals::ON);
|
||||||
code = WSP.initExternalPeripherals();
|
code = WSP.initExternalPeripherals();
|
||||||
Serial.print("WSP init external peripheral returned : ");Serial.print(code);
|
Serial.print("WSP init external peripheral returned : ");Serial.println(code);
|
||||||
Serial.println("Setup end");
|
Serial.println("Setup end");
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -37,25 +38,30 @@ void loop()
|
|||||||
Serial.print("LDR : ");
|
Serial.print("LDR : ");
|
||||||
Serial.println(WSP.sunlightMeasurement());
|
Serial.println(WSP.sunlightMeasurement());
|
||||||
|
|
||||||
|
WSP.temperatureAndATMPressureFromBMP280(&BMPTemperature, &ATMPressure);
|
||||||
|
|
||||||
Serial.print("BMP TEMP : ");
|
Serial.print("BMP TEMP : ");
|
||||||
Serial.print(WSP.temperatureFromBMP280());
|
Serial.print(BMPTemperature);
|
||||||
|
Serial.println(" *C");
|
||||||
|
|
||||||
|
Serial.print("HTU TEMP : ");
|
||||||
|
Serial.print(WSP.temperatureFromHTU21());
|
||||||
Serial.println(" *C");
|
Serial.println(" *C");
|
||||||
|
|
||||||
Serial.print("BMP PRESS : ");
|
Serial.print("BMP PRESS : ");
|
||||||
Serial.print(WSP.ATMPressure());
|
Serial.print(ATMPressure);
|
||||||
Serial.println(" Pa");
|
Serial.println(" Pa");
|
||||||
|
|
||||||
Serial.print("HUM : ");Serial.println(WSP.humidity());
|
Serial.print("HUM : ");Serial.println(WSP.humidity());
|
||||||
Serial.print("COM HUM : ");Serial.println(WSP.compensatedHumidity());
|
Serial.print("COM HUM : ");Serial.println(WSP.compensatedHumidity());
|
||||||
Serial.print("HTU TEMP : ");Serial.println(WSP.temperatureFromHTU21());
|
|
||||||
|
|
||||||
if(!WSP.getRadio().isChipConnected())
|
if(!WSP.getRadio().isChipConnected())
|
||||||
{
|
{
|
||||||
Serial.println("Chip is missing");
|
Serial.println("Radio is missing");
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
Serial.println("Chip is present");
|
Serial.println("Radio is present");
|
||||||
}
|
}
|
||||||
|
|
||||||
delay(1000);
|
delay(1000);
|
||||||
|
Loading…
Reference in New Issue
Block a user