Navigation

    • Register
    • Login
    • OpenHardware.io
    • Categories
    • Recent
    • Tags
    • Popular
    1. Home
    2. Melih Kulig
    • Profile
    • Following
    • Followers
    • Topics
    • Posts
    • Best
    • Groups

    Melih Kulig

    @Melih Kulig

    2
    Reputation
    12
    Posts
    2
    Profile views
    0
    Followers
    0
    Following
    Joined Last Online

    Melih Kulig Follow

    Best posts made by Melih Kulig

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

      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.

      posted in Development
      Melih Kulig
      Melih Kulig
    • RE: Arduino Mega to Raspberry Pi 3 gateway over serial problems

      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.

      posted in Development
      Melih Kulig
      Melih Kulig

    Latest posts made by Melih Kulig

    • RE: Arduino Mega to Raspberry Pi 3 gateway over serial problems

      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.

      posted in Development
      Melih Kulig
      Melih Kulig
    • RE: Arduino Mega to Raspberry Pi 3 gateway over serial problems

      Despite having temporary alternatives, I'm looking into if I can somehow add direct point to point communication over uart serial (/dev/Serial0 in my case) by modifying MyTransportRS485.cpp, but I'm not sure if this will work on a linux raspberry pi gateway, since functions there seem to be arduino specific. If anyone can point me in the right direction, I'd be grateful.

      posted in Development
      Melih Kulig
      Melih Kulig
    • RE: watchdog 2021

      @skywatch, I don't know if you're still looking for the answer, but in case you are, or anyone else who hits through google search, from what I understand reading this page: https://www.nongnu.org/avr-libc/user-manual/group__avr__watchdog.html , you can set your watchdog timer with wdt_enable(time constant), time constant is typically in WDTO_XS format, where X is the seconds, however not all values are available for all processors, please see the link to check which values are supported.

      Next thing to do is including wdt_reset() on your loop. This will reset the timer. If the timer isn't reset by the time your counter expires, watchdog will trigger.

      posted in Development
      Melih Kulig
      Melih Kulig
    • RE: What's the best way to set up lots of binary sensors on a single Arduino?

      Thanks ordered these from amazon, hoping to get a functional gateway out of them. I'll try to build it tomorrow according to specs and see if I can finally get some results.

      50pcs 100uf 50V Radial Electrolytic Capacitor 8x12mm
      ENC28J60 Ethernet LAN Network Module for Arduino SPI 51 AVR PIC LPC STM32
      Makerfire 10pcs Arduino NRF24L01+ 2.4GHz Wireless RF Transceiver Module New
      ELEGOO UNO Project Basic Starter Kit with UNO R3

      posted in Development
      Melih Kulig
      Melih Kulig
    • RE: What's the best way to set up lots of binary sensors on a single Arduino?

      Thank you @TheoL and @Nca78 I ordered a bunch of 1N4148 diodes and I'll see about integrating them sometime. Right now I'm trying to get any sort of output to a gateway and then to home assistant over the network, and once I have a proof of concept, I intend to clean up my hardware work and maybe even look into integrating PCA9555 as Nca78 recommended.

      I ordered a bunch of those NRF24L01 modules too, I will try that as transport and see if I can get a functional gateway.

      posted in Development
      Melih Kulig
      Melih Kulig
    • RE: What's the best way to set up lots of binary sensors on a single Arduino?

      @TheoL Do you recommend putting a diode on each pin that's connected to reed sensor so if multiple reed sensors are on they wouldn't short circuit? Many examples I've seen for reed sensor usage on internet just connect them all together, but none of the examples connect more than a few of them at the same time anyway.

      Also how do you connect your Arduino to your gateway? I posted another thread about my gateway not picking up anything over serial, but I guess it doesn't work over plain serial ports without an RS485 module, so I need to figure out a reliable way to connect a gateway.

      posted in Development
      Melih Kulig
      Melih Kulig
    • RE: Arduino Mega to Raspberry Pi 3 gateway over serial problems

      It looks like I may have misunderstood that RS485 does not work over regular uart serial ports on Arduino and Raspberry Pi, and I probably need an additional rs485 module for both of them. I prefer a wired solution for this particular use case though, and I'm still not clear on what I should do, and buy for the most optimal solution.

      posted in Development
      Melih Kulig
      Melih Kulig
    • Arduino Mega to Raspberry Pi 3 gateway over serial problems

      Hello, I'm using an Arduino Mega to read my sensors and trying to send it to Raspberry Pi serial gateway. I want to use USB serial port (Serial) for debug output, and use Serial2 to send data to Raspberry Pi. I do have a voltage divider between the two to drop from 5V to 3.3, and that part doesn't seem to be the problem initially, when I run minicom on the raspberry pi, I see the sensor values being sent as below when I open a door.

      0;7;1;0;16;1
                  0;7;1;0;16;0
      
      CTRL-A Z for help | 9600 8N1 | NOR | Minicom 2.7 | VT102 | Offline | serial0
      

      However when running mysgw, I never see anything on the same port.

      This is my ./configure:

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

      Same value combination that works for minicom doesn't seem to bring up anything on mysgw:

       sudo ./bin/mysgw
      Feb 17 20:58:50 INFO  Starting gateway...
      Feb 17 20:58:50 INFO  Protocol version - 2.3.2
      Feb 17 20:58:50 DEBUG MCO:BGN:INIT GW,CP=RSNGL---,FQ=NA,REL=255,VER=2.3.2
      Feb 17 20:58:50 DEBUG TSF:LRT:OK
      Feb 17 20:58:50 DEBUG TSM:INIT
      Feb 17 20:58:50 DEBUG TSF:WUR:MS=0
      Feb 17 20:58:50 DEBUG Serial port /dev/serial0 (9600 baud) created
      Feb 17 20:58:50 DEBUG TSM:INIT:TSP OK
      Feb 17 20:58:50 DEBUG TSM:INIT:GW MODE
      Feb 17 20:58:50 DEBUG TSM:READY:ID=0,PAR=0,DIS=0
      Feb 17 20:58:50 DEBUG MCO:REG:NOT NEEDED
      Feb 17 20:58:50 DEBUG Listening for connections on 0.0.0.0:5003
      Feb 17 20:58:50 DEBUG MCO:BGN:STP
      Feb 17 20:58:50 DEBUG MCO:BGN:INIT OK,TSP=1
      Feb 17 20:58:50 DEBUG TSM:READY:NWD REQ
      Feb 17 20:58:50 DEBUG ?TSF:MSG:SEND,0-0-255-255,s=255,c=3,t=20,pt=0,l=0,sg=0,ft=0,st=OK:
      

      This part is so far is priority #1, however I also never get any debug output on Arduino serial monitor. I tried different permutations of all the lines below on my sketch with and without the serial ports on define line, and while most seem to send something over to pi (Serial2), none of them ever produce any output on serial monitor (Serial):

      #define MY_DEBUG Serial
      #define MY_GATEWAY_SERIAL Serial2
      #define MY_BAUD_RATE 9600
      #define MY_RS485
      #define MY_RS485_HWSERIAL Serial2
      #define MY_RS485_BAUD_RATE 9600
      #define MY_SERIALDEVICE Serial2
      #define MY_DEBUGDEVICE Serial
      

      I appreciate any assistance you can provide, thanks for reading.

      posted in Development
      Melih Kulig
      Melih Kulig
    • RE: What's the best way to set up lots of binary sensors on a single Arduino?

      Thank you @TheoL, I agree, the way you put it makes it look cleaner, only one place to add +22 instead of bunch of -22's. I have one more issue, possibly not the correct section for it, but on Home Assistant I'm not getting any of my sensors. I'm wondering if it has anything to do with the way I upload software onto Arduino. Arduino is in a storage closet, so I use the same Raspberry Pi to both upload software and run as gateway. When I upload, I have to kill the gateway process. Once Arduino upload is complete, Arduino reboots, presentation() goes through before I can start running the gateway process. I doubt this is the issue, I added a presentation() call on a 30 second timer on loop(), didn't seem to change anything. I end up with a Home Assistant json file like below:

      {
          "0": {
              "sensor_id": 0,
              "children": {},
              "type": 18,
              "sketch_name": null,
              "sketch_version": null,
              "battery_level": 0,
              "protocol_version": "2.3.2",
              "heartbeat": 0
          }
      
      posted in Development
      Melih Kulig
      Melih Kulig
    • RE: What's the best way to set up lots of binary sensors on a single Arduino?

      Thanks to help from everyone, this compiled correctly and uploaded to Arduino. I will test further with the gateway and see if I run into any issues. Array size of 32 was giving errors on the 32nd element so I increased it to 48 to leave some room for future sensors as well.

      #define MY_DEBUG
      #define MY_GATEWAY_SERIAL
      #define MY_BAUD_RATE 9600
      #include <MySensors.h>
      #include <Bounce2.h>
      
      Bounce debouncer[48];
      int oldValue[48];
      MyMessage msg(0,V_TRIPPED);
      
      void setup() {
        for (byte i = 22; i <= 54; i++) {
          uint8_t arrayIndex=i-22;
          debouncer[arrayIndex] = Bounce();
          oldValue[arrayIndex] = -1;
          // Setup the button
          pinMode(i, INPUT_PULLUP);
          // After setting up the button, setup debouncer
          debouncer[arrayIndex].attach(i);
          debouncer[arrayIndex].interval(5);
        }
      }
      
      void presentation() {
        for (byte i = 22; i <= 54; i++) {
          present(i, S_DOOR);
        }
      }
      
      void loop() {
        for (byte i = 22; i <= 54; i++) {
          uint8_t arrayIndex=i-22;
          debouncer[arrayIndex].update();
          // Get the update value
          int value = debouncer[arrayIndex].read();
          if (value != oldValue[arrayIndex]) {
            // Send in the new value
            send(msg.setSensor(i).set(value == HIGH ? 1 : 0));
            oldValue[arrayIndex] = value;
          }
        }
      }
      
      posted in Development
      Melih Kulig
      Melih Kulig