Jeedom on RaspberryPI with Arduino Uno on USB and remote Arduino pro mini



  • Dear All,
    i'm doing a project with Jeedom and Mysensors.

    Raspberry PI 2 B [Jeedom] ---(usb)---> Arduino Uno [Serial Gateway] ---(nrf24)--> 433Mhz <---(nrf24)--- Arduino pro mini Sparkfun ---> dht11

    I use Mysensors Framework v2.1.1 for both Arduinos.

    I hope to manage several Arduino pro mini through Jeedom.

    I used tutorial Jeedom



  • Arduino pro mini sketch.

    /**
     * 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.
     *
     *******************************
     *
     * REVISION HISTORY
     * Version 1.0: Henrik EKblad
     * Version 1.1 - 2016-07-20: Converted to MySensors v2.0 and added various improvements - Torben Woltjen (mozzbozz)
     * 
     * DESCRIPTION
     * This sketch provides an example of how to implement a humidity/temperature
     * sensor using a DHT11/DHT-22.
     *  
     * For more information, please visit:
     * http://www.mysensors.org/build/humidity
     * 
     */
    
    // Enable debug prints
    #define MY_DEBUG
    
    // Enable and select radio type attached 
    #define MY_RADIO_NRF24
    //#define MY_RADIO_RFM69
    //#define MY_RS485
    
    
    /**
     * @def MY_NODE_ID
     * @brief Node id defaults to AUTO (tries to fetch id from controller).
     */
    //#define MY_NODE_ID 1
    
    
    // Define a lower baud rate for Arduino's running on 8 MHz (Arduino Pro Mini 3.3V & SenseBender)
    #if F_CPU == 8000000L
    #define MY_BAUD_RATE 38400
    #endif
    
    
    #include <SPI.h>
    #include <MySensors.h>  
    #include <DHT.h>
    
    // Set this to the pin you connected the DHT's data pin to
    #define DHT_DATA_PIN 3
    
    // Set this offset if the sensor has a permanent small offset to the real temperatures
    #define SENSOR_TEMP_OFFSET 0
    
    // Sleep time between sensor updates (in milliseconds)
    // Must be >1000ms for DHT22 and >2000ms for DHT11
    static const uint64_t UPDATE_INTERVAL = 60000;
    
    // Force sending an update of the temperature after n sensor reads, so a controller showing the
    // timestamp of the last update doesn't show something like 3 hours in the unlikely case, that
    // the value didn't change since;
    // i.e. the sensor would force sending an update every UPDATE_INTERVAL*FORCE_UPDATE_N_READS [ms]
    static const uint8_t FORCE_UPDATE_N_READS = 10;
    
    #define CHILD_ID_HUM 0
    #define CHILD_ID_TEMP 1
    
    float lastTemp;
    float lastHum;
    uint8_t nNoUpdatesTemp;
    uint8_t nNoUpdatesHum;
    bool metric = true;
    
    MyMessage msgHum(CHILD_ID_HUM, V_HUM);
    MyMessage msgTemp(CHILD_ID_TEMP, V_TEMP);
    DHT dht;
    
    
    void presentation()  
    { 
      // Send the sketch version information to the gateway
      sendSketchInfo("TemperatureAndHumidity", "1.1");
      
      // Register all sensors to gw (they will be created as child devices)
      present(CHILD_ID_HUM, S_HUM);
      present(CHILD_ID_TEMP, S_TEMP);
      
      metric = getControllerConfig().isMetric;
    }
    
    
    void setup()
    {
      dht.setup(DHT_DATA_PIN); // set data pin of DHT sensor
      if (UPDATE_INTERVAL <= dht.getMinimumSamplingPeriod()) {
        Serial.println("Warning: UPDATE_INTERVAL is smaller than supported by the sensor!");
      }
      // Sleep for the time of the minimum sampling period to give the sensor time to power up
      // (otherwise, timeout errors might occure for the first reading)
      sleep(dht.getMinimumSamplingPeriod());
    }
    
    
    void loop()      
    {  
      // Force reading sensor, so it works also after sleep()
      dht.readSensor(true);
      
      // Get temperature from DHT library
      float temperature = dht.getTemperature();
      if (isnan(temperature)) {
        Serial.println("Failed reading temperature from DHT!");
      } else if (temperature != lastTemp || nNoUpdatesTemp == FORCE_UPDATE_N_READS) {
        // Only send temperature if it changed since the last measurement or if we didn't send an update for n times
        lastTemp = temperature;
        if (!metric) {
          temperature = dht.toFahrenheit(temperature);
        }
        // Reset no updates counter
        nNoUpdatesTemp = 0;
        temperature += SENSOR_TEMP_OFFSET;
        send(msgTemp.set(temperature, 1));
    
        #ifdef MY_DEBUG
        Serial.print("T: ");
        Serial.println(temperature);
        #endif
      } else {
        // Increase no update counter if the temperature stayed the same
        nNoUpdatesTemp++;
      }
    
      // Get humidity from DHT library
      float humidity = dht.getHumidity();
      if (isnan(humidity)) {
        Serial.println("Failed reading humidity from DHT");
      } else if (humidity != lastHum || nNoUpdatesHum == FORCE_UPDATE_N_READS) {
        // Only send humidity if it changed since the last measurement or if we didn't send an update for n times
        lastHum = humidity;
        // Reset no updates counter
        nNoUpdatesHum = 0;
        send(msgHum.set(humidity, 1));
        
        #ifdef MY_DEBUG
        Serial.print("H: ");
        Serial.println(humidity);
        #endif
      } else {
        // Increase no update counter if the humidity stayed the same
        nNoUpdatesHum++;
      }
    
      // Sleep for a while to save energy
      sleep(UPDATE_INTERVAL); 
    }
    
    


  • Arduino Uno [Gateway] sketch.

    /**
    * 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.
    *
    *******************************
    *
    * DESCRIPTION
    * The ArduinoGateway prints data received from sensors on the serial link.
    * The gateway accepts input on seral which will be sent out on radio network.
    *
    * The GW code is designed for Arduino Nano 328p / 16MHz
    *
    * Wire connections (OPTIONAL):
    * - Inclusion button should be connected between digital pin 3 and GND
    * - RX/TX/ERR leds need to be connected between +5V (anode) and digital pin 6/5/4 with resistor 270-330R in a series
    *
    * LEDs (OPTIONAL):
    * - To use the feature, uncomment any of the MY_DEFAULT_xx_LED_PINs
    * - RX (green) - blink fast on radio message recieved. In inclusion mode will blink fast only on presentation recieved
    * - TX (yellow) - blink fast on radio message transmitted. In inclusion mode will blink slowly
    * - ERR (red) - fast blink on error during transmission error or recieve crc error
    *
    */
    
    // Enable debug prints to serial monitor
    #define MY_DEBUG
    
    
    // Enable and select radio type attached
    #define MY_RADIO_NRF24
    //#define MY_RADIO_RFM69
    
    // Set LOW transmit power level as default, if you have an amplified NRF-module and
    // power your radio separately with a good regulator you can turn up PA level.
    #define MY_RF24_PA_LEVEL RF24_PA_LOW
    
    // Enable serial gateway
    #define MY_GATEWAY_SERIAL
    
    // Define a lower baud rate for Arduino's running on 8 MHz (Arduino Pro Mini 3.3V & SenseBender)
    #if F_CPU == 8000000L
    #define MY_BAUD_RATE 38400
    #endif
    
    // Enable inclusion mode
    #define MY_INCLUSION_MODE_FEATURE
    // Enable Inclusion mode button on gateway
    //#define MY_INCLUSION_BUTTON_FEATURE
    
    // Inverses behavior of inclusion button (if using external pullup)
    //#define MY_INCLUSION_BUTTON_EXTERNAL_PULLUP
    
    // Set inclusion mode duration (in seconds)
    #define MY_INCLUSION_MODE_DURATION 60
    // Digital pin used for inclusion mode button
    //#define MY_INCLUSION_MODE_BUTTON_PIN  3
    
    // Set blinking period
    #define MY_DEFAULT_LED_BLINK_PERIOD 300
    
    // Inverses the behavior of leds
    //#define MY_WITH_LEDS_BLINKING_INVERSE
    
    // Flash leds on rx/tx/err
    // Uncomment to override default HW configurations
    //#define MY_DEFAULT_ERR_LED_PIN 4  // Error led pin
    //#define MY_DEFAULT_RX_LED_PIN  6  // Receive led pin
    //#define MY_DEFAULT_TX_LED_PIN  5  // the PCB, on board LED
    
    #include <MySensors.h>
    
    void setup()
    {
    	// Setup locally attached sensors
    }
    
    void presentation()
    {
    	// Present locally attached sensors
    }
    
    void loop()
    {
    	// Send locally attached sensor data here
    }
    
    


  • Mysensors.org Jeedom Plugin status.

    [2017-05-26 23:23:06][INFO] : Arrêt du service mySensors
    [2017-05-26 23:23:07][INFO] : Arrêt du service mySensors
    [2017-05-26 23:23:07][INFO] : Lancement du démon mySensors : Gateway /dev/ttyAMA0
    [2017-05-26 23:23:07][DEBUG] : Lancement démon mySensors : nice -n 19 nodejs /var/www/html/plugins/mySensors/node/mysensors.js http://192.XXX.XXX.XXX:80/plugins/mySensors/core/api/jeeSensors.php?apikey=XXXXXXXXXXXXXXXXXXXXXX master /dev/ttyAMA0 serial debug
    [2017-05-26 23:23:07][INFO] : Démon mySensors lancé
    
    

    Mysensors.org Jeedom plugin node server log.

    Fri May 26 2017 23:23:08 GMT+0200 (CEST) - Jeedom url : http://192.168.0.38:80/plugins/mySensors/core/api/jeeSensors.php?apikey=tdI13Ma1kRL4TGXyeuU9NIcgZU9CeHsOmGEseNYmAph5MdE3&gateway=master, gwAddress : /dev/ttyAMA0
    DEPRECATION: Please use `require('serialport')` instead of `require('serialport').SerialPort`
    Fri May 26 2017 23:23:08 GMT+0200 (CEST) - server bound on 8019
    Fri May 26 2017 23:23:08 GMT+0200 (CEST) - connected to serial gateway at /dev/ttyAMA0
    Fri May 26 2017 23:23:08 GMT+0200 (CEST) : http://192.XXX.XXX.XXX:80/plugins/mySensors/core/api/jeeSensors.php?apikey=XXXXXXXXXXXXXXXXXXXXXX&gateway=master&messagetype=saveGateway&sender=0&sensor=0&type=0&payload=1
    
    

    Arduino pro mini serial monitoring.
    Message below explain that NRF24 module doesn't work properly, due to VCC voltage issue or wiring issue (in my case that was vcc voltage issue)

    45210327 TSM:FAIL:RE-INIT
    45210333 TSM:INIT
    45210343 !TSM:INIT:TSP FAIL
    45210351 TSM:FAIL:CNT=7
    45210359 TSM:FAIL:PDT
    
    

    Arduino Uno [Gateway] serial monitoring.

    ;2550;255;3;0;9;MCO:BGN:INIT GW,CP=RNNGA--,VER=2.1.1
    0;255;3;0;9;TSM:INIT
    0;255;3;0;9;TSF:WUR:MS=0
    0;255;3;0;9;TSM:INIT:TSP OK
    0;255;3;0;9;TSM:INIT:GW MODE
    0;255;3;0;9;TSM:READY:ID=0,PAR=0,DIS=0
    0;255;3;0;9;MCO:REG:NOT NEEDED
    0;255;3;0;14;Gateway startup complete.
    0;255;0;0;18;2.1.1
    0;255;3;0;9;MCO:BGN:STP
    0;255;3;0;9;MCO:BGN:INIT OK,TSP=1
    
    

  • Hardware Contributor

    Hi,

    could you give us more info about your arduino pro mini node (how it is powered etc)? or a pic?
    Looks like you may have a bad radio wiring..
    Also, have you added a capacitor for nrf?
    https://www.mysensors.org/build/connect_radio
    This should work out of the box.



  • @scalz My Arduino pro mino is currently powered through USB-TTL with 3.3v as it is a 3.3v arduino pro mini.

    I though it was a wiring issue but i re-wired it several time looking at the tutorial to connect radio and i had no chance to work.

    I didn't put yet capacitor.



  • @scalz I have added capacitor on both nrf24 the one on the Arduino Uno [SerialGateway] and the one on Arduino pro mini.

    I still have the same messages on the Arduino pro mini..



  • I removed the DHT11 from the Arduino pro mini and it seems to work.

    I guess it is due to parallal plug on VCC for DHT11 and NRF24.

    Arduino pro mini:

    4468 MCO:SLP:WUP=-1
    Failed reading temperature from DHT!
    Failed reading humidity from DHT
    4493 MCO:SLP:MS=60000,SMS=0,I1=255,M1=255,I2=255,M2=255
    4526 MCO:SLP:TPD
    4530 MCO:SLP:WUP=-1
    Failed reading temperature from DHT!
    Failed reading humidity from DHT
    4556 MCO:SLP:MS=60000,SMS=0,I1=255,M1=255,I2=255,M2=255
    4587 MCO:SLP:TPD
    4591 MCO:SLP:WUP=-1
    Failed reading temperature from DHT!
    Failed reading humidity from DHT
    4618 MCO:SLP:MS=60000,SMS=0,I1=255,M1=255,I2=255,M2=255
    4648 MCO:SLP:TPD
    
    
    

    Arduino Uno [SerialGateway]:

    
    0;255;3;0;9;TSF:MSG:SEND,0-0-2-2,s=255,c=3,t=15,pt=6,l=2,sg=0,ft=0,st=OK:0100
    0;255;3;0;9;TSF:MSG:READ,2-2-0,s=255,c=0,t=17,pt=0,l=5,sg=0:2.1.1
    2;255;0;0;17;2.1.1
    0;255;3;0;9;TSF:MSG:READ,2-2-0,s=255,c=3,t=6,pt=1,l=1,sg=0:0
    2;255;3;0;6;0
    0;255;3;0;9;TSF:MSG:READ,2-2-0,s=255,c=3,t=11,pt=0,l=22,sg=0:TemperatureAndHumidity
    2;255;3;0;11;TemperatureAndHumidity
    0;255;3;0;9;TSF:MSG:READ,2-2-0,s=255,c=3,t=12,pt=0,l=3,sg=0:1.1
    2;255;3;0;12;1.1
    0;255;3;0;9;TSF:MSG:READ,2-2-0,s=0,c=0,t=7,pt=0,l=0,sg=0:
    2;0;0;0;7;
    0;255;3;0;9;TSF:MSG:READ,2-2-0,s=1,c=0,t=6,pt=0,l=0,sg=0:
    2;1;0;0;6;
    0;255;3;0;9;TSF:MSG:READ,2-2-0,s=255,c=3,t=26,pt=1,l=1,sg=0:2
    0;255;3;0;9;TSF:MSG:SEND,0-0-2-2,s=255,c=3,t=27,pt=1,l=1,sg=0,ft=0,st=OK:1
    0;255;3;0;5;1
    0;255;3;0;9;TSM:READY:NWD REQ
    0;255;3;0;9;TSF:MSG:SEND,0-0-255-255,s=255,c=3,t=20,pt=0,l=0,sg=0,ft=0,st=OK:
    0;255;3;0;5;0
    
    
    


  • I successed to include the arduino micro in Mysensors plugin of Jeedom.

    Now everything work.

    I plugged the DHT11 vcc on FTDI Header vcc pin.

    I plugged the USB ttl vcc on raw pin.

    And now everything work fine.
    arduino pro micro pin


Log in to reply
 

Suggested Topics

  • 8
  • 7
  • 1
  • 5
  • 2
  • 3

0
Online

11.4k
Users

11.1k
Topics

112.7k
Posts