Skip to content
  • 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
elmarculinoE

elmarculino

@elmarculino
  • Getting Started
  • Controller
  • Build
  • Hardware
  • Download/API
  • Forum
  • Store
About
Posts
5
Topics
0
Shares
0
Groups
0
Followers
0
Following
0

Posts

Recent Best Controversial

  • RS485/RS232/Serial transport class for mysensors.org
    elmarculinoE elmarculino

    @LeoDesigner My 1.5.2 RS485 Humidity sensor send the same messages as the example Humidity sketch, but shows a lot of 'X' and '?' characters at 115200 in Serial Console.

    The console with the example Humidity sketch is clean:

    sensor started, id=1, parent=0, distance=1
    send: 1-1-0-0 s=255,c=3,t=11,pt=0,l=8,sg=0,st=ok:Humidity
    send: 1-1-0-0 s=255,c=3,t=12,pt=0,l=3,sg=0,st=ok:1.0
    send: 1-1-0-0 s=0,c=0,t=7,pt=0,l=0,sg=0,st=ok:
    send: 1-1-0-0 s=1,c=0,t=6,pt=0,l=0,sg=0,st=ok:
    send: 1-1-0-0 s=1,c=1,t=0,pt=7,l=5,sg=0,st=ok:26.0
    T: 26.00
    send: 1-1-0-0 s=0,c=1,t=1,pt=7,l=5,sg=0,st=ok:44.0
    H: 44.00
    

    Do you know what can be causing it? Am I doing anything wrong, again?

    #include <SPI.h>
    #include <MySensor.h>  
    #include <DHT.h>  
    #include <MyHwATMega328.h>
    #include <SerialTransport.h>
    
    #define CHILD_ID_HUM 0
    #define CHILD_ID_TEMP 1
    #define HUMIDITY_SENSOR_DIGITAL_PIN 3
    unsigned long SLEEP_TIME = 30000; // Sleep time between reads (in milliseconds)
    
    MyTransportSerial transport(Serial,5,2); 
    MyHwATMega328 hw;
    MySensor gw(transport, hw);
    DHT dht;
    float lastTemp;
    float lastHum;
    boolean metric = true; 
    MyMessage msgHum(CHILD_ID_HUM, V_HUM);
    MyMessage msgTemp(CHILD_ID_TEMP, V_TEMP);
    
    
    void setup()  
    { 
      gw.begin();
      dht.setup(HUMIDITY_SENSOR_DIGITAL_PIN); 
    
      // Send the Sketch Version Information to the Gateway
      gw.sendSketchInfo("Humidity", "1.0");
    
      // 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);
      
      metric = gw.getConfig().isMetric;
    }
    
    void loop()      
    {  
      delay(dht.getMinimumSamplingPeriod());
    
      float temperature = dht.getTemperature();
      if (isnan(temperature)) {
          Serial.println("Failed reading temperature from DHT");
      } else if (temperature != lastTemp) {
        lastTemp = temperature;
        if (!metric) {
          temperature = dht.toFahrenheit(temperature);
        }
        gw.send(msgTemp.set(temperature, 1));
        Serial.print("T: ");
        Serial.println(temperature);
      }
      
      float humidity = dht.getHumidity();
      if (isnan(humidity)) {
          Serial.println("Failed reading humidity from DHT");
      } else if (humidity != lastHum) {
          lastHum = humidity;
          gw.send(msgHum.set(humidity, 1));
          Serial.print("H: ");
          Serial.println(humidity);
      }
    
      gw.sleep(SLEEP_TIME); //sleep a bit
    }
    
    Development rs485 serial rs485

  • RS485/RS232/Serial transport class for mysensors.org
    elmarculinoE elmarculino

    @hek None. Works out of the box. But I could not make it work with Home Assistant.

    Pin 9 >>> DI
    Pin 8 >>> RO
    Pin 2 >>> DE and RE

    INFO:mysensors.mysensors:/dev/ttyUSB0 is open...
    INFO:mysensors.mysensors:Connected to /dev/ttyUSB0
    INFO:mysensors.mysensors:n:0 c:255 t:3 s:9 p:read: 1-1-0 s=0,c=1,
    WARNING:mysensors.mysensors:Error decoding message from gateway, probably received bad byte.
    WARNING:mysensors.mysensors:Error decoding message from gateway, probably received bad byte.
    WARNING:mysensors.mysensors:Error decoding message from gateway, probably received bad byte.```
    Development rs485 serial rs485

  • RS485/RS232/Serial transport class for mysensors.org
    elmarculinoE elmarculino

    @LeoDesigner I still could not make it work in 1.5.2 with your library, but I will keep trying. Thanks!

    @hek I finally could make a gateway / sensor (Humidity) connection via RS485 using the development branch. Is any Controller compatible with the development branch? Thanks!

    0;255;3;0;9;Starting gateway (RSNGA-, 2.0.0-beta)
    0;255;3;0;9;Radio init successful.
    0;255;3;0;14;Gateway startup complete.
    0;255;3;0;9;Init complete, id=0, parent=0, distance=0
    0;255;3;0;9;read: 1-1-0 s=0,c=1,t=1,pt=7,l=5,sg=0:44.0
    1;0;1;0;1;44.0
    0;255;3;0;9;read: 1-1-0 s=0,c=1,t=1,pt=7,l=5,sg=0:43.0
    1;0;1;0;1;43.0
    0;255;3;0;9;read: 1-1-0 s=0,c=1,t=1,pt=7,l=5,sg=0:44.0
    1;0;1;0;1;44.0
    0;255;3;0;9;read: 1-1-0 s=1,c=1,t=0,pt=7,l=5,sg=0:27.0
    1;1;1;0;0;27.0
    
    Development rs485 serial rs485

  • RS485/RS232/Serial transport class for mysensors.org
    elmarculinoE elmarculino

    @LeoDesigner
    Thanks for the help. I made the changes you pointed out, but still no lucky. What controller are you using? This should work in a direct crossover connection too?

    Development rs485 serial rs485

  • RS485/RS232/Serial transport class for mysensors.org
    elmarculinoE elmarculino

    @LeoDesigner
    I'm trying a Gateway & 4 relays/4 switches configuration using 1.5.2 version. As @Michal my configuration works fine with this example: https://arduino-info.wikispaces.com/SoftwareSerialRS485Example

    Anything wrong with my sketches?

    Gateway:

    /**
     * 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 WITH_LEDS_BLINKING in MyConfig.h
     * - 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 
     * 
     */
    
    #define NO_PORTB_PINCHANGES  
    
    #include <MySigningNone.h>
    #include <MyTransportRFM69.h>
    //#include <MyTransportNRF24.h>
    //#include <MyHwATMega328.h>
    #include <MySigningAtsha204Soft.h>
    #include <MySigningAtsha204.h>
    #include <SerialTransport.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
    
    // NRFRF24L01 radio driver (set low transmit power by default) 
    //MyTransportNRF24 transport(RF24_CE_PIN, RF24_CS_PIN, RF24_PA_LEVEL_GW);
    //MyTransportRFM69 transport;
    MyTransportSerial transport(Serial,AUTO,2);
    
    // Message signing driver (signer needed if MY_SIGNING_FEATURE is turned on in MyConfig.h)
    //MySigningNone signer;
    //MySigningAtsha204Soft signer;
    //MySigningAtsha204 signer;
    
    // Hardware profile 
    MyHwATMega328 hw;
    
    // Construct MySensors library (signer needed if MY_SIGNING_FEATURE is turned on in MyConfig.h)
    // To use LEDs blinking, uncomment WITH_LEDS_BLINKING in MyConfig.h
    #ifdef WITH_LEDS_BLINKING
    MySensor gw(transport, hw /*, signer*/, RADIO_RX_LED_PIN, RADIO_TX_LED_PIN, RADIO_ERROR_LED_PIN);
    #else
    MySensor gw(transport, hw /*, signer*/);
    #endif
    
    char inputString[MAX_RECEIVE_LENGTH] = "";    // A string to hold incoming commands from serial/ethernet interface
    int inputPos = 0;
    boolean commandComplete = false;  // whether the string is complete
    
    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);
    }
    
      
    void setup()  
    { 
      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);
    }
    
    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;
        }
      }
    }
    
    
    

    4 relays / 4 switches

    /*
      State change detection (edge detection)
    
     Often, you don't need to know the state of a digital input all the time,
     but you just need to know when the input changes from one state to another.
     For example, you want to know when a button goes from OFF to ON.  This is called
     state change detection, or edge detection.
    
     This example shows how to detect when a button or button changes from off to on
     and on to off.
    
     The circuit:
     * pushbutton attached to pin 2 from +5V
     * 10K resistor attached to pin 2 from ground
     * LED attached from pin 13 to ground (or use the built-in LED on
       most Arduino boards)
    
     created  27 Sep 2005
     modified 30 Aug 2011
     by Tom Igoe
    
    This example code is in the public domain.
    
     http://www.arduino.cc/en/Tutorial/ButtonStateChange
    
     */
    
    #include <MySigningNone.h>
    //#include <MyTransportNRF24.h>
    //#include <MyTransportRFM69.h>
    #include <SerialTransport.h>
    #include <MyHwATMega328.h>
    #include <MySensor.h>
    #include <SPI.h>
    
    // this constant won't change:
    int buttonPin[] = {9, 10, 11, 12};          // array of pins that the pushbutton is attached to
    int relayPin[] = {3, 4, 5, 6};           // array of pins that the relay is attached to
    int pinCount = 4;                  // number of buttons/relays attached
    
    // Variables will change:
    int buttonState[] = {0, 0};         // current state of the button
    int lastButtonState[] = {0, 0};     // previous state of the button
    
    #define RELAY_ON 1
    #define RELAY_OFF 0
    int relayState[] = {RELAY_OFF, RELAY_OFF};   // counter for the number of button presses
    
    
    // NRFRF24L01 radio driver (set low transmit power by default) 
    MyTransportSerial transport(Serial,AUTO,2); 
    //MyTransportRFM69 radio;
    // Message signing driver (none default)
    //MySigningNone signer;
    // Select AtMega328 hardware profile
    MyHwATMega328 hw;
    // Construct MySensors library
    MySensor gw(transport, hw);
    
    void setup() 
    {
      // Initialize library and add callback for incoming messages
      gw.begin(incomingMessage, AUTO, true);
      // Send the sketch version information to the gateway and Controller
      gw.sendSketchInfo("Relays & Buttons", "1.0");
      
      for (int i = 0; i < pinCount; i++) {
        // Register all sensors to gw (they will be created as child devices)
        gw.present(buttonPin[i], S_LIGHT);
        gw.present(relayPin[i], S_LIGHT);
        
        // initialize the button pin as a input:
        pinMode(buttonPin[i], INPUT);
        digitalWrite(buttonPin[i], 0);
        // initialize the relay as an output:
        pinMode(relayPin[i], OUTPUT);
        digitalWrite(relayPin[i], gw.loadState(i)?RELAY_ON:RELAY_OFF);
      }
    }
    
    
    void loop() {
      // Alway process incoming messages whenever possible
      gw.process();
      
      for (int i = 0; i < pinCount; i++) {
        MyMessage msg(relayPin[i], V_LIGHT);
        buttonState[i] = digitalRead(buttonPin[i]);
    
        if (buttonState[i] != lastButtonState[i]) {
          if (buttonState[i] == 1) {
    //         gw.send(msg.set(relayState[i]==RELAY_ON ? RELAY_OFF : RELAY_ON));
    //          if(relayState[i]==RELAY_ON) gw.send(msg.set(RELAY_OFF));
    //          else                        gw.send(msg.set(RELAY_ON));
              if(relayState[i]==RELAY_ON) relayState[i]=RELAY_OFF;
              else                        relayState[i]=RELAY_ON;
          }
          lastButtonState[i] = buttonState[i];
        }
        digitalWrite(relayPin[i], relayState[i]);
      }
    }
    
    
    void incomingMessage(const MyMessage &message) {
      // We only expect one type of message from controller. But we better check anyway.
      if (message.type==V_LIGHT) {
          for (int i = 0; i < pinCount; i++) {
            // digitalWrite(message.sensor-1+relayPin[1], message.getBool()?RELAY_ON:RELAY_OFF);
          }
       } 
    }
    
    
    Development rs485 serial rs485
  • Login

  • Don't have an account? Register

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