From f15bc982ca7f40137998ee054fb8458112b6d6c0 Mon Sep 17 00:00:00 2001 From: Stefan Holzheu Date: Fri, 21 Apr 2023 11:33:22 +0200 Subject: [PATCH] 0.2.2 + Add delay to GPRS-Examples to make GPRS more stable + Cleanup Board examples --- libraries/BayEOSBoards/LowCurrentBoard.h | 7 +- libraries/BayEOSBoards/RF24RouterBoard.h | 1 + .../BoardTest/BoardTest.ino} | 0 .../{HX711 => HX711_ET215}/Logger/Logger.ino | 0 .../LoggerWithConf/LoggerWithConf.ino | 0 .../SerialCTS/SerialCTS.ino | 0 .../HX711_ET215/SerialESP/SerialESP.ino | 133 +++++++++++ .../{HX711 => HX711_ET215}/read/read.ino | 0 .../readWithConf/readWithConf.ino | 0 .../sendWithConf/sendWithConf.ino | 0 .../BoardTest/BoardTest.ino} | 0 .../ESP01Dallas/ESP01Dallas.ino} | 0 .../ET220-Scale/01_SendRaw/01_SendRaw.ino | 0 .../02_WriteCalibration.ino | 0 .../03_SendWeight/03_SendWeight.ino | 0 .../Logger/Logger.ino} | 0 .../RF24Dallas/RF24Dallas.ino} | 0 .../SerialCTS/SerialCTS.ino} | 0 .../read/read.ino} | 0 .../GPRSTemplateSPIFlash.ino | 8 +- .../LowCurrentGPRS_SPIFlash.ino | 221 ------------------ .../MCP_MplexShield/Logger/Logger.ino | 158 ------------- .../readChannels/readChannels.ino | 46 ---- .../MCP_MplexShield/readNTC10/readNTC10.ino | 53 ----- .../examples/Max11212_dendro/GPRS/GPRS.ino | 10 +- .../examples/SDI12/ClimaVue50/ClimaVue50.ino | 130 +++++++++++ .../SapFlowBoard/DendroGPRS/DendroGPRS.ino | 10 +- .../examples/Soilwatch10Shield/RF24/RF24.ino | 66 ------ .../examples/Soilwatch10Shield/read/read.ino | 24 -- .../examples/Thermo_ET220/GPRS/GPRS.ino | 95 ++++---- .../examples/calibration/calibration.ino | 132 +++++++++++ 31 files changed, 466 insertions(+), 628 deletions(-) rename libraries/BayEOSBoards/examples/{HX711/BoardTestET208/BoardTestET208.ino => HX711_ET215/BoardTest/BoardTest.ino} (100%) rename libraries/BayEOSBoards/examples/{HX711 => HX711_ET215}/Logger/Logger.ino (100%) rename libraries/BayEOSBoards/examples/{HX711 => HX711_ET215}/LoggerWithConf/LoggerWithConf.ino (100%) rename libraries/BayEOSBoards/examples/{HX711 => HX711_ET215}/SerialCTS/SerialCTS.ino (100%) create mode 100644 libraries/BayEOSBoards/examples/HX711_ET215/SerialESP/SerialESP.ino rename libraries/BayEOSBoards/examples/{HX711 => HX711_ET215}/read/read.ino (100%) rename libraries/BayEOSBoards/examples/{HX711 => HX711_ET215}/readWithConf/readWithConf.ino (100%) rename libraries/BayEOSBoards/examples/{HX711 => HX711_ET215}/sendWithConf/sendWithConf.ino (100%) rename libraries/BayEOSBoards/examples/{HX711/BoardTestET220/BoardTestET220.ino => HX711_ET220/BoardTest/BoardTest.ino} (100%) rename libraries/BayEOSBoards/examples/{HX711/ESP01Dallas_ET220/ESP01Dallas_ET220.ino => HX711_ET220/ESP01Dallas/ESP01Dallas.ino} (100%) rename libraries/BayEOSBoards/examples/{HX711 => HX711_ET220}/ET220-Scale/01_SendRaw/01_SendRaw.ino (100%) rename libraries/BayEOSBoards/examples/{HX711 => HX711_ET220}/ET220-Scale/02_WriteCalibration/02_WriteCalibration.ino (100%) rename libraries/BayEOSBoards/examples/{HX711 => HX711_ET220}/ET220-Scale/03_SendWeight/03_SendWeight.ino (100%) rename libraries/BayEOSBoards/examples/{HX711/LoggerET220/LoggerET220.ino => HX711_ET220/Logger/Logger.ino} (100%) rename libraries/BayEOSBoards/examples/{HX711/RF24Dallas_ET220/RF24Dallas_ET220.ino => HX711_ET220/RF24Dallas/RF24Dallas.ino} (100%) rename libraries/BayEOSBoards/examples/{HX711/SerialCTS_ET220/SerialCTS_ET220.ino => HX711_ET220/SerialCTS/SerialCTS.ino} (100%) rename libraries/BayEOSBoards/examples/{HX711/readET220/readET220.ino => HX711_ET220/read/read.ino} (100%) delete mode 100644 libraries/BayEOSBoards/examples/LowCurrentBoard/LowCurrentGPRS_SPIFlash/LowCurrentGPRS_SPIFlash.ino delete mode 100644 libraries/BayEOSBoards/examples/MCP_MplexShield/Logger/Logger.ino delete mode 100644 libraries/BayEOSBoards/examples/MCP_MplexShield/readChannels/readChannels.ino delete mode 100644 libraries/BayEOSBoards/examples/MCP_MplexShield/readNTC10/readNTC10.ino create mode 100644 libraries/BayEOSBoards/examples/SDI12/ClimaVue50/ClimaVue50.ino delete mode 100644 libraries/BayEOSBoards/examples/Soilwatch10Shield/RF24/RF24.ino delete mode 100644 libraries/BayEOSBoards/examples/Soilwatch10Shield/read/read.ino create mode 100644 libraries/HX711Array/examples/calibration/calibration.ino diff --git a/libraries/BayEOSBoards/LowCurrentBoard.h b/libraries/BayEOSBoards/LowCurrentBoard.h index af9af1c..fc3d640 100644 --- a/libraries/BayEOSBoards/LowCurrentBoard.h +++ b/libraries/BayEOSBoards/LowCurrentBoard.h @@ -340,8 +340,11 @@ void initLCB() { pinMode(LED_PIN, OUTPUT); #endif #if WITHRAINGAUGE - digitalWrite(2,HIGH); //Enable Pullup on Pin 2 == INT0 - attachInterrupt(0,rain_isr,FALLING); +#ifndef RAINGAUGEPIN +#define RAINGAUGEPIN 2 +#endif + digitalWrite(RAINGAUGEPIN,HIGH); //Enable Pullup on Pin 2 == INT0 + attachInterrupt(digitalPinToInterrupt(RAINGAUGEPIN),rain_isr,FALLING); rain_count=0; rain_event=0; #endif diff --git a/libraries/BayEOSBoards/RF24RouterBoard.h b/libraries/BayEOSBoards/RF24RouterBoard.h index 2c61ea5..30e4271 100644 --- a/libraries/BayEOSBoards/RF24RouterBoard.h +++ b/libraries/BayEOSBoards/RF24RouterBoard.h @@ -334,6 +334,7 @@ void initLCB() { blinkLED(2); adjust_OSCCAL(); #ifdef GPRS_CONFIG + delayLCB(1000); tx_res = client.begin(38400); if (! tx_res) myRTC.adjust(client.now()); #else diff --git a/libraries/BayEOSBoards/examples/HX711/BoardTestET208/BoardTestET208.ino b/libraries/BayEOSBoards/examples/HX711_ET215/BoardTest/BoardTest.ino similarity index 100% rename from libraries/BayEOSBoards/examples/HX711/BoardTestET208/BoardTestET208.ino rename to libraries/BayEOSBoards/examples/HX711_ET215/BoardTest/BoardTest.ino diff --git a/libraries/BayEOSBoards/examples/HX711/Logger/Logger.ino b/libraries/BayEOSBoards/examples/HX711_ET215/Logger/Logger.ino similarity index 100% rename from libraries/BayEOSBoards/examples/HX711/Logger/Logger.ino rename to libraries/BayEOSBoards/examples/HX711_ET215/Logger/Logger.ino diff --git a/libraries/BayEOSBoards/examples/HX711/LoggerWithConf/LoggerWithConf.ino b/libraries/BayEOSBoards/examples/HX711_ET215/LoggerWithConf/LoggerWithConf.ino similarity index 100% rename from libraries/BayEOSBoards/examples/HX711/LoggerWithConf/LoggerWithConf.ino rename to libraries/BayEOSBoards/examples/HX711_ET215/LoggerWithConf/LoggerWithConf.ino diff --git a/libraries/BayEOSBoards/examples/HX711/SerialCTS/SerialCTS.ino b/libraries/BayEOSBoards/examples/HX711_ET215/SerialCTS/SerialCTS.ino similarity index 100% rename from libraries/BayEOSBoards/examples/HX711/SerialCTS/SerialCTS.ino rename to libraries/BayEOSBoards/examples/HX711_ET215/SerialCTS/SerialCTS.ino diff --git a/libraries/BayEOSBoards/examples/HX711_ET215/SerialESP/SerialESP.ino b/libraries/BayEOSBoards/examples/HX711_ET215/SerialESP/SerialESP.ino new file mode 100644 index 0000000..e81933e --- /dev/null +++ b/libraries/BayEOSBoards/examples/HX711_ET215/SerialESP/SerialESP.ino @@ -0,0 +1,133 @@ +/**************************************************************** + + Sketch for ESP01 Serial Router connected + to BayEOS Low Power Board via FTDI connection + + +***************************************************************/ +#define ACTION_COUNT 1 + +#include +#include +#include +#include +#include + +#define ESP01_POWER_PIN 7 +#define BOARD_NAME "HX711ESP" +#define POWER_PIN 7 +#define BAT_MULTIPLIER 3.3*(100+100)/100/1023 +#define ADC_BATPIN A7 +// we will collect 60 measurements before we try to send +#define WLAN_SEND_COUNT 10 +#define SAMPLING_INT 32 + +uint16_t wlan_counter = 0; +uint8_t tx_error, res, wlan_status, low_bat = 0; +float bat, tmp_float; +unsigned long last_measurement; + +SPIFlash flash(8); +BayEOSBufferSPIFlash myBuffer; +BaySerialESP client(Serial, ESP01_POWER_PIN); + +#include +#include +uint8_t dout[] = { 6 }; +uint8_t sck = 3; +long adc[1]; +float temp0; + +HX711Array scale; +NTC_HX711 ntc(scale, 2 * 470000, 3.0); //adjust resistor values +Scale4PointCal cal0; + + +#include + + +void setup(void) { + initLCB(); //init time2 + adjust_OSCCAL(); + //CHANGE CONFIG!! + client.begin(38400); + myBuffer.init(flash); //This will restore old pointers + //myBuffer.reset(); + client.setBuffer(myBuffer); + myBuffer.setRTC(myRTC, 0); //Nutze RTC relativ! + myBuffer.skip(); //skip the unread frames in Buffer!! + client.powerUp(); + while(client.isReady()){ + blinkLED(2); + delay(1000); + } + uint8_t res; + while (res = client.setName(BOARD_NAME)) { + if (res == 10 + strlen(BOARD_NAME)) break; + blinkLED(res); + delay(res * 500 + 2000); + } + + blinkLED(client.sendMessage("Board started") + 1); client.powerDown(); + + scale.begin(dout, 1, sck); //start HX711Array with 1 ADCs + cal0.readConf(); + + + startLCB(); + wlan_counter = WLAN_SEND_COUNT - 2; + last_measurement = myRTC.now().get(); +} + +void loop() +{ + if (ISSET_ACTION(0)) { + UNSET_ACTION(0); + client.startDataFrame(); + client.addChannelValue(millis()); + pinMode(POWER_PIN,OUTPUT); + digitalWrite(POWER_PIN,HIGH); + analogReference(DEFAULT); + bat = BAT_MULTIPLIER * analogRead(ADC_BATPIN); + digitalWrite(POWER_PIN,LOW); + + client.addChannelValue(bat); + //Some DEBUG values + ntc.readResistance(); + temp0 = ntc.getTemp(0); + scale.power_up(); + scale.read_average(adc, 2); + scale.read_average(adc); + scale.power_down(); + client.addChannelValue(temp0); + client.addChannelValue(adc[0]); + client.addChannelValue(cal0.getWeight(adc[0], temp0)); + client.writeToBuffer(); + wlan_counter++; + + } + + if (ISSET_ACTION(7)) { + UNSET_ACTION(7); + if (wlan_counter > WLAN_SEND_COUNT) { + adjust_OSCCAL(); + if (! wlan_status) { + client.powerUp(); + wlan_status = 1; + } + if (res = client.sendMultiFromBuffer()) tx_error ++; + else tx_error = 0; + blinkLED(res + 1); + if (tx_error > 5 || myBuffer.available() == 0) { + wlan_counter = 0; + wlan_status = 0; + client.powerDown(); + tx_error = 0; + } + } + } + + + sleepLCB(); + +} diff --git a/libraries/BayEOSBoards/examples/HX711/read/read.ino b/libraries/BayEOSBoards/examples/HX711_ET215/read/read.ino similarity index 100% rename from libraries/BayEOSBoards/examples/HX711/read/read.ino rename to libraries/BayEOSBoards/examples/HX711_ET215/read/read.ino diff --git a/libraries/BayEOSBoards/examples/HX711/readWithConf/readWithConf.ino b/libraries/BayEOSBoards/examples/HX711_ET215/readWithConf/readWithConf.ino similarity index 100% rename from libraries/BayEOSBoards/examples/HX711/readWithConf/readWithConf.ino rename to libraries/BayEOSBoards/examples/HX711_ET215/readWithConf/readWithConf.ino diff --git a/libraries/BayEOSBoards/examples/HX711/sendWithConf/sendWithConf.ino b/libraries/BayEOSBoards/examples/HX711_ET215/sendWithConf/sendWithConf.ino similarity index 100% rename from libraries/BayEOSBoards/examples/HX711/sendWithConf/sendWithConf.ino rename to libraries/BayEOSBoards/examples/HX711_ET215/sendWithConf/sendWithConf.ino diff --git a/libraries/BayEOSBoards/examples/HX711/BoardTestET220/BoardTestET220.ino b/libraries/BayEOSBoards/examples/HX711_ET220/BoardTest/BoardTest.ino similarity index 100% rename from libraries/BayEOSBoards/examples/HX711/BoardTestET220/BoardTestET220.ino rename to libraries/BayEOSBoards/examples/HX711_ET220/BoardTest/BoardTest.ino diff --git a/libraries/BayEOSBoards/examples/HX711/ESP01Dallas_ET220/ESP01Dallas_ET220.ino b/libraries/BayEOSBoards/examples/HX711_ET220/ESP01Dallas/ESP01Dallas.ino similarity index 100% rename from libraries/BayEOSBoards/examples/HX711/ESP01Dallas_ET220/ESP01Dallas_ET220.ino rename to libraries/BayEOSBoards/examples/HX711_ET220/ESP01Dallas/ESP01Dallas.ino diff --git a/libraries/BayEOSBoards/examples/HX711/ET220-Scale/01_SendRaw/01_SendRaw.ino b/libraries/BayEOSBoards/examples/HX711_ET220/ET220-Scale/01_SendRaw/01_SendRaw.ino similarity index 100% rename from libraries/BayEOSBoards/examples/HX711/ET220-Scale/01_SendRaw/01_SendRaw.ino rename to libraries/BayEOSBoards/examples/HX711_ET220/ET220-Scale/01_SendRaw/01_SendRaw.ino diff --git a/libraries/BayEOSBoards/examples/HX711/ET220-Scale/02_WriteCalibration/02_WriteCalibration.ino b/libraries/BayEOSBoards/examples/HX711_ET220/ET220-Scale/02_WriteCalibration/02_WriteCalibration.ino similarity index 100% rename from libraries/BayEOSBoards/examples/HX711/ET220-Scale/02_WriteCalibration/02_WriteCalibration.ino rename to libraries/BayEOSBoards/examples/HX711_ET220/ET220-Scale/02_WriteCalibration/02_WriteCalibration.ino diff --git a/libraries/BayEOSBoards/examples/HX711/ET220-Scale/03_SendWeight/03_SendWeight.ino b/libraries/BayEOSBoards/examples/HX711_ET220/ET220-Scale/03_SendWeight/03_SendWeight.ino similarity index 100% rename from libraries/BayEOSBoards/examples/HX711/ET220-Scale/03_SendWeight/03_SendWeight.ino rename to libraries/BayEOSBoards/examples/HX711_ET220/ET220-Scale/03_SendWeight/03_SendWeight.ino diff --git a/libraries/BayEOSBoards/examples/HX711/LoggerET220/LoggerET220.ino b/libraries/BayEOSBoards/examples/HX711_ET220/Logger/Logger.ino similarity index 100% rename from libraries/BayEOSBoards/examples/HX711/LoggerET220/LoggerET220.ino rename to libraries/BayEOSBoards/examples/HX711_ET220/Logger/Logger.ino diff --git a/libraries/BayEOSBoards/examples/HX711/RF24Dallas_ET220/RF24Dallas_ET220.ino b/libraries/BayEOSBoards/examples/HX711_ET220/RF24Dallas/RF24Dallas.ino similarity index 100% rename from libraries/BayEOSBoards/examples/HX711/RF24Dallas_ET220/RF24Dallas_ET220.ino rename to libraries/BayEOSBoards/examples/HX711_ET220/RF24Dallas/RF24Dallas.ino diff --git a/libraries/BayEOSBoards/examples/HX711/SerialCTS_ET220/SerialCTS_ET220.ino b/libraries/BayEOSBoards/examples/HX711_ET220/SerialCTS/SerialCTS.ino similarity index 100% rename from libraries/BayEOSBoards/examples/HX711/SerialCTS_ET220/SerialCTS_ET220.ino rename to libraries/BayEOSBoards/examples/HX711_ET220/SerialCTS/SerialCTS.ino diff --git a/libraries/BayEOSBoards/examples/HX711/readET220/readET220.ino b/libraries/BayEOSBoards/examples/HX711_ET220/read/read.ino similarity index 100% rename from libraries/BayEOSBoards/examples/HX711/readET220/readET220.ino rename to libraries/BayEOSBoards/examples/HX711_ET220/read/read.ino diff --git a/libraries/BayEOSBoards/examples/LowCurrentBoard/GPRSTemplateSPIFlash/GPRSTemplateSPIFlash.ino b/libraries/BayEOSBoards/examples/LowCurrentBoard/GPRSTemplateSPIFlash/GPRSTemplateSPIFlash.ino index 225f064..877493f 100644 --- a/libraries/BayEOSBoards/examples/LowCurrentBoard/GPRSTemplateSPIFlash/GPRSTemplateSPIFlash.ino +++ b/libraries/BayEOSBoards/examples/LowCurrentBoard/GPRSTemplateSPIFlash/GPRSTemplateSPIFlash.ino @@ -52,6 +52,7 @@ void setup() startLCB(); //some settings and blink three times client.readConfigFromStringPGM(PSTR(GPRS_CONFIG)); //read GPRS config into RAM adjust_OSCCAL(); //tune clock of ATMega to make serial communication more stable + delayLCB(1000); blinkLED(client.begin(38400) + 1); //start the GPRS-Modem (e.g. connect to network) //one time blinking indicates all ok - more denotes an error. For details look at function definition delay(2000); @@ -83,10 +84,11 @@ void loop() { if (measurements >= SEND_COUNT & bat_voltage > MIN_VOLTAGE) { //time to send data digitalWrite(POWER_PIN, HIGH); //power up modem adjust_OSCCAL(); - blinkLED(client.begin(38400) + 1); //connect to network - uint8_t tx_res = 0; + delayLCB(1000); + uint8_t tx_res = client.begin(38400); + blinkLED(tx_res + 1); //connect to network while (! tx_res && myBuffer.available() && ! ISSET_ACTION(0)) { - tx_res = client.sendMultiFromBuffer(1000); //send 1000 bytes from flash storage + tx_res = client.sendMultiFromBuffer(3000); //send 3000 bytes from flash storage blinkLED(tx_res + 1); } if (! myBuffer.available()) measurements = 0; //all data sent from flash storage diff --git a/libraries/BayEOSBoards/examples/LowCurrentBoard/LowCurrentGPRS_SPIFlash/LowCurrentGPRS_SPIFlash.ino b/libraries/BayEOSBoards/examples/LowCurrentBoard/LowCurrentGPRS_SPIFlash/LowCurrentGPRS_SPIFlash.ino deleted file mode 100644 index a2eecee..0000000 --- a/libraries/BayEOSBoards/examples/LowCurrentBoard/LowCurrentGPRS_SPIFlash/LowCurrentGPRS_SPIFlash.ino +++ /dev/null @@ -1,221 +0,0 @@ -/**************************************************************** - - Sketch for SIM800L-Test with new SMD-Version of - BayEOS Low Power Board - - ***************************************************************/ -#define TICKS_PER_SECOND 128 -#define WITHDALLAS 0 -#define WITHWIND 1 -#define WITHRAINGAUGE 1 -#define SAMPLING_INT 30 -#define ACTION_COUNT 1 - -#include -#include -#include -#include -#include -#include -MCP342x mcp342x = MCP342x(); -const byte addr = 0; -const uint8_t mode = 0; //0 == one-shot mode - 1 == continuos mode -const uint8_t rate = 2; //0-3: 12bit ... 18bit -const uint8_t gain = 0; //max Voltage: 0,512 Volt - -#define GPRS_POWER_PIN 7 -#define BAT_MULTIPLIER 3.3*320/100/1023 -#define ADC_BATPIN A7 -// we will collect 60 measurements before we try to send -#define GPRS_SEND_COUNT 60 - -uint16_t gprs_counter = 0; -uint8_t tx_error, res, gprs_status, low_bat = 0; -float bat, tmp_float; -unsigned long last_measurement; - -SPIFlash flash(8); -BayEOSBufferSPIFlash myBuffer; -BayGPRS client(Serial); - -#include - -#if WITHRAINGAUGE -float last_rain_count; -#endif - - -void setup(void) { - initLCB(); //init time2 - pinMode(GPRS_POWER_PIN, OUTPUT); - digitalWrite(GPRS_POWER_PIN, HIGH); - delay(1000); - adjust_OSCCAL(); - //CHANGE CONFIG!! - client.readConfigFromStringPGM(PSTR("132.180.112.55|80|gateway/frame/saveFlat|import|import|GPRS-T1|pinternet.interkom.de|||5659|")); - client.changeIPR(38400); - res = client.begin(38400); - blinkLED(res + 1); - /* - 1 == OK - 2 == NO Communication - 3 == PIN failed - 4 == PIN locked - 5 == Not CREG - 6 == Not CGATT - 7 == No SIM Card - */ - delay(2000); - - res = client.sendMessage("GPRS started"); - blinkLED(res + 1); - if (! res) myRTC.adjust(client.now()); - - - /* - 1 == OK - 2 == no success - 3 == timeout - 4 == network timeout - 5 == gprs modem timeout - */ - analogReference(DEFAULT); - bat = BAT_MULTIPLIER * analogRead(ADC_BATPIN); - digitalWrite(GPRS_POWER_PIN, LOW); - - if (bat < 3.7) low_bat = 1; - else low_bat = 0; - - delay(2000); - - - myBuffer.init(flash); //This will restore old pointers - //myBuffer.reset(); - client.setBuffer(myBuffer); - myBuffer.setRTC(myRTC, 0); //Nutze RTC relativ! - if (myRTC.now().get() < 2000) myBuffer.skip(); //got no time! skip the unread frames in Buffer!! - digitalWrite(2, HIGH); //Enable Pullup on Pin 2 == INT0 - digitalWrite(3, HIGH); //Enable Pullup on Pin 3 == INT1 - startLCB(); - gprs_counter = GPRS_SEND_COUNT - 2; - last_measurement = myRTC.now().get(); -} - -void loop() -{ -#if WITHRAINGAUGE - handleRainEventLCB(); -#endif - - if (ISSET_ACTION(0)) { - UNSET_ACTION(0); - client.startDataFrame(); - client.addChannelValue(millis()); - mcp342x.setConf(addr, 1, 0, mode, rate, gain); - delayLCB(100); - client.addChannelValue(mcp342x.getData(addr) * 1000); -#if WITHWIND - noInterrupts(); - tmp_float = wind_count; - wind_count = 0; - interrupts(); - if (tmp_float) { - //Calibration equation - tmp_float = tmp_float * 60 / (float)(myRTC.now().get() - last_measurement) / 37.547 + 0.28; - } - last_measurement = myRTC.now().get(); - client.addChannelValue(tmp_float); -#endif - -#if WITHRAINGAUGE - noInterrupts(); - tmp_float = rain_count; - interrupts(); - //RG2+WS-CA: 0.2mm per count - client.addChannelValue(tmp_float * 0.2); - client.addChannelValue((tmp_float - last_rain_count) / (float)SAMPLING_INT * 60 * 0.2); - last_rain_count = tmp_float; -#endif - client.addChannelValue(bat); - //Some DEBUG values - client.addChannelValue(myBuffer.readPos()); - client.addChannelValue(myBuffer.writePos()); - client.addChannelValue(myRTC.now().get()); - client.writeToBuffer(); - gprs_counter++; - - } - - if (ISSET_ACTION(7)) { - UNSET_ACTION(7); - if (gprs_counter > GPRS_SEND_COUNT) { - switch (gprs_status) { - case 0: - digitalWrite(GPRS_POWER_PIN, HIGH); - if (low_bat) { - analogReference(DEFAULT); - bat = BAT_MULTIPLIER * analogRead(ADC_BATPIN); - if (bat > 4.0) low_bat = 0; - else { - client.startFrame(BayEOS_ErrorMessage); - client.addToPayload("Low bat"); - client.writeToBuffer(); - gprs_counter = 0; - digitalWrite(GPRS_POWER_PIN, LOW); - } - } - if(! low_bat){ - adjust_OSCCAL(); - client.begin(38400, 1); - gprs_status = 1; - tx_error = 0; - } - break; - case 1: - if (client.isRegistered()) { - gprs_status = 2; - tx_error = 0; - } else tx_error++; - break; - case 2: - if (client.isAttached()) { - gprs_status = 3; - tx_error = 0; - } else tx_error++; - case 3: - - adjust_OSCCAL(); - if (res = client.sendMultiFromBuffer(2000)) tx_error += 20; - else tx_error = 0; - blinkLED(res + 1); - - break; - } - analogReference(DEFAULT); - bat = BAT_MULTIPLIER * analogRead(ADC_BATPIN); - //We got to many errors or buffer is empty or low bat - if (tx_error > 100 || ! myBuffer.available() || bat < 3.7) { - if (tx_error) { - client.startFrame(BayEOS_ErrorMessage); - client.addToPayload("TX-Error:"); - client.addToPayload('0' + gprs_status); - client.addToPayload('/'); - client.addToPayload('0' + res); - client.writeToBuffer(); - } - gprs_counter = 0; - gprs_status = 0; - tx_error = 0; - if(bat<3.7) low_bat=1; - digitalWrite(GPRS_POWER_PIN, LOW); - Serial.end(); - pinMode(1, INPUT); - if (bat > 4.1 && tx_error) gprs_counter = GPRS_SEND_COUNT - 1; - } - } - } - - - sleepLCB(); - -} diff --git a/libraries/BayEOSBoards/examples/MCP_MplexShield/Logger/Logger.ino b/libraries/BayEOSBoards/examples/MCP_MplexShield/Logger/Logger.ino deleted file mode 100644 index 9ae1594..0000000 --- a/libraries/BayEOSBoards/examples/MCP_MplexShield/Logger/Logger.ino +++ /dev/null @@ -1,158 +0,0 @@ - -#include -#include -#include -#include -#include -#include -#include -#include - -const byte addr = 0; -const uint8_t gain = 0; //0-3: x1, x2, x4, x8 -const uint8_t rate = 2; //0-3: 12bit ... 18bit -// create an objcet of the class MCP342x -MCP342x mcp342x(addr); -//Configure your resistors on the board! -const uint16_t R[] = { 19877, 19975, 20028, 19966, - 20015, 19926, 19898, 19912 - }; -float ntc10_R2T(float r) { - float log_r = log(r); - return 440.61073 - 75.69303 * log_r + - 4.20199 * log_r * log_r - 0.09586 * log_r * log_r * log_r; -} - -#define CONNECTED_PIN 9 -#define SAMPLING_INT 30 -#define ACTION_COUNT 0 -#define TICKS_PER_SECOND 16 -uint8_t connected = 0; - -BaySerial client(Serial); -SPIFlash flash(8); //CS-Pin of SPI-Flash -BayEOSBufferSPIFlash myBuffer; -BayEOSLogger myLogger; -#include - - - -//Add your sensor measurements here! -float values[9]; -uint16_t count; -unsigned long last_measurement; - -//Add your sensor measurements here! -uint16_t current_tics, last_tics; -void measure() { - if (myLogger._logged_flag) { - myLogger._logged_flag = 0; - count = 0; - for (uint8_t i = 0; i < 9; i++) { - values[i] = 0; - } - } - - - - - - - digitalWrite(POWER_PIN, HIGH); - analogReference(INTERNAL); - if (digitalRead(CONNECTED_PIN)) - myLogger._bat = (1.1 * 320 / 100 / 1023 * analogRead(A0)) * 1000; - values[0] += ((float)myLogger._bat) / 1000; - digitalWrite(POWER_PIN, LOW); - digitalWrite(MPLEX_POWER_PIN, HIGH); - for (uint8_t ch = 0; ch < 8; ch++) { - mplex_set_channel(ch); - mcp342x.runADC(0); - delay(mcp342x.getADCTime()); - float I = mcp342x.getData() / (float) R[ch]; - - mcp342x.runADC(1); - delay(mcp342x.getADCTime()); - float R_mess = mcp342x.getData() / I; - values[ch + 1] += ntc10_R2T(R_mess); - } - digitalWrite(MPLEX_POWER_PIN, LOW); - - - count++; - - client.startDataFrame(0x41); - client.addChannelValue(millis(), 1); - for (uint8_t i = 0; i < 9; i++) { - client.addChannelValue(values[i] / count, i + 2); - } - - - -} - - - -void setup() { - pinMode(POWER_PIN, OUTPUT); - pinMode(CONNECTED_PIN, INPUT_PULLUP); - myBuffer.init(flash); - myBuffer.setRTC(myRTC); //Nutze RTC absolut! - client.setBuffer(myBuffer); - //register all in BayEOSLogger - myLogger.init(client, myBuffer, myRTC, 60, 2500); //min_sampling_int = 60 - //disable logging as RTC has to be set first!! - myLogger._logging_disabled = 1; - Wire.begin(); - mcp342x.reset(); - mcp342x.storeConf(rate, gain); - initLCB(); //init time2 -} - -void loop() { - //Enable logging if RTC give a time later than 2010-01-01 - if (ISSET_ACTION(7) || connected) { - UNSET_ACTION(7); - if (myLogger._logging_disabled && myRTC.now().get() > 315360000L) - myLogger._logging_disabled = 0; - - if (! myLogger._logging_disabled && (myLogger._mode == LOGGER_MODE_LIVE || - (myRTC._seconds - last_measurement) >= SAMPLING_INT)) { - last_measurement = myRTC._seconds; - measure(); - } - myLogger.run(); - - if (! connected && myLogger._logging_disabled) { - pinMode(LED_BUILTIN, OUTPUT); - digitalWrite(LED_BUILTIN, HIGH); - delayLCB(200); - digitalWrite(LED_BUILTIN, LOW); - delayLCB(800); - pinMode(LED_BUILTIN, INPUT); - } - //check if still connected - if (connected && digitalRead(CONNECTED_PIN)) { - connected++; - if (connected > 5) { - client.flush(); - client.end(); - connected = 0; - myLogger._mode = 0; - } - } - //Connected pin is pulled to GND - if (!connected && ! digitalRead(CONNECTED_PIN)) { - connected = 1; - adjust_OSCCAL(); - client.begin(38400); - } - } - //sleep until timer2 will wake us up... - if (! connected) { - Sleep.sleep(TIMER2_ON, SLEEP_MODE_PWR_SAVE); - } - - -} - diff --git a/libraries/BayEOSBoards/examples/MCP_MplexShield/readChannels/readChannels.ino b/libraries/BayEOSBoards/examples/MCP_MplexShield/readChannels/readChannels.ino deleted file mode 100644 index 60d0b8c..0000000 --- a/libraries/BayEOSBoards/examples/MCP_MplexShield/readChannels/readChannels.ino +++ /dev/null @@ -1,46 +0,0 @@ -#include -#include -#include - -const byte addr = 0; -const uint8_t gain = 0; //0-3: x1, x2, x4, x8 -const uint8_t rate = 2; //0-3: 12bit ... 18bit -const uint8_t mode = 0; //0 == one-shot mode - 1 == continuos mode - -MCP342x mcp342x(addr); - -//Configure your resistors on the board! -const uint16_t R[]={ 19877, 19975, 20028, 19966, - 20015, 19926, 19898, 19912 }; - -void setup() -{ - Serial.begin(9600); - Wire.begin(); - mcp342x.reset(); - mcp342x.storeConf(rate, gain); - pinMode(MPLEX_POWER_PIN,OUTPUT); - pinMode(5,OUTPUT); -} - -void loop(){ - digitalWrite(5,HIGH); - digitalWrite(MPLEX_POWER_PIN,HIGH); - for(uint8_t ch=0; ch<8;ch++){ - mplex_set_channel(ch); - mcp342x.runADC(0); - delay(mcp342x.getADCTime()); - float I = mcp342x.getData()/(float) R[ch]; - - mcp342x.runADC(1); - delay(mcp342x.getADCTime()); - float R_mess=mcp342x.getData()/I; - Serial.print(R_mess); - Serial.print("\t"); - } - Serial.println(); - digitalWrite(5,LOW); - digitalWrite(MPLEX_POWER_PIN,LOW); - delay(2000); -} - diff --git a/libraries/BayEOSBoards/examples/MCP_MplexShield/readNTC10/readNTC10.ino b/libraries/BayEOSBoards/examples/MCP_MplexShield/readNTC10/readNTC10.ino deleted file mode 100644 index 6543b95..0000000 --- a/libraries/BayEOSBoards/examples/MCP_MplexShield/readNTC10/readNTC10.ino +++ /dev/null @@ -1,53 +0,0 @@ -#include -#include -#include -#include - -const byte addr = 0; -const uint8_t gain = 0; //0-3: x1, x2, x4, x8 -const uint8_t rate = 2; //0-3: 12bit ... 18bit -// create an objcet of the class MCP342x -MCP342x mcp342x(addr); - -//Configure your resistors on the board! -const uint16_t R[]={ 19877, 19975, 20028, 19966, - 20015, 19926, 19898, 19912 }; - -float ntc10_R2T(float r){ - float log_r=log(r); - return 440.61073-75.69303*log_r+ - 4.20199*log_r*log_r-0.09586*log_r*log_r*log_r; -} - - -void setup() -{ - Serial.begin(9600); - Wire.begin(); - mcp342x.reset(); - mcp342x.storeConf(rate, gain); - pinMode(MPLEX_POWER_PIN,OUTPUT); - pinMode(5,OUTPUT); -} - -void loop(){ - digitalWrite(5,HIGH); - digitalWrite(MPLEX_POWER_PIN,HIGH); - for(uint8_t ch=0; ch<8;ch++){ - mplex_set_channel(ch); - mcp342x.runADC(0); - delay(mcp342x.getADCTime()); - float I = mcp342x.getData()/(float) R[ch]; - - mcp342x.runADC(1); - delay(mcp342x.getADCTime()); - float R_mess=mcp342x.getData()/I; - Serial.print(ntc10_R2T(R_mess)); - Serial.print("\t"); - } - Serial.println(); - digitalWrite(5,LOW); - digitalWrite(MPLEX_POWER_PIN,LOW); - delay(2000); -} - diff --git a/libraries/BayEOSBoards/examples/Max11212_dendro/GPRS/GPRS.ino b/libraries/BayEOSBoards/examples/Max11212_dendro/GPRS/GPRS.ino index ccefe6f..377b404 100644 --- a/libraries/BayEOSBoards/examples/Max11212_dendro/GPRS/GPRS.ino +++ b/libraries/BayEOSBoards/examples/Max11212_dendro/GPRS/GPRS.ino @@ -73,7 +73,8 @@ void setup() { digitalWrite(POWER_PIN, HIGH); //power up GPRS-Modem startLCB(); //some settings and blink three times client.readConfigFromStringPGM(PSTR(GPRS_CONFIG)); //read GPRS config into RAM - adjust_OSCCAL(); //tune clock of ATMega to make serial communication more stable + adjust_OSCCAL(); //tune clock of ATMega to make serial communication more stable + delayLCB(1000); blinkLED(client.begin(38400) + 1); //start the GPRS-Modem (e.g. connect to network) //one time blinking indicates all ok - more denotes an error. For details look at function definition delay(2000); @@ -125,10 +126,11 @@ void loop() { if (measurements >= SEND_COUNT & bat_voltage > MIN_VOLTAGE) { //time to send data digitalWrite(POWER_PIN, HIGH); //power up modem adjust_OSCCAL(); - blinkLED(client.begin(38400) + 1); //connect to network - uint8_t tx_res = 0; + delayLCB(1000); + uint8_t tx_res = client.begin(38400); + blinkLED(tx_res + 1); //connect to network while (!tx_res && myBuffer.available() && !ISSET_ACTION(0)) { - tx_res = client.sendMultiFromBuffer(1000); //send 1000 bytes from flash storage + tx_res = client.sendMultiFromBuffer(3000); //send 3000 bytes from flash storage blinkLED(tx_res + 1); } if (!myBuffer.available()) measurements = 0; //all data sent from flash storage diff --git a/libraries/BayEOSBoards/examples/SDI12/ClimaVue50/ClimaVue50.ino b/libraries/BayEOSBoards/examples/SDI12/ClimaVue50/ClimaVue50.ino new file mode 100644 index 0000000..d2e2b0b --- /dev/null +++ b/libraries/BayEOSBoards/examples/SDI12/ClimaVue50/ClimaVue50.ino @@ -0,0 +1,130 @@ +/******************************************************* + Example Sketch for BayEOS-SDI12-Low-Power-Board. + + The sketch performes a measurement at a frequency of SAMPLING_INT + It stores data an flash and tries to send the data, after collecting + min. SEND_COUNT samples. + When battery voltages is to low (below MIN_VOLTAGE), no data is send. + + +*******************************************************/ + + + +// Divider resistors for battery voltage +#define BAT_DIVIDER (100.0 + 100.0) / 100.0 +#define SAMPLING_INT 60 +#define SEND_COUNT 60 /*collect 60 measurements before send... */ +#define MIN_VOLTAGE 3.8 /*minimum voltage for send operation */ +// GPRS-Config string. +// Gateway-IP|PORT|path on server|login|password|Origin (== Board unique identifier)|apn of sim-card|apn-user|apn-pw|PIN +#define GPRS_CONFIG "132.180.112.128|80|gateway/frame/saveFlat|import@IT|import|ClimaVue01XX|iot.1nce.net||||" +#define DATA_PIN A5 /*!< The pin of the SDI-12 data bus */ +//#define DATA_PIN 3 /*!< The pin of the SDI-12 data bus */ +//END user configruation +//********************************************** + + +#include +unsigned long last_sent; + +#include +BayGPRS client = BayGPRS(Serial, 0); + + +SPIFlash flash(8); //Standard SPIFlash Instanz +BayEOSBufferSPIFlash myBuffer; //BayEOS Buffer + +// Some settings and functions for LowCurrentBoard +#include + + +#include ^ +SDI12 mySDI12(DATA_PIN); + +uint16_t measurements = SEND_COUNT; + +void setup() { + initLCB(); + mySDI12.begin(); + pinMode(POWER_PIN, OUTPUT); + myBuffer.init(flash); //This will restore old pointers + myBuffer.skip(); //This will skip unsent frames + myBuffer.setRTC(myRTC, RTC_RELATIVE_SECONDS); //use the rtc clock but relative + client.setBuffer(myBuffer); //connect the buffer to the transport client + digitalWrite(POWER_PIN, HIGH); //power up GPRS-Modem + startLCB(); //some settings and blink three times + delayLCB(1000); + client.readConfigFromStringPGM(PSTR(GPRS_CONFIG)); //read GPRS config into RAM + adjust_OSCCAL(); //tune clock of ATMega to make serial communication more stable + delayLCB(1000); + blinkLED(client.begin(38400) + 1); //start the GPRS-Modem (e.g. connect to network) + //one time blinking indicates all ok - more denotes an error. For details look at function definition + delay(2000); + blinkLED(client.sendMessage("Board started") + 1); //send a message to the gateway. + //one time blinking indicates success - more denotes an error. For details look at the function definition + Serial.end(); //Stop Serial (avoids power leakage via TX Pin) + digitalWrite(POWER_PIN, LOW); //power down GPRS-Modem + delay(2000); +} + + + +void loop() { + if (ISSET_ACTION(0)) { //will be set by timer2 interrupt each SAMPING_INT seconds + UNSET_ACTION(0); //clear the flag + digitalWrite(POWER_PIN, HIGH); //power up modem AND power divider (for battery voltage read) + analogReference(DEFAULT); + delayLCB(100); + float bat_voltage = 3.3 * BAT_DIVIDER / 1023 * analogRead(A7); //Read battery voltage + digitalWrite(POWER_PIN, LOW); //power down modem AND power divider + client.startDataFrame(); //Start the data frame with float values + client.addChannelValue(millis()); //add uptime (ms) als 4 byte float + client.addChannelValue(bat_voltage); //add battery voltage + + // Read sensor values + mySDI12.sendCommand("?R7!"); //Measure + delay(500); + + char buffer[100]; + uint8_t i = 0; + while (mySDI12.available()) { + buffer[i] = mySDI12.read(); + i++; + if (!mySDI12.available()) delay(10); + } + buffer[i] = 0; + client.addChannelValue(i); + // Parse return value and save all channel values in the data frame + char* p; + p = buffer + 1; + i = 0; + float f; + while (*p && i < 14) { + f = strtod(p, &p); + i++; + if (f == -9999 || f == 9990) f = NAN; + client.addChannelValue(f); + } + + client.writeToBuffer(); //Save data to flash + measurements++; //increase measurement count + if (measurements >= SEND_COUNT & bat_voltage > MIN_VOLTAGE) { //time to send data + digitalWrite(POWER_PIN, HIGH); //power up modem + adjust_OSCCAL(); + delayLCB(1000); + uint8_t tx_res = client.begin(38400); + blinkLED(tx_res + 1); //connect to network + while (!tx_res && myBuffer.available() && !ISSET_ACTION(0)) { + tx_res = client.sendMultiFromBuffer(3000); //send 3000 bytes from flash storage + blinkLED(tx_res + 1); + } + if (!myBuffer.available()) measurements = 0; //all data sent from flash storage + Serial.end(); + digitalWrite(POWER_PIN, LOW); //power down modem + } + } + sleepLCB(); //board stops execution here until timer2 wakes up the board again (typ. 16 per second) + //Most time the boards just wakes up, runs the timer2-ISR and as there is nothing to do just + //runs directly into sleepLCB() again. +} diff --git a/libraries/BayEOSBoards/examples/SapFlowBoard/DendroGPRS/DendroGPRS.ino b/libraries/BayEOSBoards/examples/SapFlowBoard/DendroGPRS/DendroGPRS.ino index 292e71d..3b13af0 100644 --- a/libraries/BayEOSBoards/examples/SapFlowBoard/DendroGPRS/DendroGPRS.ino +++ b/libraries/BayEOSBoards/examples/SapFlowBoard/DendroGPRS/DendroGPRS.ino @@ -72,7 +72,7 @@ void setup() startLCB(); digitalWrite(POWER_PIN, HIGH); client.readConfigFromStringPGM(PSTR(GPRS_CONFIG)); - + delayLCB(1000); blinkLED(client.begin(38400) + 1); delay(2000); blinkLED(client.sendMessage("Board started") + 1); @@ -125,11 +125,11 @@ void loop() { client.writeToBuffer(); measurements++; if (measurements >= SEND_COUNT & bat_voltage > MIN_VOLTAGE) { - blinkLED(client.begin(38400) + 1); - uint8_t tx_res = client.sendMultiFromBuffer(1000); - blinkLED(tx_res + 1); + delayLCB(1000); + uint8_t tx_res = client.begin(38400); + blinkLED(tx_res + 1); //connect to network while (! tx_res && myBuffer.available() && ! ISSET_ACTION(0)) { - tx_res = client.sendMultiFromBuffer(1000); + tx_res = client.sendMultiFromBuffer(3000); blinkLED(tx_res + 1); } if (! myBuffer.available()) measurements = 0; diff --git a/libraries/BayEOSBoards/examples/Soilwatch10Shield/RF24/RF24.ino b/libraries/BayEOSBoards/examples/Soilwatch10Shield/RF24/RF24.ino deleted file mode 100644 index b8d662d..0000000 --- a/libraries/BayEOSBoards/examples/Soilwatch10Shield/RF24/RF24.ino +++ /dev/null @@ -1,66 +0,0 @@ -#define SAMPLING_INT 64 - -#define RF24CHANNEL 0x4c -#define RF24ADDRESS 0x172af39a12LL - -//Do not use long names!! RF24 is limited to 32 byte!!! -//e.g: [DF][long][CF][RO][l][NAME][DF][T][cpu][bat][a0][a1][a2][a3][a4][cs] -// 1 4 1 1 1 3 1 1 2 2 2 2 2 2 2 2 = 29 -#define BOXNAME "P11" -#define SENSORANZAHL 4 - -#include - -SPIFlash flash(8); -BayEOSBufferSPIFlash myBuffer; - -#include -BayRF24 client = BayRF24(9, 10); - -#include - -void setup() -{ - client.init(RF24ADDRESS, RF24CHANNEL); - myBuffer.init(flash); //This will restore old pointers - //myBuffer.reset(); //This will set all pointers to zero - myBuffer.skip(); //This will move read pointer to write pointer - myBuffer.setRTC(myRTC, 0); //Nutze RTC relativ! - client.setBuffer(myBuffer); //use skip! - initLCB(); //init time2 - pinMode(POWER_PIN,OUTPUT); - startLCB(); - -} - -float bat=4.0; - -void loop() { - if (ISSET_ACTION(0)) { - UNSET_ACTION(0); - //eg measurement - client.startDataFrameWithOrigin(BayEOS_Int16le,BOXNAME,1,1); - client.addChannelValue(millis()); - client.addChannelValue(1000 * bat); - digitalWrite(POWER_PIN,HIGH); - delay(15); - for(uint8_t i=0;i uint8_t dout[] = { A2, A1, A0 }; @@ -53,18 +53,17 @@ void readBat() { analogReference(DEFAULT); pinMode(POWER_PIN, OUTPUT); digitalWrite(POWER_PIN, HIGH); + delayLCB(50); batLCB = 3.3 * 200 / 100 / 1023 * analogRead(A7); digitalWrite(POWER_PIN, LOW); - pinMode(POWER_PIN, INPUT); } uint16_t measurements = SEND_COUNT; -void setup() -{ +void setup() { initLCB(); - scale.begin(dout, 3, sck); //start HX711Array with 3 ADCs + scale.begin(dout, 3, sck); //start HX711Array with 3 ADCs scale.set_gain(128); readBat(); scale.power_down(); @@ -73,21 +72,25 @@ void setup() pinMode(SW10_PW, OUTPUT); pinMode(POWER_PIN, OUTPUT); - myBuffer.init(flash); //This will restore old pointers - myBuffer.skip(); //This will skip unsent frames - myBuffer.setRTC(myRTC, RTC_RELATIVE_SECONDS); //use the rtc clock but relative - client.setBuffer(myBuffer); //connect the buffer to the transport client - digitalWrite(POWER_PIN, HIGH); //power up GPRS-Modem - startLCB(); //some settings and blink three times - client.readConfigFromStringPGM(PSTR(GPRS_CONFIG)); //read GPRS config into RAM - adjust_OSCCAL(); //tune clock of ATMega to make serial communication more stable - blinkLED(client.begin(38400) + 1); //start the GPRS-Modem (e.g. connect to network) + myBuffer.init(flash); //This will restore old pointers + myBuffer.skip(); //This will skip unsent frames + myBuffer.setRTC(myRTC, RTC_RELATIVE_SECONDS); //use the rtc clock but relative + client.setBuffer(myBuffer); //connect the buffer to the transport client + digitalWrite(POWER_PIN, HIGH); //power up GPRS-Modem + startLCB(); //some settings and blink three times + client.readConfigFromStringPGM(PSTR(GPRS_CONFIG)); //read GPRS config into RAM + adjust_OSCCAL(); //tune clock of ATMega to make serial communication more stable + delayLCB(1000); + blinkLED(client.begin(38400) + 1); //start the GPRS-Modem (e.g. connect to network) //one time blinking indicates all ok - more denotes an error. For details look at function definition delay(2000); - blinkLED(client.sendMessage("Board started") + 1); //send a message to the gateway. + client.startFrame(BayEOS_Message); + client.addToPayload("Board started"); + client.writeToBuffer(); + blinkLED(client.sendMultiFromBuffer(3000) + 1); //send a message to the gateway. //one time blinking indicates success - more denotes an error. For details look at the function definition - Serial.end(); //Stop Serial (avoids power leakage via TX Pin) - digitalWrite(POWER_PIN, LOW); //power down GPRS-Modem + Serial.end(); //Stop Serial (avoids power leakage via TX Pin) + digitalWrite(POWER_PIN, LOW); //power down GPRS-Modem @@ -97,47 +100,47 @@ void setup() void loop() { - if (ISSET_ACTION(0)) { //will be set by timer2 interrupt each SAMPING_INT seconds - UNSET_ACTION(0); //clear the flag - ds.t_conversion(); //Start T-conversion + if (ISSET_ACTION(0)) { //will be set by timer2 interrupt each SAMPING_INT seconds + UNSET_ACTION(0); //clear the flag + ds.t_conversion(); //Start T-conversion delayLCB(700); scale.power_up(); scale.read_average(adc); readBat(); scale.power_down(); - client.startDataFrame(); //Start the data frame with float values - client.addChannelValue(millis()); //add uptime (ms) als 4 byte float - client.addChannelValue(batLCB); //add battery voltage + client.startDataFrame(); //Start the data frame with float values + client.addChannelValue(millis()); //add uptime (ms) als 4 byte float + client.addChannelValue(batLCB); //add battery voltage float temp; ds.readChannel(1, &temp); client.addChannelValue(temp); -//Themospannung: 4,1mV/100°C - client.addChannelValue(temp+3.3 / 128 / 256 / 256 / 256 / 4.1 *100 *100 * adc[0]); - client.addChannelValue(temp+3.3 / 128 / 256 / 256 / 256 / 4.1 *100 *100 * adc[1]); - client.addChannelValue(temp+3.3 / 128 / 256 / 256 / 256 / 4.1 *100 *100 * adc[2]); - digitalWrite(SW10_PW,HIGH); + //Themospannung: 4,1mV/100°C + client.addChannelValue(temp + 3.3 / 128 / 256 / 256 / 256 / 4.1 * 100 * 100 * adc[0]); + client.addChannelValue(temp + 3.3 / 128 / 256 / 256 / 256 / 4.1 * 100 * 100 * adc[1]); + client.addChannelValue(temp + 3.3 / 128 / 256 / 256 / 256 / 4.1 * 100 * 100 * adc[2]); + digitalWrite(SW10_PW, HIGH); delayLCB(15); client.addChannelValue(analogRead(SW10_AD)); - digitalWrite(SW10_PW,LOW); - - client.writeToBuffer(); //Save data to flash - measurements++; //increase measurement count - if (measurements >= SEND_COUNT & batLCB > MIN_VOLTAGE) { //time to send data - digitalWrite(POWER_PIN, HIGH); //power up modem + digitalWrite(SW10_PW, LOW); + + client.writeToBuffer(); //Save data to flash + measurements++; //increase measurement count + if (measurements >= SEND_COUNT & batLCB > MIN_VOLTAGE) { //time to send data + digitalWrite(POWER_PIN, HIGH); //power up modem adjust_OSCCAL(); - blinkLED(client.begin(38400) + 1); //connect to network - uint8_t tx_res = 0; - while (! tx_res && myBuffer.available() && ! ISSET_ACTION(0)) { - tx_res = client.sendMultiFromBuffer(1000); //send 1000 bytes from flash storage + delayLCB(1000); + uint8_t tx_res = client.begin(38400); + blinkLED(tx_res + 1); //connect to network + while (!tx_res && myBuffer.available() && !ISSET_ACTION(0)) { + tx_res = client.sendMultiFromBuffer(3000); //send 1000 bytes from flash storage blinkLED(tx_res + 1); } - if (! myBuffer.available()) measurements = 0; //all data sent from flash storage + if (!myBuffer.available()) measurements = 0; //all data sent from flash storage Serial.end(); - digitalWrite(POWER_PIN, LOW); //power down modem - + digitalWrite(POWER_PIN, LOW); //power down modem } } - sleepLCB(); //board stops execution here until timer2 wakes up the board again (typ. 16 per second) - //Most time the boards just wakes up, runs the timer2-ISR and as there is nothing to do just + sleepLCB(); //board stops execution here until timer2 wakes up the board again (typ. 16 per second) + //Most time the boards just wakes up, runs the timer2-ISR and as there is nothing to do just //runs directly into sleepLCB() again. } diff --git a/libraries/HX711Array/examples/calibration/calibration.ino b/libraries/HX711Array/examples/calibration/calibration.ino new file mode 100644 index 0000000..0c690a1 --- /dev/null +++ b/libraries/HX711Array/examples/calibration/calibration.ino @@ -0,0 +1,132 @@ +/* + * Calibration Sketch + * + */ + +#include +#include + +//Make sure, that you have choosen the right board! +#define HX711_DOUT 6 +#define HX711_SCK 3 +uint8_t dout[] = { HX711_DOUT }; +uint8_t sck = HX711_SCK; + +HX711_4PointCal scale; + +float sw = 3.00; +float t[] = { 10.0, 20.0 }; +long cal_adc[] = { -68137L, -73803, -378845L, -384611L }; + + +volatile uint8_t tics; +ISR(TIMER2_OVF_vect) { + tics++; +} + + +void setup() { + Serial.begin(9600); + // put your setup code here, to run once: + printHelp(); + Serial.flush(); + Sleep.setupTimer2(2); //init timer2 to 1/16 sec + scale.set_no_sleep(1); + scale.begin(dout, 1, sck); //start HX711Array with one ADCs + scale.power_up(); + +} + +long adc; +char c=0; +void loop() { + Serial.flush(); + char cc=0; + if (Serial.available()){ + cc = Serial.read(); + if ((cc >= 'a' && cc <= 'z') || (cc >= '0' && cc <= '1')) c = cc; + } + + switch (c) { + case 'h': + printHelp(); + c = '0'; + break; + case '1': + case 't': + adc = scale.read_average(10); + if (c == 't') { + scale.setTare(adc, 20); + c = '1'; + } + Serial.print("ADC: "); + Serial.print(adc); + Serial.print(" -- Weight: "); + Serial.println(scale.getWeight(adc, 20)); + break; + case 'z': + Serial.print("Reading Zero ADC..."); + Serial.flush(); + adc = scale.read_average(50); + Serial.println(adc); + cal_adc[0] = adc; + cal_adc[1] = adc; + c = '0'; + break; + case 'w': + Serial.print("Reading Weight ADC..."); + Serial.flush(); + adc = scale.read_average(50); + Serial.println(adc); + cal_adc[2] = adc; + cal_adc[3] = adc; + c = '0'; + break; + case 'r': + Serial.println("Reading Conf..."); + scale.readConf(); + c = '0'; + break; + case 's': + Serial.println("Saving Conf..."); + scale.setConf(sw, t, cal_adc); + scale.saveConf(); + c = '0'; + break; + case 'p': + scale.printConf(); + c = '0'; + break; + case 'c': + while (Serial.available()) { + delay(1); + Serial.read(); + } + Serial.println("Please enter calibration weight"); + while (Serial.available() < 3) {} + String s = Serial.readString(); + s.trim(); + sw = s.toFloat(); + Serial.print("Calibration weight: "); + Serial.println(sw); + c = '0'; + break; + case '0': + break; + } +} + + +void printHelp(void) { + Serial.println("Commands:"); + Serial.println("z: Zero calibration"); + Serial.println("w: Weight calibration"); + Serial.println("c: Set calibration weight"); + Serial.println("p: Print calibration"); + Serial.println("r: Read calibration from EEPROM"); + Serial.println("s: Save calibration to EEPROM"); + Serial.println("t: Tare"); + Serial.println("1: Continuous readings"); + Serial.println("0: Stop readings"); + Serial.println("h: Print help"); +} \ No newline at end of file