Slim Node Si7021 sensor example
-
@ar91 Please find the code I used in 3 different nodes. The good thing with the playground lib is that there is error message if dialog with DHT22 failed.
/** * The MySensors Arduino library handles the wireless radio link and protocol * between your home built sensors/actuators and HA controller of choice. * The sensors forms a self healing radio network with optional repeaters. Each * repeater and gateway builds a routing tables in EEPROM which keeps track of the * network topology allowing messages to be routed to nodes. * * Created by Henrik Ekblad <henrik.ekblad@mysensors.org> * Copyright (C) 2013-2015 Sensnology AB * Full contributor list: https://github.com/mysensors/Arduino/graphs/contributors * * Documentation: http://www.mysensors.org * Support Forum: http://forum.mysensors.org * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * version 2 as published by the Free Software Foundation. * */ /**************************************************************************************/ /* Temperature, humidity and luminosity measurements. */ /* */ /* Version : 1.1.6 */ /* Date : 10/01/2016 */ /* Modified by : David Carlier */ /**************************************************************************************/ /* --------------- */ /* RST | | A5 */ /* RX | | A4 */ /* TX | ARDUINO | A3 */ /* RFM69 (DIO0) --------- D2 | UNO | A2 */ /* DHT22 --------- D3 | | A1 */ /* Power --------- D4 | ATMEGA 328p | A0 --------- Light dep. resistor */ /* +3v --------- VCC | | GND --------- GND */ /* GND --------- GND | 8MHz int. | REF */ /* OSC | | VCC --------- +3v */ /* OSC | | D13 --------- RFM69 (SCK) */ /* D5 | | D12 --------- RFM69 (MISO) */ /* D6 | | D11 --------- RFM69 (MOSI) */ /* D7 | | D10 --------- RFM69 (NSS) */ /* D8 | | D9 */ /* --------------- */ /* */ /* Power = Vcc for LDR. */ /* +3v = 2*AA */ /* */ /**************************************************************************************/ #include <SPI.h> #include <MySensor.h> #include <dht.h> #include <MyTransportRFM69.h> #include <MySigningAtsha204Soft.h> #define CHILD_ID_HUM 0 #define CHILD_ID_TEMP 1 #define CHILD_ID_LIGHT 2 #define CHILD_ID_VOLTAGE 3 #define LIGHT_SENSOR_ANALOG_PIN 0 #define HUMIDITY_SENSOR_DIGITAL_PIN 3 #define POWER_PIN 4 //unsigned long SLEEP_TIME = 850000; // Sleep time between reads (in milliseconds) (close to 15') unsigned long SLEEP_TIME = 275000; // Sleep time between reads (in milliseconds) (close to 5') //Construct MySensors library MySigningAtsha204Soft signer; MyHwATMega328 hw; MyTransportRFM69 transport; MySensor gw(transport, hw, signer); dht DHT; MyMessage msgHum(CHILD_ID_HUM, V_HUM); MyMessage msgTemp(CHILD_ID_TEMP, V_TEMP); MyMessage msgLum(CHILD_ID_LIGHT, V_LEVEL); MyMessage msgVolt(CHILD_ID_VOLTAGE, V_VOLTAGE); /**************************************************************************************/ /* Initialization */ /**************************************************************************************/ void setup() { //Get time (for setup duration) #ifdef DEBUG unsigned long startTime = millis(); #endif //Start MySensors gw.begin(); //Send the Sketch Version Information to the Gateway gw.sendSketchInfo("GHAS sensor", "1.1.5"); //Register all sensors to gw (they will be created as child devices) gw.present(CHILD_ID_HUM, S_HUM); gw.present(CHILD_ID_TEMP, S_TEMP); gw.present(CHILD_ID_LIGHT, S_LIGHT_LEVEL); gw.present(CHILD_ID_VOLTAGE, S_MULTIMETER); //Delay for DHT22 delay(1500); //Print setup debug #ifdef DEBUG int duration = millis() - startTime; Serial.print("[Setup duration: "); Serial.print(duration, DEC); Serial.println(" ms]"); #endif } /**************************************************************************************/ /* Main loop */ /**************************************************************************************/ void loop() { //Get time (for a complete loop) #ifdef DEBUG unsigned long startTime = millis(); #endif //Power on powerOnPeripherals(); //Get DHT22 data int dht22Result = DHT.read22(HUMIDITY_SENSOR_DIGITAL_PIN); switch (dht22Result) { case DHTLIB_OK: //Serial.println("OK,\t"); break; case DHTLIB_ERROR_CHECKSUM: #ifdef DEBUG Serial.println("Checksum error,\t"); #endif break; case DHTLIB_ERROR_TIMEOUT: #ifdef DEBUG Serial.println("Time out error,\t"); #endif break; case DHTLIB_ERROR_CONNECT: #ifdef DEBUG Serial.println("Connect error,\t"); #endif break; case DHTLIB_ERROR_ACK_L: #ifdef DEBUG Serial.println("Ack Low error,\t"); #endif break; case DHTLIB_ERROR_ACK_H: #ifdef DEBUG Serial.println("Ack High error,\t"); #endif break; default: #ifdef DEBUG Serial.println("Unknown error,\t"); #endif break; } //Get temperature and humidity float temperature = 0; float humidity = 0; if (dht22Result == DHTLIB_OK) { temperature = DHT.temperature; humidity = DHT.humidity; } //Get power before luminosity to use real voltage float realVoltage = getVoltage() / 100.0; int batteryPcnt = realVoltage * 100 / 3.0; if (batteryPcnt > 100) {batteryPcnt = 100;} int lux = computeIlluminance(realVoltage); //Power off powerOffPeripherals(); //Send data to gateway gw.send(msgHum.set(humidity, 1)); gw.send(msgTemp.set(temperature, 1)); gw.send(msgLum.set(lux)); gw.send(msgVolt.set(realVoltage, 2)); gw.sendBatteryLevel(batteryPcnt); //Print debug #ifdef DEBUG Serial.print(temperature, 1); Serial.print(" degC"); Serial.print(" "); Serial.print(humidity, 1); Serial.print(" %"); Serial.print(" "); Serial.print(lux); Serial.print(" lx"); Serial.print(" "); Serial.print(realVoltage); Serial.print(" v"); int duration = millis() - startTime; Serial.print(" "); Serial.print("["); Serial.print(duration, DEC); Serial.println(" ms]"); Serial.flush(); #endif //Sleep gw.sleep(SLEEP_TIME); } /**************************************************************************************/ /* Allows to compute illuminance (in LUX) from LIGHT_SENSOR_ANALOG_PIN. */ /**************************************************************************************/ int computeIlluminance(float realVoltage) { //Get luminosity int luminosity = analogRead(LIGHT_SENSOR_ANALOG_PIN); //Calculating the voltage in the input of the ADC double voltage = realVoltage * ((double)luminosity / 1024.0); //Calculating the resistance of the photoresistor in the voltage divider double resistance = (10.0 * realVoltage) / voltage - 10.0; //Calculating the intensity of light in lux and return it int illuminance = 255.84 * pow(resistance, -10/9); return illuminance; } /**************************************************************************************/ /* Allows to get the real Vcc (return value * 100). */ /**************************************************************************************/ int getVoltage() { const long InternalReferenceVoltage = 1056L; ADMUX = (0<<REFS1) | (1<<REFS0) | (0<<ADLAR) | (1<<MUX3) | (1<<MUX2) | (1<<MUX1) | (0<<MUX0); delay(50); // Let mux settle a little to get a more stable A/D conversion //Start a conversion ADCSRA |= _BV( ADSC ); //Wait for it to complete while (((ADCSRA & (1<<ADSC)) != 0)); //Scale the value int result = (((InternalReferenceVoltage * 1023L) / ADC) + 5L) / 10L; return result; } /**************************************************************************************/ /* Allows to power ON peripherals. */ /**************************************************************************************/ void powerOnPeripherals() { //Power-up pinMode (POWER_PIN, OUTPUT); digitalWrite (POWER_PIN, HIGH); delay(1); } /**************************************************************************************/ /* Allows to power OFF peripherals. */ /**************************************************************************************/ void powerOffPeripherals() { //Power off digitalWrite (HUMIDITY_SENSOR_DIGITAL_PIN, LOW); digitalWrite (POWER_PIN, LOW); pinMode (HUMIDITY_SENSOR_DIGITAL_PIN, INPUT); pinMode (POWER_PIN, INPUT); }Hope it helps !
David.
-
@GertSanders indeed they are capacitors (silly me) - apparently they are 0.1uf - the black one I have already soldered is 4.7uf
-
@carlierd Are you running your Atmega at 1Mhz, Because I tried to use your sketch and i am getting "Checksum Error".
-
Bump, can anyone advise on how I got about finding out where I need to solder the resistors on? So far I've just soldered the 4.7uf capacitor, as can be seen from the pics. But I'm struggling to find out where I need to solder the other capacitor's I have (from the BOM).
-
Bump, can anyone advise on how I got about finding out where I need to solder the resistors on? So far I've just soldered the 4.7uf capacitor, as can be seen from the pics. But I'm struggling to find out where I need to solder the other capacitor's I have (from the BOM).
@rsachoc C1,C2,C3 are clearly marked at top layer silkscreen. You'll see them in the middle of the uC socket if you look at your 2nd picture in you last post above. C5 is visible next to the 4.7u cap, in the 3rd picture of my first post in this thread.
-
Progress!
http://imgur.com/zRvXvrN
http://imgur.com/KpB7dazA question though. To get to this point, I copied the pictures posted above, but where do I now add these resistors?
Also, if I want to add a 2AA battery cage, where do I connect the red and black wires to?
Thanks! And sorry for the newb questions!
-
Thanks, apologies, I really should have looked at my board, I was searching for the answer in the main slim node thread and I think i was looking at older boards and couldn't for the life of me find where C3 is!
-
-
@m26872 no problem, not your fault at all, mine for being a newbie. So much so that my first attempt resulted in me soldering the capacitor to the wrong hole, so I've had to abandon my first attempt. You live, you learn, next time I'll double check.
-
Hi all, again.
I have now successfully built (I think) the slim node, but without the 7021 temp sensor. Because this is the most expensive part of the device and because I find desoldering a challenge, but mainly because I'm waiting for it to arrive from China, can I try and upload the bootloader and sketch without the sensor attached?
If so, I had a couple questions from reading through this thread and the slim node thread. Firstly, uploading the bootloader, can this be done with the FTDI adaptor or do I need to follow the bit described in the slim node thread and attempt it using AVR studio? Secondly, once that is done, is it just a matter of uploading the sketch provided above?
Also, I wanted to confirm a few things on attaching the si7021 temp sensor. From what I can see, SOA (SDA) on the si7021 goes to A4 and SCL goes to A5. Also, GND goes to GND on the board (rightmost set on pins bottom right when FTDI is at the top) and VIN goes to VCC (just next to GND on the board)?
Thanks in advance.
-
Hi all, again.
I have now successfully built (I think) the slim node, but without the 7021 temp sensor. Because this is the most expensive part of the device and because I find desoldering a challenge, but mainly because I'm waiting for it to arrive from China, can I try and upload the bootloader and sketch without the sensor attached?
If so, I had a couple questions from reading through this thread and the slim node thread. Firstly, uploading the bootloader, can this be done with the FTDI adaptor or do I need to follow the bit described in the slim node thread and attempt it using AVR studio? Secondly, once that is done, is it just a matter of uploading the sketch provided above?
Also, I wanted to confirm a few things on attaching the si7021 temp sensor. From what I can see, SOA (SDA) on the si7021 goes to A4 and SCL goes to A5. Also, GND goes to GND on the board (rightmost set on pins bottom right when FTDI is at the top) and VIN goes to VCC (just next to GND on the board)?
Thanks in advance.
@rsachoc said:
can I try and upload the bootloader and sketch without the sensor attached?
Yes, you should be able to get far without the sensor. Send something over MySensors net and view debug prints. Or make some simple sensor like a reed switch.
uploading the bootloader, can this be done with the FTDI adaptor or do I need to follow the bit described in the slim node thread and attempt it using AVR studio?
Yes, Avr Studio or Uno as ISP.
Secondly, once that is done, is it just a matter of uploading the sketch provided above?
Yes, but if you don't connect a Si7021 I would go for some other simple test sketch to avoid any Si7021 library startup issues.
Also, I wanted to confirm a few things on attaching the si7021 temp sensor. From what I can see, SOA (SDA) on the si7021 goes to A4 and SCL goes to A5. Also, GND goes to GND on the board (rightmost set on pins bottom right when FTDI is at the top) and VIN goes to VCC (just next to GND on the board)?
Yes.
-
Folks, a word of caution, for people that are attempting this for the first time, please burn the bootloader before you solder everything, as silly me, I built the entire thing (without the si7021) and now I'll need to bin it because the ATMega is soldered to the board and I've no way to load the bootloader soldered to the board!
Ah, the life of a newbie :grin:
I think what I'll do is once I've actually got a working board, I'll do a newbie writeup so that people don't make the same mistakes as me.
-
Folks, a word of caution, for people that are attempting this for the first time, please burn the bootloader before you solder everything, as silly me, I built the entire thing (without the si7021) and now I'll need to bin it because the ATMega is soldered to the board and I've no way to load the bootloader soldered to the board!
Ah, the life of a newbie :grin:
I think what I'll do is once I've actually got a working board, I'll do a newbie writeup so that people don't make the same mistakes as me.
-
@rsachoc Why don't you just solder some wires to pins you need ? The "in cicuit serial programming" concept would let you do it with almost anything attached.
-
Some of my tips (noob alert) that I've gathered in my travels so far for this temp Slim node
- Burn the bootloader onto the ATMega328 first! (here is a guide for Arduino as ISP)
- Check the capacitor polarity before you solder it (the 4.7uF electrolytic capacitor, the others don't matter)
- I prefer using strips for the Atmega (see here) as you'll have more clearance for the capacitors which sit underneath (there is a caveat to this however, in that if you're not sure if you've got/burnt a bootloader onto the ATMega, using strips there is no going back, whereas with the chip socket, you can remove the ATMega). Update I think, for me anyway, if you're confident that the ATMega has been bootloaded successfully, I still prefer strips, however if you're unsure what you can do is use the socket and just sit it higher in it's position to get a decent clearance.
- The bill of materials (BOM) is here and also helps with figuring out which pieces go where
- Solder the capacitors, wires for Si7021 (with si7021 attached) and FTDI pins to the board first, then the strips + AtMega328p (see below), then the NRF last to the board. I found that the FTDI pins facing straight up were best for the box I was going to put it in
- Solder the strips to the ATMega first, then to the board
- Check the size of the box/fitting you are going to mount this in before you do all the above!
- Check that you are putting the ATMega chip the right way on the board, the notch should be facing the pins for the FTDI.
- Check continuity of the pins from the ATMega to the board pins underneath, I found the ATMega to strips were the most difficult to solder, and after I tested continuity I found a single pin which didn't have connection, so I added some more solder to this pin.
- Don't forget the resistor at R1 (I soldered this to the underside of the board, less by choice and more by the fact that I forgot about it, but I guess the preference would be the same side as the capacitors)
- I strongly advise buying the 3.3v ready si7021 temp sensor (here) as the modification to the 5v version is quite difficult for a newbie (the components are quite small) and you'll probably mess it up like I did.
General soldering tips
12) Practice soldering first, some of the joins are a little challenging and it took me a few attempts to get the hang of it
13) Get a decent size tip, my first was a bit large -
Some of my tips (noob alert) that I've gathered in my travels so far for this temp Slim node
- Burn the bootloader onto the ATMega328 first! (here is a guide for Arduino as ISP)
- Check the capacitor polarity before you solder it (the 4.7uF electrolytic capacitor, the others don't matter)
- I prefer using strips for the Atmega (see here) as you'll have more clearance for the capacitors which sit underneath (there is a caveat to this however, in that if you're not sure if you've got/burnt a bootloader onto the ATMega, using strips there is no going back, whereas with the chip socket, you can remove the ATMega). Update I think, for me anyway, if you're confident that the ATMega has been bootloaded successfully, I still prefer strips, however if you're unsure what you can do is use the socket and just sit it higher in it's position to get a decent clearance.
- The bill of materials (BOM) is here and also helps with figuring out which pieces go where
- Solder the capacitors, wires for Si7021 (with si7021 attached) and FTDI pins to the board first, then the strips + AtMega328p (see below), then the NRF last to the board. I found that the FTDI pins facing straight up were best for the box I was going to put it in
- Solder the strips to the ATMega first, then to the board
- Check the size of the box/fitting you are going to mount this in before you do all the above!
- Check that you are putting the ATMega chip the right way on the board, the notch should be facing the pins for the FTDI.
- Check continuity of the pins from the ATMega to the board pins underneath, I found the ATMega to strips were the most difficult to solder, and after I tested continuity I found a single pin which didn't have connection, so I added some more solder to this pin.
- Don't forget the resistor at R1 (I soldered this to the underside of the board, less by choice and more by the fact that I forgot about it, but I guess the preference would be the same side as the capacitors)
- I strongly advise buying the 3.3v ready si7021 temp sensor (here) as the modification to the 5v version is quite difficult for a newbie (the components are quite small) and you'll probably mess it up like I did.
General soldering tips
12) Practice soldering first, some of the joins are a little challenging and it took me a few attempts to get the hang of it
13) Get a decent size tip, my first was a bit large@rsachoc As a great man once said: "most bananas grow bent, and yet everyone loves them. There is nothing strange about the diversity of routes to success"
-
Thanks all, I'm sure I will be adding to it, as I'm now trying to compile and upload the sketch. However, I'm getting the following error:
#error No forward link or gateway feature activated. This means nowhere to send messages! Pretty pointless. ^ exit status 1 Error compiling.I'm using the W5100 MQTT gateway sketch (which I believe is on the development branch), so I'm not sure if that's what's causing the error? I've tried deleting the Arduino IDE, the mysensors development branch from my PC, and reinstalling and redownloading the mysensors dev branch, but the same thing happens?
-
OK, so it seems that it was because I was using the dev branch that I'm getting that error. I switched over to stable and the sketch compiles, although I do get a warning.
WARNING: Category '' in library UIPEthernet is not valid. Setting to 'Uncategorized'But I also can't upload the sketch above:
avrdude: stk500_recv(): programmer is not responding avrdude: stk500_getsync() attempt 1 of 10: not in sync: resp=0x18I noted above that something needed to be changed in terms of the baud rate, mine is set at 115200 in myconfig.h and I can't seem to find a reference in mysensor.h