Skip to content
  • MySensors
  • OpenHardware.io
  • Categories
  • Recent
  • Tags
  • Popular
Skins
  • Light
  • Brite
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Brand Logo
  1. Home
  2. Development
  3. Can't get RFM69 working

Can't get RFM69 working

Scheduled Pinned Locked Moved Development
27 Posts 5 Posters 10.0k Views 3 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • SweebeeS Offline
    SweebeeS Offline
    Sweebee
    wrote on last edited by
    #5

    Arduino uno > level shifter > RFM69HW

    the level shifter / RFM is powered by a separate 5 > 3.3v converter.

    1 Reply Last reply
    0
    • carlierdC Offline
      carlierdC Offline
      carlierd
      wrote on last edited by
      #6

      hello,

      How did you powered the rfm69 on the uno ? using the 3.3 from the uno or using a voltage regulator ?
      I first used voltage regulator but I encountered some issues with the uno so I finally directly used the 3.3 from the uni board.

      another thing, remove not used include such 'MyTransportNRF24' in your code.

      I will post my gateway and sensor code thus evening as I can't do it from my phone now ...

      1 Reply Last reply
      0
      • SweebeeS Offline
        SweebeeS Offline
        Sweebee
        wrote on last edited by
        #7

        The RFM is powered by the regulator. Havent tried to power it from the 3v from the arduino yet.

        1 Reply Last reply
        0
        • carlierdC Offline
          carlierdC Offline
          carlierd
          wrote on last edited by
          #8

          Hello,

          The code as promise.
          For the gateway I don't change a lot of thing from the example provided in the lib:

          /**
           * 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.
           *
           */
          
          /**************************************************************************************/
          /* Serial gateway (RFM69 with encryption, soft signing and LEDs).                     */
          /*                                                                                    */
          /* Version     : 0.1.1                                                                */
          /* Date        : 29/11/2015                                                           */
          /* Modified by : David Carlier                                                        */
          /**************************************************************************************/
          
          #define NO_PORTB_PINCHANGES
          
          #include <MyTransportRFM69.h>
          #include <MyHwATMega328.h>
          #include <MySigningAtsha204Soft.h>
          
          #include <SPI.h>
          #include <MyParserSerial.h>
          #include <MySensor.h>
          #include <stdarg.h>
          #include <PinChangeInt.h>
          #include "GatewayUtil.h"
          
          #define INCLUSION_MODE_TIME 1 // Number of minutes inclusion mode is enabled
          #define INCLUSION_MODE_PIN  3 // Digital pin used for inclusion mode button
          #define RADIO_ERROR_LED_PIN 4  // Error led pin
          #define RADIO_RX_LED_PIN    6  // Receive led pin
          #define RADIO_TX_LED_PIN    5  // the PCB, on board LED
          
          //Construct MySensors library
          MySigningAtsha204Soft signer;
          MyHwATMega328 hw;
          MyTransportRFM69 transport;
          MySensor gw(transport, hw, signer, RADIO_RX_LED_PIN, RADIO_TX_LED_PIN, RADIO_ERROR_LED_PIN);
          
          //Variables
          char inputString[MAX_RECEIVE_LENGTH] = "";
          int inputPos = 0;
          boolean commandComplete = false;
          
          void parseAndSend(char *commandBuffer);
          
          void output(const char *fmt, ... ) {
             va_list args;
             va_start (args, fmt );
             vsnprintf_P(serialBuffer, MAX_SEND_LENGTH, fmt, args);
             va_end (args);
             Serial.print(serialBuffer);
          }
          
            
          /**************************************************************************************/
          /* Initialization                                                                     */
          /**************************************************************************************/
          void setup()
            {
            //Start MySensors
            gw.begin(incomingMessage, 0, true, 0);
            setupGateway(INCLUSION_MODE_PIN, INCLUSION_MODE_TIME, output);
          
            //Add interrupt for inclusion button to pin
            PCintPort::attachInterrupt(pinInclusion, startInclusionInterrupt, RISING);
          
            //Send startup log message on serial
            serial(PSTR("0;0;%d;0;%d;Gateway startup complete.\n"), C_INTERNAL, I_GATEWAY_READY);
            }
          
          /**************************************************************************************/
          /* Main loop                                                                          */
          /**************************************************************************************/
          void loop()
            {
            gw.process();
          
            checkButtonTriggeredInclusion();
            checkInclusionFinished();
          
            if (commandComplete)
              {
              //A command wass issued from serial interface
              //We will now try to send it to the actuator
              parseAndSend(gw, inputString);
              commandComplete = false;  
              inputPos = 0;
              }
            }
          
          /*
            SerialEvent occurs whenever a new data comes in the
           hardware serial RX.  This routine is run between each
           time loop() runs, so using delay inside loop can delay
           response.  Multiple bytes of data may be available.
           */
          void serialEvent() {
            while (Serial.available()) {
              // get the new byte:
              char inChar = (char)Serial.read(); 
              // if the incoming character is a newline, set a flag
              // so the main loop can do something about it:
              if (inputPos<MAX_RECEIVE_LENGTH-1 && !commandComplete) { 
                if (inChar == '\n') {
                  inputString[inputPos] = 0;
                  commandComplete = true;
                } else {
                  // add it to the inputString:
                  inputString[inputPos] = inChar;
                  inputPos++;
                }
              } else {
                 // Incoming message too long. Throw away 
                  inputPos = 0;
              }
            }
          }
          

          For the sensor, there is more difference from the humidity example:

          /**
           * 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.5                                                                */
          /* Date        : 04/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 and DHT22 et SWITCH.                                           */
          /* +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 = 275000; // Sleep time between reads (in milliseconds)
          
          //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();
            delay(2000);
          
            //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);
            }
          
          

          David

          SweebeeS 1 Reply Last reply
          0
          • SweebeeS Offline
            SweebeeS Offline
            Sweebee
            wrote on last edited by
            #9

            Thanks, will try it :)

            1 Reply Last reply
            0
            • L Offline
              L Offline
              lafleur
              wrote on last edited by
              #10

              How do you change I/O pins define for the RFM69 if using a different platform??

              will this work under 1.6 development ?

              Thanks

              1 Reply Last reply
              0
              • carlierdC carlierd

                Hello,

                The code as promise.
                For the gateway I don't change a lot of thing from the example provided in the lib:

                /**
                 * 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.
                 *
                 */
                
                /**************************************************************************************/
                /* Serial gateway (RFM69 with encryption, soft signing and LEDs).                     */
                /*                                                                                    */
                /* Version     : 0.1.1                                                                */
                /* Date        : 29/11/2015                                                           */
                /* Modified by : David Carlier                                                        */
                /**************************************************************************************/
                
                #define NO_PORTB_PINCHANGES
                
                #include <MyTransportRFM69.h>
                #include <MyHwATMega328.h>
                #include <MySigningAtsha204Soft.h>
                
                #include <SPI.h>
                #include <MyParserSerial.h>
                #include <MySensor.h>
                #include <stdarg.h>
                #include <PinChangeInt.h>
                #include "GatewayUtil.h"
                
                #define INCLUSION_MODE_TIME 1 // Number of minutes inclusion mode is enabled
                #define INCLUSION_MODE_PIN  3 // Digital pin used for inclusion mode button
                #define RADIO_ERROR_LED_PIN 4  // Error led pin
                #define RADIO_RX_LED_PIN    6  // Receive led pin
                #define RADIO_TX_LED_PIN    5  // the PCB, on board LED
                
                //Construct MySensors library
                MySigningAtsha204Soft signer;
                MyHwATMega328 hw;
                MyTransportRFM69 transport;
                MySensor gw(transport, hw, signer, RADIO_RX_LED_PIN, RADIO_TX_LED_PIN, RADIO_ERROR_LED_PIN);
                
                //Variables
                char inputString[MAX_RECEIVE_LENGTH] = "";
                int inputPos = 0;
                boolean commandComplete = false;
                
                void parseAndSend(char *commandBuffer);
                
                void output(const char *fmt, ... ) {
                   va_list args;
                   va_start (args, fmt );
                   vsnprintf_P(serialBuffer, MAX_SEND_LENGTH, fmt, args);
                   va_end (args);
                   Serial.print(serialBuffer);
                }
                
                  
                /**************************************************************************************/
                /* Initialization                                                                     */
                /**************************************************************************************/
                void setup()
                  {
                  //Start MySensors
                  gw.begin(incomingMessage, 0, true, 0);
                  setupGateway(INCLUSION_MODE_PIN, INCLUSION_MODE_TIME, output);
                
                  //Add interrupt for inclusion button to pin
                  PCintPort::attachInterrupt(pinInclusion, startInclusionInterrupt, RISING);
                
                  //Send startup log message on serial
                  serial(PSTR("0;0;%d;0;%d;Gateway startup complete.\n"), C_INTERNAL, I_GATEWAY_READY);
                  }
                
                /**************************************************************************************/
                /* Main loop                                                                          */
                /**************************************************************************************/
                void loop()
                  {
                  gw.process();
                
                  checkButtonTriggeredInclusion();
                  checkInclusionFinished();
                
                  if (commandComplete)
                    {
                    //A command wass issued from serial interface
                    //We will now try to send it to the actuator
                    parseAndSend(gw, inputString);
                    commandComplete = false;  
                    inputPos = 0;
                    }
                  }
                
                /*
                  SerialEvent occurs whenever a new data comes in the
                 hardware serial RX.  This routine is run between each
                 time loop() runs, so using delay inside loop can delay
                 response.  Multiple bytes of data may be available.
                 */
                void serialEvent() {
                  while (Serial.available()) {
                    // get the new byte:
                    char inChar = (char)Serial.read(); 
                    // if the incoming character is a newline, set a flag
                    // so the main loop can do something about it:
                    if (inputPos<MAX_RECEIVE_LENGTH-1 && !commandComplete) { 
                      if (inChar == '\n') {
                        inputString[inputPos] = 0;
                        commandComplete = true;
                      } else {
                        // add it to the inputString:
                        inputString[inputPos] = inChar;
                        inputPos++;
                      }
                    } else {
                       // Incoming message too long. Throw away 
                        inputPos = 0;
                    }
                  }
                }
                

                For the sensor, there is more difference from the humidity example:

                /**
                 * 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.5                                                                */
                /* Date        : 04/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 and DHT22 et SWITCH.                                           */
                /* +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 = 275000; // Sleep time between reads (in milliseconds)
                
                //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();
                  delay(2000);
                
                  //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);
                  }
                
                

                David

                SweebeeS Offline
                SweebeeS Offline
                Sweebee
                wrote on last edited by
                #11

                @carlierd I tried to compile your gateway but i get this error:

                Arduino: 1.6.5 (Mac OS X), Board:"Arduino Uno"
                
                SerialGateway:52: error: no matching function for call to 'MySensor::MySensor(MyTransportRFM69&, MyHwATMega328&, MySigningAtsha204Soft&, int, int, int)'
                SerialGateway.ino:52:91: note: candidates are:
                In file included from SerialGateway.ino:37:0:
                /Users/Wiebe/Documents/Arduino/libraries/MySensors/MySensor.h:158:2: note: MySensor::MySensor(MyTransport&, MyHw&)
                  MySensor(MyTransport &radio =*new MyTransportNRF24(), MyHw &hw=*new MyHwDriver()
                  ^
                /Users/Wiebe/Documents/Arduino/libraries/MySensors/MySensor.h:158:2: note:   candidate expects 2 arguments, 6 provided
                /Users/Wiebe/Documents/Arduino/libraries/MySensors/MySensor.h:149:7: note: MySensor::MySensor(const MySensor&)
                 class MySensor
                       ^
                /Users/Wiebe/Documents/Arduino/libraries/MySensors/MySensor.h:149:7: note:   candidate expects 1 argument, 6 provided
                no matching function for call to 'MySensor::MySensor(MyTransportRFM69&, MyHwATMega328&, MySigningAtsha204Soft&, int, int, int)'
                
                
                1 Reply Last reply
                0
                • carlierdC Offline
                  carlierdC Offline
                  carlierd
                  wrote on last edited by
                  #12

                  Hello,

                  I am using stable version of MySensors not the dev branch. What version are you using ?

                  David

                  SweebeeS 1 Reply Last reply
                  0
                  • carlierdC carlierd

                    Hello,

                    I am using stable version of MySensors not the dev branch. What version are you using ?

                    David

                    SweebeeS Offline
                    SweebeeS Offline
                    Sweebee
                    wrote on last edited by
                    #13

                    @carlierd 1.5 https://github.com/mysensors/Arduino/tree/master

                    1 Reply Last reply
                    0
                    • carlierdC Offline
                      carlierdC Offline
                      carlierd
                      wrote on last edited by
                      #14

                      @Sweebee said:

                      SerialGateway:52: error: no matching function for call to 'MySensor::MySensor(MyTransportRFM69&, MyHwATMega328&, MySigningAtsha204Soft&, int, int, int)'

                      Did you enabled signing feature in MyConfig.h : #define MY_SIGNING_FEATURE ??

                      1 Reply Last reply
                      0
                      • SweebeeS Offline
                        SweebeeS Offline
                        Sweebee
                        wrote on last edited by
                        #15

                        I think the gateway works now, i removed the separate 5-3.3v converter and used the arduino 3.3v.

                        Now the sensor, i uploaden your sketch, but i get no init message?

                        1 Reply Last reply
                        0
                        • carlierdC Offline
                          carlierdC Offline
                          carlierd
                          wrote on last edited by
                          #16

                          Did you connect the gateway to a controller ? or to MYSController ? You get the gateway ready message ?

                          For the sensor, you are using the sketch I upload ?
                          Debug mode is enable in MyConfig.h ?

                          You should have some debug messages in the console when connecting to the node.

                          David.

                          1 Reply Last reply
                          0
                          • SweebeeS Offline
                            SweebeeS Offline
                            Sweebee
                            wrote on last edited by Sweebee
                            #17

                            The problem is on the uno everything seems to work fine.

                            for the sensor i attached the RFM to a arduino pro mini 3.3v

                            double checked the wiring, tried 2 different RFM's, tried 2 arduino pro mini's.

                            uploaden the gateway to it and i get:

                            0;0;3;0;9;gateway started, id=0, parent=0, distance=0
                            

                            but when i try to send something with the pro mini i get nothing back, while on the UNO I get:

                            0;0;3;0;9;send: 0-0-10-10 s=1,c=1,t=2,pt=0,l=1,sg=0,st=fail:1
                            

                            So on the pro mini i get the init message, but no message when i try to send something.

                            1 Reply Last reply
                            0
                            • carlierdC Offline
                              carlierdC Offline
                              carlierd
                              wrote on last edited by
                              #18

                              RFM69 or RFM69HW ?

                              For RFM69HW you have to modify MyTransportRFM69.hand enable HW model on line 33.
                              Replace bool isRFM69HW=falseby bool isRFM69HW=true.

                              Nothing on the serial output of the pro mini ??

                              1 Reply Last reply
                              0
                              • fetsF Offline
                                fetsF Offline
                                fets
                                wrote on last edited by
                                #19

                                Do you use 4.7uF capacitor ?

                                1 Reply Last reply
                                0
                                • SweebeeS Offline
                                  SweebeeS Offline
                                  Sweebee
                                  wrote on last edited by Sweebee
                                  #20

                                  Yes i have the HW versions, so i replaced bool isRFM69HW=false by bool isRFM69HW=true

                                  added a capacitor.

                                  refreshed and still no feedback after sending.

                                  I get a serial output from the pro mini on start. but no more serial messages when i try to send a message.

                                  1 Reply Last reply
                                  0
                                  • carlierdC Offline
                                    carlierdC Offline
                                    carlierd
                                    wrote on last edited by
                                    #21

                                    Put your arduino pro debug message to see what happens.

                                    You used DHT22 ?

                                    1 Reply Last reply
                                    0
                                    • SweebeeS Offline
                                      SweebeeS Offline
                                      Sweebee
                                      wrote on last edited by
                                      #22

                                      Its working now!

                                      Gateway doesn't work on the pro mini, but your sensor sketch is working :D

                                      now the next thing, i get a lot of fails:

                                      send: 10-10-0-0 s=255,c=3,t=11,pt=0,l=11,sg=0,st=fail:GHAS sensor
                                      send: 10-10-0-0 s=255,c=3,t=12,pt=0,l=5,sg=0,st=fail:1.1.5
                                      send: 10-10-0-0 s=0,c=0,t=7,pt=0,l=0,sg=0,st=fail:
                                      find parent
                                      send: 10-10-255-255 s=255,c=3,t=7,pt=0,l=0,sg=0,st=bc:
                                      send: 10-10-0-0 s=1,c=0,t=6,pt=0,l=0,sg=0,st=fail:
                                      send: 10-10-0-0 s=2,c=0,t=16,pt=0,l=0,sg=0,st=fail:
                                      send: 10-10-0-0 s=3,c=0,t=30,pt=0,l=0,sg=0,st=fail:
                                      [Setup duration: 7385 ms]
                                      send: 10-10-0-0 s=0,c=1,t=1,pt=7,l=5,sg=0,st=fail:0.0
                                      send: 10-10-0-0 s=1,c=1,t=0,pt=7,l=5,sg=0,st=fail:0.0
                                      send: 10-10-0-0 s=2,c=1,t=37,pt=2,l=2,sg=0,st=fail:9
                                      find parent
                                      send: 10-10-255-255 s=255,c=3,t=7,pt=0,l=0,sg=0,st=bc:
                                      send: 10-10-0-0 s=3,c=1,t=38,pt=7,l=5,sg=0,st=fail:3.30
                                      send: 10-10-0-0 s=255,c=3,t=0,pt=1,l=1,sg=0,st=fail:100
                                      0.0 degC   0.0 %   9 lx   3.30 v   [4851 ms]
                                      

                                      but the gateway receives everything fine?

                                      22:13:05.403 [pimatic-mysensors] debug: <- Presented Node  [ '10', '0', '0', '0', '7', '' ]
                                      22:13:05.451 [pimatic-mysensors] debug: <- I_LOG_MESSAGE  0;0;3;0;9;read: 10-10-255 s=255,c=3,t=7,pt=0,l=0,sg=0:
                                      22:13:05.497 [pimatic-mysensors] debug: <- I_LOG_MESSAGE  0;0;3;0;9;read: 10-10-255 s=255,c=3,t=7,pt=0,l=0,sg=0:
                                      22:13:05.538 [pimatic-mysensors] debug: <- I_LOG_MESSAGE  0;0;3;0;9;read: 10-10-255 s=255,c=3,t=7,pt=0,l=0,sg=0:
                                      22:13:05.980 [pimatic-mysensors] debug: <- I_LOG_MESSAGE  0;0;3;0;9;send: 0-0-10-10 s=255,c=3,t=8,pt=1,l=1,sg=0,st=fail:0
                                      22:13:06.115 [pimatic-mysensors] debug: <- I_LOG_MESSAGE  0;0;3;0;9;send: 0-0-10-10 s=255,c=3,t=8,pt=1,l=1,sg=0,st=fail:0
                                      22:13:06.246 [pimatic-mysensors] debug: <- I_LOG_MESSAGE  0;0;3;0;9;send: 0-0-10-10 s=255,c=3,t=8,pt=1,l=1,sg=0,st=fail:0
                                      22:13:07.594 [pimatic-mysensors] debug: <- I_LOG_MESSAGE  0;0;3;0;9;read: 10-10-0 s=1,c=0,t=6,pt=0,l=0,sg=0:
                                      22:13:07.594 [pimatic-mysensors] debug: <- Presented Node  [ '10', '1', '0', '0', '6', '' ]
                                      22:13:07.635 [pimatic-mysensors] debug: <- I_LOG_MESSAGE  0;0;3;0;9;read: 10-10-0 s=1,c=0,t=6,pt=0,l=0,sg=0:
                                      22:13:07.639 [pimatic-mysensors] debug: <- Presented Node  [ '10', '1', '0', '0', '6', '' ]
                                      22:13:07.680 [pimatic-mysensors] debug: <- I_LOG_MESSAGE  0;0;3;0;9;read: 10-10-0 s=1,c=0,t=6,pt=0,l=0,sg=0:
                                      22:13:07.680 [pimatic-mysensors] debug: <- Presented Node  [ '10', '1', '0', '0', '6', '' ]
                                      22:13:07.729 [pimatic-mysensors] debug: <- I_LOG_MESSAGE  0;0;3;0;9;read: 10-10-0 s=2,c=0,t=16,pt=0,l=0,sg=0:
                                      22:13:07.729 [pimatic-mysensors] debug: <- Presented Node  [ '10', '2', '0', '0', '16', '' ]
                                      22:13:07.774 [pimatic-mysensors] debug: <- I_LOG_MESSAGE  0;0;3;0;9;read: 10-10-0 s=2,c=0,t=16,pt=0,l=0,sg=0:
                                      22:13:07.775 [pimatic-mysensors] debug: <- Presented Node  [ '10', '2', '0', '0', '16', '' ]
                                      22:13:07.815 [pimatic-mysensors] debug: <- I_LOG_MESSAGE  0;0;3;0;9;read: 10-10-0 s=2,c=0,t=16,pt=0,l=0,sg=0:
                                      22:13:07.816 [pimatic-mysensors] debug: <- Presented Node  [ '10', '2', '0', '0', '16', '' ]
                                      22:13:07.864 [pimatic-mysensors] debug: <- I_LOG_MESSAGE  0;0;3;0;9;read: 10-10-0 s=3,c=0,t=30,pt=0,l=0,sg=0:
                                      22:13:07.865 [pimatic-mysensors] debug: <- Presented Node  [ '10', '3', '0', '0', '30', '' ]
                                      22:13:07.909 [pimatic-mysensors] debug: <- I_LOG_MESSAGE  0;0;3;0;9;read: 10-10-0 s=3,c=0,t=30,pt=0,l=0,sg=0:
                                      22:13:07.909 [pimatic-mysensors] debug: <- Presented Node  [ '10', '3', '0', '0', '30', '' ]
                                      22:13:07.950 [pimatic-mysensors] debug: <- I_LOG_MESSAGE  0;0;3;0;9;read: 10-10-0 s=3,c=0,t=30,pt=0,l=0,sg=0:
                                      22:13:07.954 [pimatic-mysensors] debug: <- Presented Node  [ '10', '3', '0', '0', '30', '' ]
                                      22:13:10.060 [pimatic-mysensors] debug: <- I_LOG_MESSAGE  0;0;3;0;9;read: 10-10-0 s=0,c=1,t=1,pt=7,l=5,sg=0:0.0
                                      22:13:10.105 [pimatic-mysensors] debug: <- I_LOG_MESSAGE  0;0;3;0;9;read: 10-10-0 s=0,c=1,t=1,pt=7,l=5,sg=0:0.0
                                      22:13:10.150 [pimatic-mysensors] debug: <- I_LOG_MESSAGE  0;0;3;0;9;read: 10-10-0 s=0,c=1,t=1,pt=7,l=5,sg=0:0.0
                                      22:13:10.244 [pimatic-mysensors] debug: <- I_LOG_MESSAGE  0;0;3;0;9;read: 10-10-0 s=1,c=1,t=0,pt=7,l=5,sg=0:0.0
                                      22:13:10.289 [pimatic-mysensors] debug: <- I_LOG_MESSAGE  0;0;3;0;9;read: 10-10-0 s=1,c=1,t=0,pt=7,l=5,sg=0:0.0
                                      22:13:10.342 [pimatic-mysensors] debug: <- I_LOG_MESSAGE  0;0;3;0;9;read: 10-10-0 s=2,c=1,t=37,pt=2,l=2,sg=0:9
                                      22:13:10.383 [pimatic-mysensors] debug: <- I_LOG_MESSAGE  0;0;3;0;9;read: 10-10-0 s=2,c=1,t=37,pt=2,l=2,sg=0:9
                                      22:13:10.428 [pimatic-mysensors] debug: <- I_LOG_MESSAGE  0;0;3;0;9;read: 10-10-0 s=2,c=1,t=37,pt=2,l=2,sg=0:9
                                      22:13:10.477 [pimatic-mysensors] debug: <- I_LOG_MESSAGE  0;0;3;0;9;read: 10-10-255 s=255,c=3,t=7,pt=0,l=0,sg=0:
                                      22:13:10.522 [pimatic-mysensors] debug: <- I_LOG_MESSAGE  0;0;3;0;9;read: 10-10-255 s=255,c=3,t=7,pt=0,l=0,sg=0:
                                      22:13:10.563 [pimatic-mysensors] debug: <- I_LOG_MESSAGE  0;0;3;0;9;read: 10-10-255 s=255,c=3,t=7,pt=0,l=0,sg=0:
                                      22:13:10.903 [pimatic-mysensors] debug: <- I_LOG_MESSAGE  0;0;3;0;9;send: 0-0-10-10 s=255,c=3,t=8,pt=1,l=1,sg=0,st=fail:0
                                      22:13:11.038 [pimatic-mysensors] debug: <- I_LOG_MESSAGE  0;0;3;0;9;send: 0-0-10-10 s=255,c=3,t=8,pt=1,l=1,sg=0,st=fail:0
                                      22:13:11.174 [pimatic-mysensors] debug: <- I_LOG_MESSAGE  0;0;3;0;9;send: 0-0-10-10 s=255,c=3,t=8,pt=1,l=1,sg=0,st=fail:0
                                      22:13:12.583 [pimatic-mysensors] debug: <- I_LOG_MESSAGE  0;0;3;0;9;read: 10-10-0 s=3,c=1,t=38,pt=7,l=5,sg=0:3.30
                                      22:13:12.628 [pimatic-mysensors] debug: <- I_LOG_MESSAGE  0;0;3;0;9;read: 10-10-0 s=3,c=1,t=38,pt=7,l=5,sg=0:3.30
                                      22:13:12.673 [pimatic-mysensors] debug: <- I_LOG_MESSAGE  0;0;3;0;9;read: 10-10-0 s=3,c=1,t=38,pt=7,l=5,sg=0:3.30
                                      22:13:12.722 [pimatic-mysensors] debug: <- I_LOG_MESSAGE  0;0;3;0;9;read: 10-10-0 s=255,c=3,t=0,pt=1,l=1,sg=0:100
                                      
                                      1 Reply Last reply
                                      0
                                      • carlierdC Offline
                                        carlierdC Offline
                                        carlierd
                                        wrote on last edited by
                                        #23

                                        It's perhaps due to the signing feature ...

                                        May be you should disable it for the moment.

                                        Disable the feature in MyConfig.h and replace the gateway constructor by:

                                        MySensor gw(transport, hw /*, signer*/, RADIO_RX_LED_PIN, RADIO_TX_LED_PIN, RADIO_ERROR_LED_PIN);
                                        
                                        1 Reply Last reply
                                        0
                                        • SweebeeS Offline
                                          SweebeeS Offline
                                          Sweebee
                                          wrote on last edited by Sweebee
                                          #24

                                          Thanks! it working great now.

                                          Why does signing not work? Because of the controller? or is this handled by the gateway?

                                          Edit: Oh it was disabled on the gateway, now it works :)

                                          1 Reply Last reply
                                          0
                                          Reply
                                          • Reply as topic
                                          Log in to reply
                                          • Oldest to Newest
                                          • Newest to Oldest
                                          • Most Votes


                                          9

                                          Online

                                          11.7k

                                          Users

                                          11.2k

                                          Topics

                                          113.1k

                                          Posts


                                          Copyright 2025 TBD   |   Forum Guidelines   |   Privacy Policy   |   Terms of Service
                                          • Login

                                          • Don't have an account? Register

                                          • Login or register to search.
                                          • First post
                                            Last post
                                          0
                                          • MySensors
                                          • OpenHardware.io
                                          • Categories
                                          • Recent
                                          • Tags
                                          • Popular