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
Melih KuligM

Melih Kulig

@Melih Kulig
About
Posts
12
Topics
2
Shares
0
Groups
0
Followers
0
Following
0

Posts

Recent Best Controversial

  • What's the best way to set up lots of binary sensors on a single Arduino?
    Melih KuligM Melih Kulig

    Hello,

    I have an Arduino device where I need to monitor status of 32 pins for reed sensors. To make things easier, I put everything in for loop as much as I can, but I'm running into some roadblocks and I could use a little help.

    I started off with this example (https://github.com/mysensors/MySensorsArduinoExamples/blob/master/examples/BinarySwitchSensor/BinarySwitchSensor.ino) and examples from forums on this site (https://forum.mysensors.org/topic/264/help-with-arrays-and-debouncing). Second one was good for helping me simplify, but still would be too cluttered for 32 pins. I tried my modifications seen below:

    #define MY_DEBUG
    #define MY_GATEWAY_SERIAL
    #define MY_BAUD_RATE 9600
    #include <MySensors.h>
    #include <Bounce2.h>
    
    Bounce debouncer[32];
    int oldValue[32];
    MyMessage msg[32];
    
    void setup() {
      for (byte i = 22; i <= 54; i++) {
        debouncer[i] = Bounce();
        oldValue[i] = -1;
      }
      for (byte i = 22; i <= 54; i++) {
        pinMode(i, INPUT);
        digitalWrite(i, HIGH);
        debouncer[i].attach(i);
        debouncer[i].interval(5);
      }
    }
    
    void presentation() {
      for (byte i = 22; i <= 54; i++) {
        present(i, S_DOOR);
      }
    }
    
    void loop() {
      for (byte i = 22; i <= 54; i++) {
        debouncer[i].update();
        int value = debouncer[i].read();
        if (value != oldValue[i]) {
          send(msg[i].set(value == HIGH ? 1 : 0));
          oldValue[i] = value;
        }
      }
    }
    

    I understand that since MyMessage objects are created at definition, I can't use "msg (i, V_TRIPPED)" in setup(). I can't seem to use constructor methods from MyMessage.cpp properly either. I tried code below in setup() but that threw error message 'unresolved overloaded function type' for both lines.

    msg[i].setSensor[i];
    msg[i].setType[V_TRIPPED];
    

    Is there a better way to set up 32 instances of the message object with a for loop? I plan to add more sensors of different types once I get these working, so I would like to keep this in a for loop to make it maintainable.

    Thank you.

    Development

  • Arduino Mega to Raspberry Pi 3 gateway over serial problems
    Melih KuligM Melih Kulig

    I finally got it working reading through google searches. I'd like to provide how I did it for anyone that may run into a similar issue in the future. While looking for this solution, I saw at least one person who had the exact same issue and their problem went unresolved.

    Raspberry Pi 3 is connected to Arduino Mega through regular serial link. Raspberry pi uses uart pins that map to Serial0 in raspbian. On Arduino Mega I use Serial2 pins (16,17). There's a voltage divider circuit between the two that reduces 5v to 3.3 for the pi.

    I compiled my gateway on pi with below:

    ./configure --my-transport=rs485 --my-rs485-serial-port=/dev/serial0 --my-rs485-baudrate=9600
    

    On Arduino I have these define lines:

    #define MY_DEBUG
    #define MY_DEBUGDEVICE Serial
    #define MY_RS485
    #define MY_RS485_HWSERIAL Serial2
    #define MY_NODE_ID 1
    #define MY_RS485_BAUD_RATE 9600
    #define MY_RS485_DE_PIN -1
    

    I'm not an expert on this by any means, but out of everything I tried, this is what worked for me. There are still some remaining issues:

    • Possibly due to line noise or voltage being low on Arduino, I've had one crash that made Arduino print gibberish on serial and it stopped transmitting anything at all.
    • I use Home Assistant and it seems to give up on MySensors if it doesn't receive anything in a while. Requires restart of HA core. Not very reliable.

    I still welcome any insight into this process and any alternatives/recommendations. I'd like to make this as reliable as possible, but my knowledge of these systems and electronics is limited.

    Development
  • Login

  • Don't have an account? Register

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