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
M

mrhutchinsonmn

@mrhutchinsonmn
About
Posts
99
Topics
32
Shares
0
Groups
0
Followers
0
Following
0

Posts

Recent Best Controversial

  • Relay device not showing up in HA but does in .json
    M mrhutchinsonmn

    @cabat Thank you! Apparently, the MySensors sketch supplied in the Build section is not written to work with HA. I did take a stab at it and pop some code in the loop section, and the sensor now shows up but is not functional. I will have to dig more and determine what should be added to the sketch for it to work.

    Thanks much for the pointer.

    Home Assistant

  • Relay device not showing up in HA but does in .json
    M mrhutchinsonmn

    I have the following relay device that shows up in the .json file of HA, but will not appear on the dashboard as an available device. Guessing it doesn't like something about the sketch, but not sure what that might be.

    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-2019 Sensnology AB
     * Full contributor list: https://github.com/mysensors/MySensors/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
     *
     * DESCRIPTION
     * Example sketch showing how to control physical relays.
     * This example will remember relay state after power failure.
     * http://www.mysensors.org/build/relay
     */
    
    // Enable debug prints to serial monitor
    #define MY_DEBUG
    
    // Enable and select radio type attached
    #define MY_RADIO_RF24
    //#define MY_RADIO_NRF5_ESB
    //#define MY_RADIO_RFM69
    //#define MY_RADIO_RFM95
    
    // Enable repeater functionality for this node
    #define MY_REPEATER_FEATURE
    #define MY_NODE_ID 100
    #include <MySensors.h>
    
    #define RELAY_PIN 2  // Arduino Digital I/O pin number for first relay (second on pin+1 etc)
    #define NUMBER_OF_RELAYS 1 // Total number of attached relays
    #define RELAY_ON 1  // GPIO value to write to turn on attached relay
    #define RELAY_OFF 0 // GPIO value to write to turn off attached relay
    
    
    void before()
    {
      for (int sensor=1, pin=RELAY_PIN; sensor<=NUMBER_OF_RELAYS; sensor++, pin++) {
        // Then set relay pins in output mode
        pinMode(pin, OUTPUT);
        // Set relay to last known state (using eeprom storage)
        digitalWrite(pin, loadState(sensor)?RELAY_ON:RELAY_OFF);
      }
    }
    
    void setup()
    {
    
    }
    
    void presentation()
    {
      // Send the sketch version information to the gateway and Controller
      sendSketchInfo("Relay", "1.0");
    
      for (int sensor=1, pin=RELAY_PIN; sensor<=NUMBER_OF_RELAYS; sensor++, pin++) {
        // Register all sensors to gw (they will be created as child devices)
        present(sensor, S_BINARY);
      }
    }
    
    
    void loop()
    {
    
    }
    
    void receive(const MyMessage &message)
    {
      // We only expect one type of message from controller. But we better check anyway.
      if (message.getType()==V_STATUS) {
        // Change relay state
        digitalWrite(message.getSensor()-1+RELAY_PIN, message.getBool()?RELAY_ON:RELAY_OFF);
        // Store state in eeprom
        saveState(message.getSensor(), message.getBool());
        // Write some debug info
        Serial.print("Incoming change for sensor:");
        Serial.print(message.getSensor());
        Serial.print(", New status: ");
        Serial.println(message.getBool());
      }
    }
    

    .json file:

    {
        "0": {
            "sensor_id": 0,
            "children": {},
            "type": 18,
            "sketch_name": null,
            "sketch_version": null,
            "battery_level": 0,
            "protocol_version": "2.3.2",
            "heartbeat": 0
        },
        "100": {
            "sensor_id": 100,
            "children": {
                "1": {
                    "id": 1,
                    "type": 3,
                    "description": "",
                    "values": {}
                }
            },
            "type": 18,
            "sketch_name": "Relay",
            "sketch_version": "1.0",
            "battery_level": 0,
            "protocol_version": "2.3.2",
            "heartbeat": 0
        }
    
    Home Assistant

  • make erring out on raspberry pi 2 b
    M mrhutchinsonmn

    I am attempting to set up homeassistant with a mysensors ethernet gateway on the same raspberry pi 2 b. However, make is erring out. Do I need an older mysensors library?

    [SECTION] Detecting target machine.
      [OK] machine detected: SoC=BCM2835, Type=rpi1, CPU=armv7l.
    [SECTION] Detecting SPI driver.
      [OK] SPI driver detected:BCM.
    [SECTION] Gateway configuration.
      [OK] Type: ethernet.
      [OK] Transport: rf24.
      [OK] Signing: Disabled.
      [OK] Encryption: Disabled.
      [OK] CPPFLAGS: -march=armv6zk -mtune=arm1176jzf-s -mfpu=vfp -mfloat-abi=hard -DMY_RADIO_RF24 -DMY_GATEWAY_LINUX -DMY_DEBUG -DLINUX_SPI_BCM -DLINUX_ARCH_RASPBERRYPI -DMY_PORT=5003 
      [OK] CXXFLAGS:  -std=c++11
    [SECTION] Detecting init system.
      [OK] Init system detected: systemd.
    [SECTION] Saving configuration.
      [OK] Saved.
    [SECTION] Cleaning previous builds.
      [OK] Finished.
    root@rpi2-20230102:~/MySensors# ^C
    
    
    root@rpi2-20230102:~/MySensors# ^C
    root@rpi2-20230102:~/MySensors# make
    gcc -MT build/hal/architecture/Linux/drivers/core/config.o -MMD -MP -march=armv6zk -mtune=arm1176jzf-s -mfpu=vfp -mfloat-abi=hard -DMY_RADIO_RF24 -DMY_GATEWAY_LINUX -DMY_DEBUG -DLINUX_SPI_BCM -DLINUX_ARCH_RASPBERRYPI -DMY_PORT=5003  -Ofast -g -Wall -Wextra  -I. -I./core -I./hal/architecture/Linux/drivers/core -I./hal/architecture/Linux/drivers/BCM -c hal/architecture/Linux/drivers/core/config.c -o build/hal/architecture/Linux/drivers/core/config.o
    In file included from /usr/include/stdio.h:864,
                     from hal/architecture/Linux/drivers/core/config.c:23:
    /usr/include/arm-linux-gnueabihf/bits/stdio.h: In function 'vprintf':
    /usr/include/arm-linux-gnueabihf/bits/stdio.h:40:1: sorry, unimplemented: Thumb-1 hard-float VFP ABI
       40 | {
          | ^
    make: *** [Makefile:103: build/hal/architecture/Linux/drivers/core/config.o] Error 1
    
    General Discussion

  • Possible to have an external power source for moisture sensors??
    M mrhutchinsonmn

    @mfalkvidd I was looking at it through the perspective of my 8 channel relay which needs an external power source to work reliably. Seems 6 moisture sensors will work fine.

    General Discussion

  • Possible to have an external power source for moisture sensors??
    M mrhutchinsonmn

    @mrhutchinsonmn Did some more research. It seems it is possible to run all 6 sensors on a single board without a 2nd power source since readings are not taken simultaneously. Is that a correct assertation?

    General Discussion

  • Possible to have an external power source for moisture sensors??
    M mrhutchinsonmn

    I want to run 6 analog moisture sensors on a single arduino nano(if possible). I am guessing that may cause erratic behavior from power issues. Is there a way to use an external power source and still provide a connection to the nano, like is done with a jd-vcc pin on my 8 channel relay, so the sensor will work correctly?

    General Discussion

  • Contributions
    M mrhutchinsonmn

    Is there a way to contribute to mysensors tutorials, example sketches, etc? In my experience, I have found some tutorials to be limited, vague, or missing information that would be helpful to a novice, such as myself. For example: currently, I am learning RS485 and have a working moisture sensor sketch I would like to contribute that may be helpful to someone else. Is there a corner for such contributions?

    General Discussion

  • Motion Sensor not presenting to RS485 Gateway / TSM:FPAR:NO REPLY
    M mrhutchinsonmn

    @electrik Yes... that worked!!! Moved node and child id above mysensors.h

    Thank you!!!!

    Home Assistant

  • Motion Sensor not presenting to RS485 Gateway / TSM:FPAR:NO REPLY
    M mrhutchinsonmn

    @rejoe2 In research, some stated it needed to be there if the sensor did not present itself. Followed @electrik advice and it now works. Thank you for your feedback!

    Home Assistant

  • Motion Sensor not presenting to RS485 Gateway / TSM:FPAR:NO REPLY
    M mrhutchinsonmn

    Thank you for the advice!

    I started over, just to be sure I didn't have anymore mix ups, but still have not been able to get the RS485 motion sensor and RS485 gateway to talk.

    Hardware: Arduino Nanos+ RS485 modules.

    Wiring:
    RO = Pin 8 of Arduino
    DI = Pin 9 of Arduino
    A = A on other Nano
    B = B on other Nano
    DI= Pin 9 of Nano
    RO = Pin 8 of Nano
    DE & RE = Pin 2 of Nano
    VCC = External power source
    GND = External power source

    Current 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-2019 Sensnology AB
    * Full contributor list: https://github.com/mysensors/MySensors/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 RS485 Gateway prints data received from sensors on the serial link.
    * The gateway accepts input on seral which will be sent out on
    * the RS485 link.
    *
    * 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):
    * - RX (green) - blink fast on radio message received. In inclusion mode will blink fast only on presentation received
    * - TX (yellow) - blink fast on radio message transmitted. In inclusion mode will blink slowly
    * - ERR (red) - fast blink on error during transmission error or receive crc error
    *
    * If your Arduino board has additional serial ports
    * you can use to connect the RS485 module.
    * Otherwise, the gateway uses AltSoftSerial to handle two serial
    * links on one Arduino. Use the following pins for RS485 link
    *
    *  Board          Transmit  Receive   PWM Unusable
    * -----          --------  -------   ------------
    * Teensy 3.0 & 3.1  21        20         22
    * Teensy 2.0         9        10       (none)
    * Teensy++ 2.0      25         4       26, 27
    * Arduino Uno        9         8         10
    * Arduino Leonardo   5        13       (none)
    * Arduino Mega      46        48       44, 45
    * Wiring-S           5         6          4
    * Sanguino          13        14         12
    *
    */
    
    // Enable debug prints to serial monitor
    #define MY_DEBUG
    
    // Enable RS485 transport layer
    #define MY_RS485
    
    // Define this to enables DE-pin management on defined pin
    #define MY_RS485_DE_PIN 2
    
    // Set RS485 baud rate to use
    #define MY_RS485_BAUD_RATE 9600
    
    // Enable this if RS485 is connected to a hardware serial port
    //#define MY_RS485_HWSERIAL Serial
    
    // Enable serial gateway
    #define MY_GATEWAY_SERIAL
    
    
    // Enable inclusion mode
    #define MY_INCLUSION_MODE_FEATURE
    // Enable Inclusion mode button on gateway
    #define MY_INCLUSION_BUTTON_FEATURE
    // 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
    
    // Flash leds on rx/tx/err
    #define MY_DEFAULT_ERR_LED_PIN 4  // Error led pin
    #define MY_DEFAULT_RX_LED_PIN  5  // Receive led pin
    #define MY_DEFAULT_TX_LED_PIN  6  // 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
    }
    
    

    Current Motion Detector 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-2019 Sensnology AB
     * Full contributor list: https://github.com/mysensors/MySensors/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
     *
     * DESCRIPTION
     * This is an example of sensors using RS485 as transport layer
     *
     * Motion Sensor example using HC-SR501
     * http://www.mysensors.org/build/motion
     *
     * If your Arduino board has additional serial ports
     * you can use to connect the RS485 module.
     * Otherwise, the transport uses AltSoftSerial to handle two serial
     * links on one Arduino. Use the following pins for RS485 link
     *
     *  Board          Transmit  Receive   PWM Unusable
     * -----          --------  -------   ------------
     * Teensy 3.0 & 3.1  21        20         22
     * Teensy 2.0         9        10       (none)
     * Teensy++ 2.0      25         4       26, 27
     * Arduino Uno        9         8         10
     * Arduino Leonardo   5        13       (none)
     * Arduino Mega      46        48       44, 45
     * Wiring-S           5         6          4
     * Sanguino          13        14         12 *
     *
     */
    
    // Enable debug prints to serial monitor
    #define MY_DEBUG
    
    // Enable RS485 transport layer
    #define MY_RS485
    
    // Define this to enables DE-pin management on defined pin
    #define MY_RS485_DE_PIN 2
    
    // Set RS485 baud rate to use
    #define MY_RS485_BAUD_RATE 9600
    
    // Enable this if RS485 is connected to a hardware serial port
    //#define MY_RS485_HWSERIAL Serial1
    
    #include <MySensors.h>
    
    uint32_t SLEEP_TIME = 120000; // Sleep time between reports (in milliseconds)
    #define DIGITAL_INPUT_SENSOR 3   // The digital input you attached your motion sensor.  (Only 2 and 3 generates interrupt!)
    #define MY_NODE_ID 12
    #define CHILD_ID 1   // Id of the sensor child
    
    // Initialize motion message
    MyMessage msg(CHILD_ID, V_TRIPPED);
    
    void setup()
    {
      pinMode(DIGITAL_INPUT_SENSOR, INPUT);      // sets the motion sensor digital pin as input
    }
    
    void presentation()
    {
      // Send the sketch version information to the gateway and Controller
      sendSketchInfo("Motion Sensor", "1.0");
    
      // Register all sensors to gw (they will be created as child devices)
      present(CHILD_ID, S_MOTION);
    }
    
    void loop()
    {
      // Read digital motion value
      bool tripped = digitalRead(DIGITAL_INPUT_SENSOR) == HIGH;
    
      Serial.println(tripped);
      send(msg.set(tripped?"1":"0"));  // Send tripped value to gw
    
      // Sleep until interrupt comes in on motion sensor. Send update every two minute.
      sleep(digitalPinToInterrupt(DIGITAL_INPUT_SENSOR), CHANGE, SLEEP_TIME);
    }
    

    Commented the following out on the gateway, as per other forum users recommendations ( but made no difference)

    // Enable inclusion mode
    //#define MY_INCLUSION_MODE_FEATURE
    // Enable Inclusion mode button on gateway
    //#define MY_INCLUSION_BUTTON_FEATURE
    // 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
    

    Serial Monitor info:

    21257 TSM:FAIL:CNT=7
    321259 TSM:FAIL:DIS
    321261 TSF:TDI:TSL
    381263 TSM:FAIL:RE-INIT
    381265 TSM:INIT
    381266 TSM:INIT:TSP OK
    381268 TSM:FPAR
    381287 ?TSF:MSG:SEND,255-255-255-255,s=255,c=3,t=7,pt=0,l=0,sg=0,ft=0,st=OK:
    383295 !TSM:FPAR:NO REPLY
    383297 TSM:FPAR
    383315 ?TSF:MSG:SEND,255-255-255-255,s=255,c=3,t=7,pt=0,l=0,sg=0,ft=0,st=OK:
    385324 !TSM:FPAR:NO REPLY
    385326 TSM:FPAR
    385344 ?TSF:MSG:SEND,255-255-255-255,s=255,c=3,t=7,pt=0,l=0,sg=0,ft=0,st=OK:
    387352 !TSM:FPAR:NO REPLY
    387354 TSM:FPAR
    387373 ?TSF:MSG:SEND,255-255-255-255,s=255,c=3,t=7,pt=0,l=0,sg=0,ft=0,st=OK:
    389381 !TSM:FPAR:FAIL
    

    Ideas?

    Home Assistant

  • Motion Sensor not presenting to RS485 Gateway / TSM:FPAR:NO REPLY
    M mrhutchinsonmn

    @mfalkvidd Ugh!!! Too many versions of the sketch :)... Had to switch between my laptop and pc because of sketch upload issues.... Must have grabbed an old sketch.. I HAD commented hwserial out earlier... Getting communication now but not a valid message, not enough values to unpack errors. I will dig into that tomorrow. Thank you!!!

    Home Assistant

  • Motion Sensor not presenting to RS485 Gateway / TSM:FPAR:NO REPLY
    M mrhutchinsonmn

    @mrhutchinsonmn Might have confused the issue with my reply.. Neither 115200 nor 9600 baud rates resolve the communication issue.

    Home Assistant

  • Motion Sensor not presenting to RS485 Gateway / TSM:FPAR:NO REPLY
    M mrhutchinsonmn

    @mrhutchinsonmn said in Motion Sensor not presenting to RS485 Gateway / TSM:FPAR:NO REPLY:

    9600

    Good catch.. That was an old version... both are set to 115200 after 9600 did not work

    Home Assistant

  • Motion Sensor not presenting to RS485 Gateway / TSM:FPAR:NO REPLY
    M mrhutchinsonmn

    Hardware: Arduino nano boards+ RS485 devices with separate 5 volt power supply

    I am trying to set up my 1st Rs485 gateway motion sensor on Home Assistant, per the following tutorial:
    https://www.mysensors.org/build/rs485

    The motion sensor is not presenting itself to the gateway, so I did some digging and found this thread on the subject:

    https://forum.mysensors.org/topic/11048/mqtt-ethernet-gateway-with-wired-rs485-network.

    I have things wired up as per this pic provided in the tutorial

    Although I am not using mqtt, everything seemed to be pertinent but I was still unable to get communication between the sensor and gateway.

    Ha logs show the gateway seems to be happy:

    [mysensors] Connected to Serial<id=0x7f2fd0c2f518, open=True>(port='/dev/ttyUSB0', baudrate=115200, bytesize=8, parity='N', stopbits=1, timeout=0, xonxoff=False, rtscts=False, dsrdtr=False)
    2020-10-05 13:17:05 INFO (MainThread) [mysensors] Connected to <_SelectorSocketTransport fd=25 read=idle write=<idle, bufsize=0>>
    p:Gateway startup complete.
    

    However serial monitor for the motion sensor shows the following:

    
    |  \/  |_   _/ ___|  ___ _ __  ___  ___  _ __ ___
    | |\/| | | | \___ \ / _ \ `_ \/ __|/ _ \| `__/ __|
    | |  | | |_| |___| |  __/ | | \__ \  _  | |  \__ \
    |_|  |_|\__, |____/ \___|_| |_|___/\___/|_|  |___/
            |___/                      2.3.2
    
    16 MCO:BGN:INIT NODE,CP=RSNNA---,FQ=16,REL=255,VER=2.3.2
    26 TSM:INIT
    28 TSF:WUR:MS=0
    29 TSM:INIT:TSP OK
    31 TSM:FPAR
    33 ?TSF:MSG:SEND,255-255-255-255,s=255,c=3,t=7,pt=0,l=0,sg=0,ft=0,st=OK:
    2041 !TSM:FPAR:NO REPLY
    2043 TSM:FPAR
    2045 ?TSF:MSG:SEND,255-255-255-255,s=255,c=3,t=7,pt=0,l=0,sg=0,ft=0,st=OK:
    4054 !TSM:FPAR:NO REPLY
    4056 TSM:FPAR
    4058 ?TSF:MSG:SEND,255-255-255-255,s=255,c=3,t=7,pt=0,l=0,sg=0,ft=0,st=OK:
    6066 !TSM:FPAR:NO REPLY
    6068 TSM:FPAR
    6070 ?TSF:MSG:SEND,255-255-255-255,s=255,c=3,t=7,pt=0,l=0,sg=0,ft=0,st=OK:
    8078 !TSM:FPAR:FAIL
    8079 TSM:FAIL:CNT=1
    8081 TSM:FAIL:DIS
    8083 TSF:TDI:TSL
    18085 TSM:FAIL:RE-INIT
    18087 TSM:INIT
    18088 TSM:INIT:TSP OK
    

    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-2019 Sensnology AB
    * Full contributor list: https://github.com/mysensors/MySensors/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 RS485 Gateway prints data received from sensors on the serial link.
    * The gateway accepts input on seral which will be sent out on
    * the RS485 link.
    *
    * 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):
    * - RX (green) - blink fast on radio message received. In inclusion mode will blink fast only on presentation received
    * - TX (yellow) - blink fast on radio message transmitted. In inclusion mode will blink slowly
    * - ERR (red) - fast blink on error during transmission error or receive crc error
    *
    * If your Arduino board has additional serial ports
    * you can use to connect the RS485 module.
    * Otherwise, the gateway uses AltSoftSerial to handle two serial
    * links on one Arduino. Use the following pins for RS485 link
    *
    *  Board          Transmit  Receive   PWM Unusable
    * -----          --------  -------   ------------
    * Teensy 3.0 & 3.1  21        20         22
    * Teensy 2.0         9        10       (none)
    * Teensy++ 2.0      25         4       26, 27
    * Arduino Uno        9         8         10
    * Arduino Leonardo   5        13       (none)
    * Arduino Mega      46        48       44, 45
    * Wiring-S           5         6          4
    * Sanguino          13        14         12
    *
    */
    
    // Enable debug prints to serial monitor
    #define MY_DEBUG
    
    // Enable RS485 transport layer
    #define MY_RS485
    
    // Define this to enables DE-pin management on defined pin
    #define MY_RS485_DE_PIN 2
    
    // Set RS485 baud rate to use
    #define MY_RS485_BAUD_RATE 115200
    
    // Enable this if RS485 is connected to a hardware serial port
    #define MY_RS485_HWSERIAL Serial
    
    // Enable serial gateway
    #define MY_GATEWAY_SERIAL
    
    
    // Enable inclusion mode
    //#define MY_INCLUSION_MODE_FEATURE
    // Enable Inclusion mode button on gateway
    //#define MY_INCLUSION_BUTTON_FEATURE
    // 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
    
    // Flash leds on rx/tx/err
    #define MY_DEFAULT_ERR_LED_PIN 4  // Error led pin
    #define MY_DEFAULT_RX_LED_PIN  5  // Receive led pin
    #define MY_DEFAULT_TX_LED_PIN  6  // 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
    }
    
    

    Motion detector 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-2019 Sensnology AB
     * Full contributor list: https://github.com/mysensors/MySensors/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
     *
     * DESCRIPTION
     * This is an example of sensors using RS485 as transport layer
     *
     * Motion Sensor example using HC-SR501
     * http://www.mysensors.org/build/motion
     *
     * If your Arduino board has additional serial ports
     * you can use to connect the RS485 module.
     * Otherwise, the transport uses AltSoftSerial to handle two serial
     * links on one Arduino. Use the following pins for RS485 link
     *
     *  Board          Transmit  Receive   PWM Unusable
     * -----          --------  -------   ------------
     * Teensy 3.0 & 3.1  21        20         22
     * Teensy 2.0         9        10       (none)
     * Teensy++ 2.0      25         4       26, 27
     * Arduino Uno        9         8         10
     * Arduino Leonardo   5        13       (none)
     * Arduino Mega      46        48       44, 45
     * Wiring-S           5         6          4
     * Sanguino          13        14         12 *
     *
     */
    
    // Enable debug prints to serial monitor
    #define MY_DEBUG
    
    // Enable RS485 transport layer
    #define MY_RS485
    
    // Define this to enables DE-pin management on defined pin
    #define MY_RS485_DE_PIN 2
    
    // Set RS485 baud rate to use
    #define MY_RS485_BAUD_RATE 115200
    
    // Enable this if RS485 is connected to a hardware serial port
    //#define MY_RS485_HWSERIAL Serial
    
    #include <MySensors.h>
    
    uint32_t SLEEP_TIME = 120000; // Sleep time between reports (in milliseconds)
    #define DIGITAL_INPUT_SENSOR 3   // The digital input you attached your motion sensor.  (Only 2 and 3 generates interrupt!)
    #define MY_NODE_ID 123
    #define CHILD_ID 1   // Id of the sensor child
    
    // Initialize motion message
    MyMessage msg(CHILD_ID, V_TRIPPED);
    
    void setup()
    {
      pinMode(DIGITAL_INPUT_SENSOR, INPUT);      // sets the motion sensor digital pin as input
    }
    
    void presentation()
    {
      // Send the sketch version information to the gateway and Controller
      sendSketchInfo("Motion Sensor", "1.0");
    
      // Register all sensors to gw (they will be created as child devices)
      present(CHILD_ID, S_MOTION);
    }
    
    void loop()
    {
      // Read digital motion value
      bool tripped = digitalRead(DIGITAL_INPUT_SENSOR) == HIGH;
    
      Serial.println(tripped);
      send(msg.set(tripped?"1":"0"));  // Send tripped value to gw
    
      // Sleep until interrupt comes in on motion sensor. Send update every two minute.
      sleep(digitalPinToInterrupt(DIGITAL_INPUT_SENSOR), CHANGE, SLEEP_TIME);
    }
    
    
    

    To rule out hardware failure, I followed this tutorial, and all works as expected:
    https://naylampmechatronics.com/blog/37_Comunicación-RS485-con-Arduino.html

    Transmitter sketch:

    const int ledPin =  13;  // Built-in LED
    const int EnTxPin =  2;  // HIGH:Transmitter, LOW:Receiver
    void setup() 
    { 
      Serial.begin(9600);
      Serial.setTimeout(100);  
      pinMode(ledPin, OUTPUT);
      pinMode(EnTxPin, OUTPUT);
      digitalWrite(ledPin, LOW); 
      digitalWrite(EnTxPin, HIGH); 
    } 
     
    void loop() 
    {   
      int rdata = analogRead(0); //data from potentiometer 
      int angle= map(rdata, 0, 1023, 0, 180); 
      
      //transmitter data packet
      Serial.print("I"); //initiate data packet
      Serial.print("S"); //code for servo
      Serial.print(angle); //servo angle data
      Serial.print("F"); //finish data packet
      delay(50); 
    
      //receiver data packet
      Serial.print("I"); //initiate data packet
      Serial.print("L"); //code for sensor
      Serial.print("F"); //finish data packet
      Serial.flush();    
      
      digitalWrite(EnTxPin, LOW); //RS485 as receiver
    
      if(Serial.find("i"))
      {
          int data=Serial.parseInt(); 
          if(Serial.read()=='f') //finish reading
           {
             onLED(data);            
          }
          
      }
      digitalWrite(EnTxPin, HIGH); //RS485 as transmitter
      
    } 
    
    void onLED(int data)
    {
      if(data>500)
         digitalWrite(ledPin, HIGH); 
      else
         digitalWrite(ledPin, LOW); 
    }
    

    Reciever sketch:

    #include <Servo.h>
    Servo myservo; 
    const int EnTxPin = 2;
    void setup () {
      Serial.begin (9600);
      myservo.attach (9); 
      pinMode(EnTxPin, OUTPUT );
      digitalWrite (EnTxPin, LOW );
    }
    
    void loop (){
      if ( Serial.available ()){
        if ( Serial.read () == 'I' ){
          char function = Serial.read ();
          if (function == 'S' ){
            int angle = Serial.parseInt ();
            if ( Serial.read () == 'F' ){
              if (angle <= 180) {
                myservo.write (angle);
              }
            }
          }
          else if (function == 'L' ){
            if ( Serial.read () == 'F' ){
              int val = analogRead (0);
              digitalWrite (EnTxPin, HIGH ); //enable to transmit
              Serial.print ( "i" ); 
              Serial.print (val); 
              Serial.println ( "f" ); 
              Serial.flush (); 
              digitalWrite (EnTxPin, LOW ); //enable to receive
            }
          }
        }
      }
      delay (10);
    }
    
    

    Any ideas about what might be causing the issue?

    Home Assistant

  • RS485 & 8 Channel Relay
    M mrhutchinsonmn

    I am considering moving away from using nrf24l01 for my garden automation system and implementing an RS485 solution instead. However, I am not clear if I can run my 8 channel relay via a single RS485 module as I currently do with nrf24l01, or if each channel needs a single RS485 module. (have not worked with RS485 yet)..

    General Discussion

  • Help modifying sketch for rf-nano
    M mrhutchinsonmn

    That worked for me. Thank you!

    General Discussion

  • Help modifying sketch for rf-nano
    M mrhutchinsonmn

    @Michiel-van-der-Wulp

    The sketch looks like this now but does not work with gateway sketch (below). Is that related to code in the mysensors.h library, or do I need to make a change in the serial gateway sketch?

    /*
      AnalogReadSerial
    
      Reads an analog input on pin 0, prints the result to the Serial Monitor.
      Graphical representation is available using Serial Plotter (Tools > Serial Plotter menu).
      Attach the center pin of a potentiometer to pin A0, and the outside pins to +5V and ground.
    
      This example code is in the public domain.
    
      http://www.arduino.cc/en/Tutorial/AnalogReadSerial
    */
    #define MY_NODE_ID 35
    // Enable debug prints
     #define MY_DEBUG
    // Enable and select radio type attached
    #define MY_RADIO_RF24
    //#define MY_RADIO_NRF5_ESB
    //#define MY_RADIO_RFM69
    //#define MY_RADIO_RFM95
    #define CE_PIN   10
    #define CSN_PIN 9
    #define CHILD_ID_A0 0
    //#define CHILD_ID_A1 1
    //#define CHILD_ID_A2 2
    #include <MySensors.h>
    MyMessage msg(CHILD_ID_A0, V_LEVEL);
    //MyMessage msg2(CHILD_ID_A1, V_LEVEL);
    //MyMessage msg3(CHILD_ID_A2, V_LEVEL);
    // the setup routine runs once when you press reset:
    void setup() {
      // initialize serial communication at 9600 bits per second:
      Serial.begin(9600);
    }
    void presentation()
    {
      sendSketchInfo("Analog Soil Moisture Sensorx3", "1c.0");
      present(CHILD_ID_A0, S_MOISTURE);
     // present(CHILD_ID_A1, S_MOISTURE);
     // present(CHILD_ID_A2, S_MOISTURE);
    }
    // the loop routine runs over and over again forever:
    void loop() {
      // read the input on analog pin 0:
     int sensorValue = analogRead(A0);
     //int sensorValueA1 = analogRead(A1);
     //int sensorValueA2 = analogRead(A2);
      // print out the value you read:
      Serial.println(sensorValue);
      // Serial.println(sensorValueA1);
      //Serial.println(sensorValueA2);
      send(msg.set(sensorValue));
      // send(msg2.set(sensorValueA1));
     // send(msg3.set(sensorValueA2));
      delay(10000);        // delay in between reads for stability
    }
    

    Gateway Sketch:

    /*
      AnalogReadSerial
    
      Reads an analog input on pin 0, prints the result to the Serial Monitor.
      Graphical representation is available using Serial Plotter (Tools > Serial Plotter menu).
      Attach the center pin of a potentiometer to pin A0, and the outside pins to +5V and ground.
    
      This example code is in the public domain.
    
      http://www.arduino.cc/en/Tutorial/AnalogReadSerial
    */
    #define MY_NODE_ID 35
    // Enable debug prints
     #define MY_DEBUG
    // Enable and select radio type attached
    #define MY_RADIO_RF24
    //#define MY_RADIO_NRF5_ESB
    //#define MY_RADIO_RFM69
    //#define MY_RADIO_RFM95
    #define CE_PIN   10
    #define CSN_PIN 9
    #define CHILD_ID_A0 0
    //#define CHILD_ID_A1 1
    //#define CHILD_ID_A2 2
    #include <MySensors.h>
    MyMessage msg(CHILD_ID_A0, V_LEVEL);
    //MyMessage msg2(CHILD_ID_A1, V_LEVEL);
    //MyMessage msg3(CHILD_ID_A2, V_LEVEL);
    // the setup routine runs once when you press reset:
    void setup() {
      // initialize serial communication at 9600 bits per second:
      Serial.begin(9600);
    }
    void presentation()
    {
      sendSketchInfo("Analog Soil Moisture Sensorx3", "1c.0");
      present(CHILD_ID_A0, S_MOISTURE);
     // present(CHILD_ID_A1, S_MOISTURE);
     // present(CHILD_ID_A2, S_MOISTURE);
    }
    // the loop routine runs over and over again forever:
    void loop() {
      // read the input on analog pin 0:
     int sensorValue = analogRead(A0);
     //int sensorValueA1 = analogRead(A1);
     //int sensorValueA2 = analogRead(A2);
      // print out the value you read:
      Serial.println(sensorValue);
      // Serial.println(sensorValueA1);
      //Serial.println(sensorValueA2);
      send(msg.set(sensorValue));
      // send(msg2.set(sensorValueA1));
     // send(msg3.set(sensorValueA2));
      delay(10000);        // delay in between reads for stability
    }
    
    General Discussion

  • Help modifying sketch for rf-nano
    M mrhutchinsonmn

    I have set all my sensors up using a nano and nrf24l01 wireless modules. Just received some rf-nanos I ordered but they are not working with my current sketches. I could use some advice on what to change in my moisture sensor sketch to get it to send data to my gateway. I verified the new rf-nanos work with the following 2 sketches.

    rf-nano send sketch:

    /*
        
       RF Nano Send Example
       
       Hey guys! This example code is designed to send one random 
       integer from one RF Nano to a second RF Nano, to show just how 
       simple the code can be. This code is also compatible with an RF Nano 
       (Arduino Nano with integrated NRF24L01)
    
       - Matt (ACBR 2020)
       
       Pins for Radio
       1 - GND 
       2 - VCC 5v
       3 - CE - Arduino pin 9
       4 - CSN - Arduino pin 10
       5 - SCK - Arduino pin 13
       6 - MOSI - Arduino pin 11
       7 - MISO - Arduino pin 12
       8 - UNUSED
     */
     
    #include <SPI.h>
    #include <nRF24L01.h>
    #include <RF24.h>
    #define CE_PIN   10
    #define CSN_PIN 9
    
    const uint64_t pipe = 0x1; // This is the transmit pipeline
    int sendData[1];  // One element array holding our random number
    
    RF24 radio(CE_PIN, CSN_PIN); // Activate the Radio
    
    void setup()   
    {
      Serial.begin(9600);
      radio.begin();
      radio.openWritingPipe(pipe);
      randomSeed(analogRead(A0));
    }
    
    
    void loop()   
    {
      radio.write( sendData, sizeof(sendData));
      sendData[0] = random(10);
      Serial.println(sendData[0]);
    }
    

    rf-nano receive sketch:

    /* 
      
       RF Nano Receive Example
     
       Hey guys! This example code is designed to send one random integer 
       from one RF Nano to a second RF Nano, to show just how simple the 
       code can be. This code is also compatible with an RF Nano (Arduino 
       Nano with integrated NRF24L01)
    
       - Matt (ACBR 2020)
       
       1 - GND 
       2 - VCC 3.3V 
       3 - CE - Arduino pin 9
       4 - CSN - Arduino pin 10
       5 - SCK - Arduino pin 13
       6 - MOSI - Arduino pin 11
       7 - MISO - Arduino pin 12
       8 - UNUSED 
    */
    
    #include <SPI.h>
    #include <nRF24L01.h>
    #include <RF24.h>
    #define CE_PIN   10
    #define CSN_PIN 9
    
    const uint64_t pipe = 0x1;  // This is the transmit pipe
    int sendData[1];  // One element array holding our random number
    
    RF24 radio(CE_PIN, CSN_PIN);
    
    void setup()  
    {
      Serial.begin(9600); 
      delay(1000);
      Serial.println("Nrf24L01 Receiver Starting");
      radio.begin();
      radio.openReadingPipe(1,pipe);
      radio.startListening();
    }
    
    
    void loop()   
    {
      if ( radio.available() )
      {
        bool done = false;
        while (!done)
        {
          radio.read(sendData, sizeof(sendData));
          Serial.print("Random Number: ");
          Serial.println(sendData[0]);
          delay(50);
        }
      }
      else
      {    
          Serial.println("Darn, not working yet!");
      }
    }
    

    sensor sketch needing modification:

    /*
      AnalogReadSerial
    
      Reads an analog input on pin 0, prints the result to the Serial Monitor.
      Graphical representation is available using Serial Plotter (Tools > Serial Plotter menu).
      Attach the center pin of a potentiometer to pin A0, and the outside pins to +5V and ground.
    
      This example code is in the public domain.
    
      http://www.arduino.cc/en/Tutorial/AnalogReadSerial
    */
    #define MY_NODE_ID 35
    // Enable debug prints
     #define MY_DEBUG
    // Enable and select radio type attached
    #define MY_RADIO_RF24
    //#define MY_RADIO_NRF5_ESB
    //#define MY_RADIO_RFM69
    //#define MY_RADIO_RFM95
    #define CHILD_ID_A0 0
    //#define CHILD_ID_A1 1
    //#define CHILD_ID_A2 2
    #include <MySensors.h>
    #include #include <RF24.h>
    MyMessage msg(CHILD_ID_A0, V_LEVEL);
    //MyMessage msg2(CHILD_ID_A1, V_LEVEL);
    //MyMessage msg3(CHILD_ID_A2, V_LEVEL);
    // the setup routine runs once when you press reset:
    void setup() {
      // initialize serial communication at 9600 bits per second:
      Serial.begin(9600);
    }
    void presentation()
    {
      sendSketchInfo("Analog Soil Moisture Sensorx3", "1c.0");
      present(CHILD_ID_A0, S_MOISTURE);
     // present(CHILD_ID_A1, S_MOISTURE);
     // present(CHILD_ID_A2, S_MOISTURE);
    }
    // the loop routine runs over and over again forever:
    void loop() {
      // read the input on analog pin 0:
     int sensorValue = analogRead(A0);
     //int sensorValueA1 = analogRead(A1);
     //int sensorValueA2 = analogRead(A2);
      // print out the value you read:
      Serial.println(sensorValue);
      // Serial.println(sensorValueA1);
      //Serial.println(sensorValueA2);
      send(msg.set(sensorValue));
      // send(msg2.set(sensorValueA1));
     // send(msg3.set(sensorValueA2));
      delay(10000);        // delay in between reads for stability
    }
    
    General Discussion

  • Looking for esp8266 moisture sensor sketch that works with current libraries
    M mrhutchinsonmn

    @mfalkvidd was part of the sketch. I could see right away that sleep did not work :)

    General Discussion

  • Looking for esp8266 moisture sensor sketch that works with current libraries
    M mrhutchinsonmn

    Fixed it with the following changes: .(Still interested in finding more esp8266 sketches)

    // Enable debug prints to serial monitor
    #define MY_DEBUG
    
    // Use a bit lower baudrate for serial prints on ESP8266 than default in MyConfig.h
    #define MY_BAUD_RATE 9600
    
    // Enables and select radio type (non attached at the moment)
    //#define MY_RADIO_NRF24
    //#define MY_RADIO_RFM69
    
    #define MY_GATEWAY_ESP8266
    
    
    #define MY_WIFI_SSID ""
    #define MY_WIFI_PASSWORD ""
    
    // Enable UDP communication
    //#define MY_USE_UDP  // If using UDP you need to set MY_CONTROLLER_IP_ADDRESS below
    
    // Set the hostname for the WiFi Client. This is the hostname
    // it will pass to the DHCP server if not static.
    #define MY_HOSTNAME "test-sensor-gateway"
    
    // Enable MY_IP_ADDRESS here if you want a static ip address (no DHCP)
    //#define MY_IP_ADDRESS 192,168,178,87
    
    // If using static ip you can define Gateway and Subnet address as well
    //#define MY_IP_GATEWAY_ADDRESS 192,168,178,1
    //#define MY_IP_SUBNET_ADDRESS 255,255,255,0
    
    // The port to keep open on node server mode
    #define MY_PORT 5003
    
    // How many clients should be able to connect to this gateway (default 1)
    #define MY_GATEWAY_MAX_CLIENTS 2
    
    // Controller ip address. Enables client mode (default is "server" mode).
    // Also enable this if MY_USE_UDP is used and you want sensor data sent somewhere.
    //#define MY_CONTROLLER_IP_ADDRESS 192, 168, 178, 68
    
    // Enable inclusion mode
    //#define MY_INCLUSION_MODE_FEATURE
    
    // Enable Inclusion mode button on gateway
    //#define MY_INCLUSION_BUTTON_FEATURE
    // 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
    
    // Flash leds on rx/tx/err
    // Led pins used if blinking feature is enabled above
    //#define MY_DEFAULT_ERR_LED_PIN 16  // Error led pin
    //#define MY_DEFAULT_RX_LED_PIN  16  // Receive led pin
    //#define MY_DEFAULT_TX_LED_PIN  16  // the PCB, on board LED
    
    #if defined(MY_USE_UDP)
    #include <WiFiUdp.h>
    #endif
    
    #include <ESP8266WiFi.h>
    #include <MySensors.h>
    
    #define CHILD_ID 0
    
    int AirValue = 694;
    int WaterValue = 344;
    int intervals = (AirValue - WaterValue)/3; 
    int soilMoistureValue = 0;
    
    MyMessage msg(CHILD_ID, V_LEVEL);
    unsigned long SLEEP_TIME = 30000;
    int sensorPin = A0;
      
    void setup()
    {
      // Setup locally attached sensors
    }
    
    void presentation()
    {
      // Present locally attached sensors here
      sendSketchInfo("Soil Moisture Sensor Capacitive", "1.0");
      present(CHILD_ID, S_MOISTURE);
    
    }
    
    void loop()
    {
      // Send locally attached sensors data here
      int soilMoistureValue;
      soilMoistureValue = analogRead(sensorPin);
     
    
      if(soilMoistureValue > WaterValue && soilMoistureValue < (WaterValue + intervals))
        {
          send(msg.set(100));
        
        }
        else if(soilMoistureValue > (WaterValue + intervals) && soilMoistureValue < (AirValue - intervals))
          {
            send(msg.set(50));
         
          }
        else if(soilMoistureValue < AirValue && soilMoistureValue > (AirValue - intervals))
        {
           send(msg.set(0));
            
        
         }
        
    sleep(SLEEP_TIME);
    // note-to-self: search for possible wait() alternative or deep-sleep
    }
    
    
    General Discussion
  • Login

  • Don't have an account? Register

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