💬 Temperature Sensor
-
i dont know how but i got it now running perfect, and cleaned up a bid.
for if anyone could use ....// Enable debug prints to serial monitor #define MY_DEBUG // Enable and select radio type attached #define MY_RADIO_NRF24 //#define MY_RADIO_RFM69 #include <SPI.h> #include <MySensors.h> #include <BH1750.h> #include <Wire.h> #include <OneWire.h> #include <DallasTemperature.h> // Data wire is plugged into port 3 on the Arduino #define ONE_WIRE_BUS 3 // Setup a oneWire instance to communicate with any OneWire devices (not just Maxim/Dallas temperature ICs) OneWire oneWire(ONE_WIRE_BUS); // Pass our oneWire reference to Dallas Temperature. DallasTemperature sensors(&oneWire); // arrays to hold device address DeviceAddress insideThermometer; unsigned long SLEEP_TIME = 30000; // Sleep time between reads (in milliseconds) int BATTERY_SENSE_PIN = A0; // select the input pin for the battery sense point int SOLAR_SENSE_PIN = A1; // select the input pin for the solar sense point #define CHILD_ID_BATTERY 4 #define CHILD_ID_SOLAR 6 #define CHILD_ID_LIGHT 1 #define CHILD_ID_TEMP1 2 BH1750 lightSensor; float TempC = 50.5; int oldBatteryPcnt = 0; MyMessage msgTempC(CHILD_ID_TEMP1,V_TEMP); MyMessage msgbatt(CHILD_ID_BATTERY, V_VOLTAGE); MyMessage msgsolar(CHILD_ID_SOLAR, V_VOLTAGE); MyMessage msg(CHILD_ID_LIGHT, V_LIGHT_LEVEL); uint16_t lastlux; //lux void setup(void) { // use the 1.1 V internal reference #if defined(__AVR_ATmega2560__) analogReference(INTERNAL1V1); #else analogReference(INTERNAL); #endif // Send the sketch version information to the gateway and Controller sendSketchInfo("Battery Meter", "2.0"); present(CHILD_ID_LIGHT, S_LIGHT_LEVEL); sensors.begin(); // start reading sensor // search for devices on the bus and assign based on an index. ideally, if (!sensors.getAddress(insideThermometer, 0)) Serial.println("Unable to find address for Device 0"); // set the resolution to 9 bit (Each Dallas/Maxim device is capable of several different resolutions) //sensors.setResolution(insideThermometer, 9); } void loop(void) { // get the battery Voltage int sensorValue2 = analogRead(BATTERY_SENSE_PIN); delay(1000); int sensorValue1 = analogRead(BATTERY_SENSE_PIN); delay(100); int sensorValue = analogRead(BATTERY_SENSE_PIN); delay(1000); int sensorValueS = analogRead(SOLAR_SENSE_PIN); delay(1000); #ifdef MY_DEBUG Serial.print("Battery Voltage2: "); Serial.println(sensorValue2); Serial.print("Battery Voltage1: "); Serial.println(sensorValue1); Serial.print("Battery Voltage: "); Serial.println(sensorValue); Serial.print("Solar Voltage: "); Serial.println(sensorValueS); #endif // 1M, 470K divider across battery and using internal ADC ref of 1.1V // Sense point is bypassed with 0.1 uF cap to reduce noise at that point // ((1e6+470e3)/470e3)*1.1 = Vmax = 3.44 Volts // 3.44/1023 = Volts per bit = 0.003363075 const float vRef = 4.200/ 1.05/ 1023 ; int batteryPcnt = sensorValue / 10; float batteryV = sensorValue * 0.0042598 ; // 0.0038952294568380753114792412093 max 4,2 volt float batteryS = sensorValueS * 0.0102459 ; // 0.0038952294568380753114792412093 max 10 volt float TempC = sensors.getTempC(insideThermometer); #ifdef MY_DEBUG Serial.print("DS1820 Temperature: "); Serial.print(TempC); Serial.println(" C"); send(msgTempC.set(TempC ,2)); Serial.print("Battery Voltage: "); Serial.print(batteryV); Serial.println(" V"); send(msgbatt.set(batteryV ,2)); Serial.print("Solar Voltage: "); Serial.print(batteryS); Serial.println(" V"); send(msgsolar.set(batteryS ,2)); Serial.print("Battery percent: "); Serial.print(batteryPcnt); Serial.println(" %"); #endif if (oldBatteryPcnt != batteryPcnt) { // Power up radio after sleep sendBatteryLevel(batteryPcnt); oldBatteryPcnt = batteryPcnt; } uint16_t lux = lightSensor.readLightLevel();// Get Lux value Serial.println(lux); if (lux != lastlux) { send(msg.set(lux)); lastlux = lux; } sleep(SLEEP_TIME); } -
Hi,
Can someone push me into the right direction.
I followed the "tutorial" and setup a Serial Gateway. This seems to be running just fine.Now i want to add a node with a temperature sensor.
Both are using the NRF24L radio.
On my node i get an errors in the serial monitor.
What did i do wrong?0 MCO:BGN:INIT NODE,CP=RNNNA--,VER=2.1.1 3 MCO:BGN:BFR 63 TSM:INIT 64 TSF:WUR:MS=0 71 !TSM:INIT:TSP FAIL 72 TSM:FAIL:CNT=1 74 TSM:FAIL:PDT 10077 TSM:FAIL:RE-INIT 10079 TSM:INIT 10085 !TSM:INIT:TSP FAIL 10088 TSM:FAIL:CNT=2 10089 TSM:FAIL:PDT -
I just tried this today but get an error. Here's the output.....
Arduino: 1.8.3 (Windows 10), Board: "Arduino Pro or Pro Mini, ATmega328 (3.3V, 8 MHz)"
In file included from C:\Users\captain\Documents\Arduino\MYS-HW-CH\MYS-HW-CH.ino:37:0:
C:\Users\captain\Documents\Arduino\libraries\DallasTemperature/DallasTemperature.h: In function 'void loop()':
C:\Users\captain\Documents\Arduino\libraries\DallasTemperature/DallasTemperature.h:252:13: error: 'int16_t DallasTemperature::millisToWaitForConversion(uint8_t)' is private
int16_t millisToWaitForConversion(uint8_t); ^MYS-HW-CH:85: error: within this context
int16_t conversionTime = sensors.millisToWaitForConversion(sensors.getResolution());
^exit status 1
within this contextThis report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.THis is MYS 2.1.1 installed so a bit baffled as to what is causing the problem, it should just work, right?
Anyone with any insight please let me know! :)
-
I just tried this today but get an error. Here's the output.....
Arduino: 1.8.3 (Windows 10), Board: "Arduino Pro or Pro Mini, ATmega328 (3.3V, 8 MHz)"
In file included from C:\Users\captain\Documents\Arduino\MYS-HW-CH\MYS-HW-CH.ino:37:0:
C:\Users\captain\Documents\Arduino\libraries\DallasTemperature/DallasTemperature.h: In function 'void loop()':
C:\Users\captain\Documents\Arduino\libraries\DallasTemperature/DallasTemperature.h:252:13: error: 'int16_t DallasTemperature::millisToWaitForConversion(uint8_t)' is private
int16_t millisToWaitForConversion(uint8_t); ^MYS-HW-CH:85: error: within this context
int16_t conversionTime = sensors.millisToWaitForConversion(sensors.getResolution());
^exit status 1
within this contextThis report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.THis is MYS 2.1.1 installed so a bit baffled as to what is causing the problem, it should just work, right?
Anyone with any insight please let me know! :)
@skywatch just follow the instructions on the build page:
This example uses a modified version of the external DTH library, which is included in the MySensors external examples. Please install it and restart the Arduino IDE before trying to compile.
-
-
Hi,
I have only one sensor on the mini pro and I have this in the logs:
2017-07-30 14:41:28.492 (Mysensor) Temp (Congélateur)
2017-07-30 14:41:28.497 (Mysensor) Temp (Congélateur)
2017-07-30 14:41:28.501 (Mysensor) Temp (Congélateur)
2017-07-30 14:41:28.506 (Mysensor) Temp (Congélateur)
2017-07-30 14:41:28.510 (Mysensor) Temp (Congélateur)
2017-07-30 14:41:28.515 (Mysensor) Temp (Congélateur)
2017-07-30 14:41:28.521 (Mysensor) Temp (Congélateur)
2017-07-30 14:41:28.526 (Mysensor) Temp (Congélateur)Sleep time is set to 60000ms, why the time between 2 messages is around 5ms???
-
Hi,
I have only one sensor on the mini pro and I have this in the logs:
2017-07-30 14:41:28.492 (Mysensor) Temp (Congélateur)
2017-07-30 14:41:28.497 (Mysensor) Temp (Congélateur)
2017-07-30 14:41:28.501 (Mysensor) Temp (Congélateur)
2017-07-30 14:41:28.506 (Mysensor) Temp (Congélateur)
2017-07-30 14:41:28.510 (Mysensor) Temp (Congélateur)
2017-07-30 14:41:28.515 (Mysensor) Temp (Congélateur)
2017-07-30 14:41:28.521 (Mysensor) Temp (Congélateur)
2017-07-30 14:41:28.526 (Mysensor) Temp (Congélateur)Sleep time is set to 60000ms, why the time between 2 messages is around 5ms???
@Digdogger it can depend on a lot of things. The best way to know is to look at the debug logs from the node and the gateway from the time when it happened. There could be a problem with the communication, with the radios, with the power supply, with the sketch, etc.
It could also be that you're using a microcontroller that doesn't support MySensors sleep, such as the esp8266. But it is just a guess. The information that's usually needed to troubleshoot is listed in https://forum.mysensors.org/topic/666/debug-faq-and-how-ask-for-help/
-
Slightly off-topic here... but related to this particular sketch
If you look close enough (and copy-paste the sketch into your IDE) you'll witness that one curly-bracket is technically missing at the end of loop()...
But as I added it to the sketch I got error
Sketch compiles fine "with" the missing curly-bracket... ???
Any comment to that (in my sense) funny behavior ?
-
Slightly off-topic here... but related to this particular sketch
If you look close enough (and copy-paste the sketch into your IDE) you'll witness that one curly-bracket is technically missing at the end of loop()...
But as I added it to the sketch I got error
Sketch compiles fine "with" the missing curly-bracket... ???
Any comment to that (in my sense) funny behavior ?
-
I must have gone mad then :ghost:
Check the loop()
The last closing curly--bracket is forfor (int i=0; i<numSensors && i<MAX_ATTACHED_DS18B20; i++) {So which one closes
void loop() {If i add one more to "make it right" then hell brakes loose...
sketch_jul31a:110: error: expected declaration before '}' token } ^ exit status 1 expected declaration before '}' token1-That's the only sketch behaving this way
2-Even the "IDE-automatic-opening-bracket-finder" (shows which bracket is open when placing cursor on closing bracket) can NOT find the right bracket for loop()...:scream:
-
Interesting observation @ben999
This is caused by the preprocessing directives.
#if COMPARE_TEMP == 1 if (lastTemperature[i] != temperature && temperature != -127.00 && temperature != 85.00) { #else if (temperature != -127.00 && temperature != 85.00) { #endifOnly one of these if statements will be active. The Arduino IDE probably doesn't evaluate preprocessing directives, so it sees two if statements and therefore thinks it should see two end braces. A way to "fix" this could be to move the starting curly brace to after the preprocessing directives:
#if COMPARE_TEMP == 1 if (lastTemperature[i] != temperature && temperature != -127.00 && temperature != 85.00) #else if (temperature != -127.00 && temperature != 85.00) #endif {This allows the Arduino IDE to parse the code correctly, and correctly match the braces.