Hello
I wonder if you could help me with that isue. I know I always want to make it hard for myself
I have a configuration file to activate or not some sensors. Some of them have setting values.
Actually, I want to be able to use one or more DS18B20 sensors (OneWire). My station allow 5 DS18B20 sensors, but actualy I want to use two of them.
Here is my configuration file station-29.h
Consider only
- const bool bud1_active; // To activate the sensor for the buds sensors
- t_ds18b20 bud1_config; // Configuration for the bud sensors
- const bool temperature_soil_active; // ts; i; // Activate the sensors for soil tempreature
- t_ds18b20 tsoil_config; // Config for the soil temperature sensors
You will oberved, I forsee a pin to power the sensors, because I want the sensor to be powered only when a measure is taken. As the sensor is into the soil, it's not good to keep it permanently powered.
struct t_ds18b20 { // for DS18B20 calibration
const byte pinPower;
const byte pinRead;
float refMin; // Temperature of the ice
float refMax; // Temprature of the boiled water
float tMin; // Measure in the ice
float tMax; // Measure in the boiled water
};
struct ini_station
{
const char* nom;
const int station_id;
const int pcb_version;
const int analogRResolution;
bool actif; //Activate station: true/false
const int32_t tx_interval; // // (sec) 15, 30, 60 (1mn), 120 (2mn), 300 (5mn), 900 (15mn), 1800 (30mn), 3600sec (1h)
const bool mprint; // Display print in the terminal
const int sd; //Activate SD card: 0=inactive; 1=active; 2=active and read config from SD
//boolean conf_from_sd = false; // If sd is active and conf_from_sd, the sensor configuration from SD will considered instead of the conf from that ino file
bool logger; // (sd must be true) If true, the station activity will be saved into the SD card
const bool oled; // Activate the OLED display
const bool rtc; // Activate the RTC DS3231 clock
const bool rtc_calibrate; // Calibrating the RTC DS3231 clock. RTC. RTC must be true (Default false)
const bool eeprom; // Activate the EEPROM chip. It must be true to save the LoRaWAN keys
const bool watchdog;
const bool sleepMode;
const int lora; // 0=unactivate LoRaWAN; 1=OTAA; 2=ABP
const bool temperature_active; // te; a;
const bool pressure_active; // pr; b;
const bool humidity_active; // hu; c
const bool luminosity_active; // lu; d;
const byte wm1_active; // w1; e;
const byte wm2_active; // w2; f;
const byte wm3_active; // w3; g;
// bool datetime_active; // da; h; // date_time_active is always the same than rtc
const bool temperature_soil_active; // ts; i; // Must define the analog pin
t_ds18b20 tsoil_config;
const byte gauge_active; // ga; j;
const bool battery_active; // ba; k;
const byte wattering_active; // ar; l;
const byte aneno_active; // an; m;
const bool irtemp_active; // ir; n;
const bool wrm_active; // wr; o
const bool bud1_active; // b1; p;
t_ds18b20 bud1_config;
const bool bud2_active; // b2; q;
t_ds18b20 bud2_config;
const bool bud3_active; // b3; r;
t_ds18b20 bud3_config;
const bool bud4_active; // b4; s;
t_ds18b20 bud4_config;
const byte sun_active; // su; t;
const byte wdirection_active; // wd; u;
const byte wdirection_offset;
const byte sf110bud_active; // sb; v;
const byte sf110leaf_active; // sl; w;
/*
const char * nomDuCapteur;
const uint8_t codeDuCapteur;
*/
};
/*
* In the below configuration, make sure there is not analog pin conflict. For exemple, the Pyranometer (A2) can not be used with BUD station
* Watermark (Irrigation) can not be used with Bud sensor as they use the same analog pin.
*
* WATTERING must be used with A4 (18)
* RAIN GAUGE must be used with A0 (14)
* BUD sensors use A0 to A3
* WATTERMAR use A0 to A3
* WIND sensor use A0
*/
ini_station station = {
"Station 29", // Station name
29, // station ID
3, // PCB VERSION IS :0 = v2; 1 > v2; 3 = fox-board_full_mcp-v3
12, // analogReadResolution
true, // station active (true or false)
120, // TX INTERVAL (sec) 15, 30, 60 (1mn), 120 (2mn), 300 (5mn), 900 (15mn), 1800 (30mn), 3600sec (1h)
true, // mprint
0, // SD card: 0=inactive; 1=active; 2=active and read config from SD
false, // LOGGER: (SD must not be 0) If true, the station activity will be saved into the SD card
false, // OLED: Active or not
true, // RTC DS3231 I2C
false, // RTC CALIBRATE RTC Must be true. Do not forget to have it back to fase after calibrating
false, // EEMPROM: Active or not
false, // Watchdog
false, // SLEEP: Active the sleep mode (Arduinolowpower)
1, // LoRaWAN: 0=unactivate; 1=OTAA; 2=ABP;
false, // te; a;
false, // pr; b;
false, // hu; c
true, // lu; d;
15, // w1; e; // 0=Unactive; 14=A0; *15=A1*; 16=A2; 17=A3; 18=A4; 19=A5
16, // w2; f; // 0=Unactive; 14=A0; 15=A1; *16=A2*; 17=A3; 18=A4; 19=A5
17, // w3; g; // 0=Unactive; 14=A0; 15=A1; 16=A2; *17=A3*; 18=A4; 19=A5
//true, // da; h; // date_time_active is always the same than rtc
true, // ts; i; // Must define the analog pin
{4,19,0,97,0, 97}, // ts: ds18b20 calibration: Analog pin, refMin, refMax, min, max
0, // ga; j; // 0=Unactive; 14=A0; 15=A1; 16=A2; *17=A3*; 18=A4; 19=A5
true, // ba; k;
18, // ar; l; // WATTERING // 0=Unactive; 14=A0; 15=A1; 16=A2; 17=A3; *18=A4*; 19=A5
0, // an; m; // WWIND SPEED // 0=Unactive; *14=A0*; 15=A1; 16=A2; 17=A3; 18=A4; 19=A5
false, // ir; n;
false, // wr; o
true, // b1; p; // 0=Unactive; *14=A0*; 15=A1; 16=A2; 17=A3; 18=A4; 19=A5
{1,14,0,97,0,0}, // b1; ds18b20 calibration: Analog pin, refMin, refMax, min, max
false, // b2; q; // 0=Unactive; 14=A0; *15=A1*; 16=A2; 17=A3; 18=A4; 19=A5
{2,15,0,97,0,0}, // b2; ds18b20 calibration: Analog pin, refMin, refMax, min, max
false, // b3; r; // 0=Unactive; 14=A0; 15=A1; *16=A2*; 17=A3; 18=A4; 19=A5
{3,16,0,97,0,0}, // b3; ds18b20 calibration: Analog pin, refMin, refMax, min, max
false, // b4; s; // 0=Unactive; 14=A0; 15=A1; 16=A2; *17=A3*; 18=A4; 19=A5
{4,17,0,97,0,0}, // b4; ds18b20 calibration: Analog pin, refMin, refMax, min, max
0, // su; t; // SUN: // 0=Unactive; 14=A0; 15=A1; *16=A2*; 17=A3; 18=A4; 19=A5
0, // wd; u; // WIND DIRECTION 0=Unactive; 14=A0; *15=A1*; 16=A2; 17=A3; 18=A4; 19=A5 and the WindDirectionOffset
0, // Offset of the wind direction bar from the Noth (Degree). 0 if the bar point to the North
0, // sb; v; // 0=Unactive; 14=A0; 15=A1; *16=A2*; 17=A3; 18=A4; 19=A5
0, // sl; w; // 0=Unactive; 14=A0; 15=A1; *16=A2*; 17=A3; 18=A4; 19=A5
};
Now I need to initiate the ds18b20 library and the exemple start as the following before the setup()
#include <OneWire.h>
OneWire ds18x20[] = {10,11} //ds18b20_pinRead;
const int oneWireCount = sizeof(ds18x20)/sizeof(OneWire);
Ecods18b20 sensor[oneWireCount];
10 and 11 are the reading ping. It read the value returned by the sensors. I need to have the reading pin only for the active sensors.
Now, my problem starts and how to make it efficient?
First,I start has the following, but it does not filter the inactive sensors yet.
const uint8_t ds18b20_pinRead[]={station.tsoil_config.pinRead,station.bud1_config.pinRead,station.bud2_config.pinRead,station.bud3_config.pinRead,station.bud4_config.pinRead};
const uint8_t ds18b20_pinPower[]={station.tsoil_config.pinPower, station.bud1_config.pinPower, station.bud2_config.pinPower, station.bud3_config.pinPower, station.bud4_config.pinPower};
The idea is later to loop the two array and to get the power pin regarding the index of the arrays.
I do not know if it's a good way to start.
If now I change to
#include <OneWire.h>
OneWire ds18x20[] = ds18b20_pinRead; //{1,2}
const int oneWireCount = sizeof(ds18x20)/sizeof(OneWire);
Ecods18b20 sensor[oneWireCount];
I got the follwoing error
initializer fails to determine size of 'ds18x20'
Keeping in mind, ds18b20_pinRead is not dynamic, but it can have a different size when the board start, depending of the amount of active sensors.
Lastly, what it look more complicate is how to build
- uint8_t ds18b20_pinRead
- uint8_t ds18b20_pinPower
before the startup() according to the configuration file? (in my point of view ds18b20_pinRead
and ds18b20_pinPower
, does not need to be const.
How would you recommand me to do the second step?
Many thanks and I wish you a nice day!