Navigation

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

    Kai Bepperling

    @Kai Bepperling

    13
    Reputation
    11
    Posts
    404
    Profile views
    0
    Followers
    0
    Following
    Joined Last Online

    Kai Bepperling Follow

    Best posts made by Kai Bepperling

    • RooDe - A "reliable" PeopleCounter

      My idea is to provide a kit with everything a user needs to build a RooDe. That would include the enclosure, sensors (pre soldered), cables in the correct length and screws/nuts. Pleas vote šŸ™‚

      Today is finally the day where i write about my lovely project: RooDe.
      RooDe is a fairly low price reliable PeopleCounter using the MySensors library for communication. The project started as a university project about 2 years ago. I started with a scientific research about exisiting products, people counting techniques and so forth.
      The main goal was to built a low price but reliable people counting system for door ways. I tried a lot of diffierent methods and sensors and ended up with a good combination (two SHARP IR sensors). The system is working very well for me and i use it (passive) nearly every day since then.

      After the university project i continued the development, fixed a lot of bugs, made the system even more reliable, modular and cleaner. At the moment i am switching to fairly new sensors, the VL53L0X which are much better for that prupose due to the non analog interface (which caused a lot of problems...). I refactored the whole project and created a new repository on GitHub: https://github.com/Lyr3x/Roode

      Features:

      • Configurable Setup
        • Different measuring sensors
        • OLED support (displaying the counter and boot up Info)
        • PIR for wakeup after sleep
        • Push-Button support for manual counter change on the hardware itself (not finished yet)
      • Calibration system for your own environment
        • Threshold calculation using standard deviation
        • Recalibration via Domoticz
        • Update Counter via Domoticz
      • Domoticz setup to control Roode and automate things
      • BatteryMode - With a pair of 18650 i used the system for about 3 month.
        • Battery management can be improved though!
      • STL files for a 3D printable enclosure (Available via GitHub)

      Hardware used:

      • Any Atmel 328P AVR (Arduino Pro Mini 5V is working well)
      • 2x VL53L0X/VL53L1X
        • The VL53XXX are using I²C and are much more reliable up to 2m/4m
      • HC-SR501
      • 1x NRF24L01+ incl. Power Adapter
        • Alternative: RFM69 or ESP8266 (ESP8266 for MQTT)
      • 1x CP2101 Micro USB TTL Adapter and used as power supply
      • 1x 128x32 OLED Display (Optional)

      When using ESP8266/ESP32 i recommend the wemos d1 mini boards (available with 8266 and 32) as i build another super small enclosure with a pcb to connect all devices. As the Arduino hardware is super limited the project continues on the ESP platform using MQTT as transmitter

      I have a lot more ideas and plans how to improve RooDe and hope some guys will test the system and give me some feedback. I would really appreciate some feedback about the code itself. I think there is a lot to improve.
      Feel free to open issues and contribute to the project!

      Some of my ideas where i would really appreciate some support:

      • Developing one PCB with all the stuff integrated to make the whole system much smaller and less messy -> If anyone with experience wants to help me to achieve this i would very appreciate a message.
      • Developing support for the VL53L1X
        • These new sensors support programmable ROI position -> Its possible to define two ROI's to count people with one sensor or we can cover 4 ROI's with two sensors to make it possible to count 2 people entering simultaneously. Need to get two sensors to implement this.
      • OTA update mechanism (Not sure if this is a good idea though)

      I'll attach some pictures of the development process. Hope you like the idea and implementation Cheers!
      RooDe latest changelog:
      You will always find the lates changes on GitHub. Check always the dev branches!

      Changelog v1.0 - upcoming release

      • Completely new architecture
        • easy to extend due to new abstraction layer for both sensors and transmitter types (MySensors, MQTT, Blynk, whatever)
      • Independent sensor calibration
      • improved detection algorithm
      • ESP Platform
        • Support for MQTT
        • Multicore support for ESP32 - coming soon
        • Web Interface for easy configuration and setup - coming soon
        • OTA update

      Changelog v0.9.6

      • added full VL53L0X support
      • measruing speed improvements
      • Fixed receiving and sending message issues
      • Added OLED brightness config option
      • general bug fixes and improvements

      Thread Changelog:
      2.12.18:

      • Removed the old Circuit plan as it is maybe confusing
      • Updated Goals
      • Added a few more pictures

      Assembled RooDe: https://photos.app.goo.gl/WdYxeUiESCUnJaAfA

      The first self soldered circuit (was working good) prototype
      1_1543592637580_Platine_klein_oben.jpg
      This is the first iteration of enclosure without the OLED panel
      0_1543592637579_Gehaeuse_montiert.jpg

      The new design preview with the VL53L0X-Sensors
      0_1543592812633_be99e35c-d576-41f1-8f38-3001addd06da-image.png

      posted in My Project
      Kai Bepperling
      Kai Bepperling
    • RE: OLED not wroking for me

      Ah damn it. I was sure i posted the Log...

      At the beginning everything initializes fine like:

      16 MCO:BGN:INIT NODE,CP=RNNNA---,VER=2.2.0
      25 TSM:INIT
      26 TSF:WUR:MS=0
      33 TSM:INIT:TSP OK
      35 TSF:SID:OK,ID=4
      37 TSM:FPAR
      73 TSF:MSG:SEND,4-4-255-255,s=255,c=3,t=7,pt=0,l=0,sg=0,ft=0,st=OK:
      637 TSF:MSG:READ,0-0-4,s=255,c=3,t=8,pt=1,l=1,sg=0:0
      643 TSF:MSG:FPAR OK,ID=0,D=1
      985 TSF:MSG:READ,3-3-4,s=255,c=3,t=8,pt=1,l=1,sg=0:1
      2080 TSM:FPAR:OK
      2081 TSM:ID
      2082 TSM:ID:OK
      2084 TSM:UPL
      2087 TSF:MSG:SEND,4-4-0-0,s=255,c=3,t=24,pt=1,l=1,sg=0,ft=0,st=OK:1
      2098 TSF:MSG:READ,0-0-4,s=255,c=3,t=25,pt=1,l=1,sg=0:1
      2102 TSF:MSG:PONG RECV,HP=1
      2105 TSM:UPL:OK
      2106 TSM:READY:ID=4,PAR=0,DIS=1
      2111 TSF:MSG:SEND,4-4-0-0,s=255,c=3,t=15,pt=6,l=2,sg=0,ft=0,st=OK:0100
      2118 TSF:MSG:READ,0-0-4,s=255,c=3,t=15,pt=6,l=2,sg=0:0100
      2127 TSF:MSG:SEND,4-4-0-0,s=255,c=0,t=17,pt=0,l=5,sg=0,ft=0,st=OK:2.2.0
      2136 TSF:MSG:SEND,4-4-0-0,s=255,c=3,t=6,pt=1,l=1,sg=0,ft=0,st=OK:0
      2147 TSF:MSG:READ,0-0-4,s=255,c=3,t=6,pt=0,l=1,sg=0:M
      2154 TSF:MSG:SEND,4-4-0-0,s=255,c=3,t=11,pt=0,l=5,sg=0,ft=0,st=OK:RooDe
      2162 TSF:MSG:SEND,4-4-0-0,s=255,c=3,t=12,pt=0,l=6,sg=0,ft=0,st=OK:0.9.3b
      2170 TSF:MSG:SEND,4-4-0-0,s=0,c=0,t=3,pt=0,l=0,sg=0,ft=0,st=OK:
      2179 TSF:MSG:SEND,4-4-0-0,s=1,c=0,t=36,pt=0,l=0,sg=0,ft=0,st=OK:
      2186 TSF:MSG:SEND,4-4-0-0,s=3,c=0,t=36,pt=0,l=0,sg=0,ft=0,st=OK:
      2192 MCO:REG:REQ
      2195 TSF:MSG:SEND,4-4-0-0,s=255,c=3,t=26,pt=1,l=1,sg=0,ft=0,st=OK:2
      2202 TSF:MSG:READ,0-0-4,s=255,c=3,t=27,pt=1,l=1,sg=0:1
      2206 MCO:PIM:NODE REG=1
      2209 MCO:BGN:STP
      

      Then i calibrate my IR Sensors (Analog pins 7 and šŸ˜Ž which fails because:

      1
      1
      2
      11
      11
      15
      15
      43
      47
      48
      56
      72
      79
      95
      111
      125
      New threshold is: 19327
      

      i am just calculating an average... After that the sensor does not detect movement through both sensors which results in not sending anything or i just getting a TNR.

      When reading values like IRR:770
      IRC:376
      wihtout the included library the sensor will send a new state. This is a very strange behavior.

      posted in Development
      Kai Bepperling
      Kai Bepperling
    • RE: RooDe - A "reliable" PeopleCounter

      @alowhum @mfalkvidd is totally right. You will get 4 (straight cutted) people parts.

      Because the system needs to be mounted in a doorway or sth. like that it is only possible to count one person at a time. For me it is not a real world problem because i never enter a room with a second body next to me, do you?

      Regarding foolproofnes: It is more or less. The system itself should be plug and play (due to the self calibration function) and the domoticz part (a how to setup guide is included) isnt that complicated.

      posted in My Project
      Kai Bepperling
      Kai Bepperling
    • RE: OLED not wroking for me

      If send had the same signature as the mysensors send it will be endless but it dont. Maybe i should rename my own send function.
      Should i clear the array by hand after the calibration? I thought this is not needed..

      Edit: thanks for the hint with the array. If i init the array with 250 ints the display is working for now.

      What is the best way to "clear/remove" an array?

      posted in Development
      Kai Bepperling
      Kai Bepperling
    • RE: RooDe - A "reliable" PeopleCounter

      @alowhum Well you are totally right there are many edge cases and situations where people counter cant work realiable. But if you think about your home automation universe, how often these edge cases coming along?
      To clarify: Reliable in this context means the system is capable to count one person at a time walking through a doorway or any two walls in range of 4 meters.

      These things never were as reliable as they needed to be.

      That depends on your expectations. At least two persons walking every day through a Roode setup and of course it happens every week that i need to tune the counter manually via the domoticz app. I tried multiple methods and sensors to count people. In my opinion you dont need a 100% reliable people counter covering every edge case and scenario.

      People coming in through the window.

      Seriously?

      This project is not an industrial standard system, which should used as an alarm system or sth. like that. It's counting people to turn your fan and lights on. But if you entering your rooms through the window put another system behind your window...

      People walking out halfway, changing their mind and walking back in

      Is covered.

      Children that are too short to be counted.

      If possible adjust the size. Everything between hip and shoulder works fine.

      Summary:
      The system is built to use in a private smart home stuff scenario, where you don't enter your room and jump out of the window. If you carry something out of room and you don't do that every day the system will give you a huge benefit in laziness and don't bother you with unreliability.
      I don't cover gigantic doorways where crowds entering a room simultane. There are also cats and birds who are not countable too.

      No people counter will ever be 100% reliable.
      To be hones. No sensor every will be.

      I got your points and you are right, but in my opinion you should adjust your expectations within the context. I did not advertised a 100% reliable but a reliable system. But i added some "" to make the title not to confusing

      posted in My Project
      Kai Bepperling
      Kai Bepperling
    • RE: OLED not wroking for me

      Nothing more to say. Sometimes it can be that simple šŸ˜…

      posted in Development
      Kai Bepperling
      Kai Bepperling
    • RE: RooDe - A "reliable" PeopleCounter

      @petewill Very happy to hear that you are interested! If you have any questions feel free to ask.

      I was very productive this weekend and i have some pictures of the new enclosure for you guys. The enclosure is made to use an Arduino Pro Mini (top right), an NRF24L01+ with adapter (top left), OLED Display (top center), PIR, center and two VL53L0X

      2_1543782371321_WallMount.png 1_1543782371321_Inside_with_electronics.png 0_1543782371319_Complete.png

      posted in My Project
      Kai Bepperling
      Kai Bepperling

    Latest posts made by Kai Bepperling

    • RE: RooDe - A "reliable" PeopleCounter

      Hey guys,

      i have a question for you: Is there a interest in a DIY-kit? I could provide a whole kit with all the sensors, cables and enclosure. But before i am going to to buy stuff and so on, i ask you guys about your opinion to see if there is an interest.

      My idea is to provide a kit with everything a user needs to build a RooDe. That would include the enclosure, sensors (pre soldered), cables in the correct length and screws/nuts.
      I'll add a poll in the main post!

      posted in My Project
      Kai Bepperling
      Kai Bepperling
    • RE: RooDe - A "reliable" PeopleCounter

      @petewill Very happy to hear that you are interested! If you have any questions feel free to ask.

      I was very productive this weekend and i have some pictures of the new enclosure for you guys. The enclosure is made to use an Arduino Pro Mini (top right), an NRF24L01+ with adapter (top left), OLED Display (top center), PIR, center and two VL53L0X

      2_1543782371321_WallMount.png 1_1543782371321_Inside_with_electronics.png 0_1543782371319_Complete.png

      posted in My Project
      Kai Bepperling
      Kai Bepperling
    • RE: RooDe - A "reliable" PeopleCounter

      @alowhum Well you are totally right there are many edge cases and situations where people counter cant work realiable. But if you think about your home automation universe, how often these edge cases coming along?
      To clarify: Reliable in this context means the system is capable to count one person at a time walking through a doorway or any two walls in range of 4 meters.

      These things never were as reliable as they needed to be.

      That depends on your expectations. At least two persons walking every day through a Roode setup and of course it happens every week that i need to tune the counter manually via the domoticz app. I tried multiple methods and sensors to count people. In my opinion you dont need a 100% reliable people counter covering every edge case and scenario.

      People coming in through the window.

      Seriously?

      This project is not an industrial standard system, which should used as an alarm system or sth. like that. It's counting people to turn your fan and lights on. But if you entering your rooms through the window put another system behind your window...

      People walking out halfway, changing their mind and walking back in

      Is covered.

      Children that are too short to be counted.

      If possible adjust the size. Everything between hip and shoulder works fine.

      Summary:
      The system is built to use in a private smart home stuff scenario, where you don't enter your room and jump out of the window. If you carry something out of room and you don't do that every day the system will give you a huge benefit in laziness and don't bother you with unreliability.
      I don't cover gigantic doorways where crowds entering a room simultane. There are also cats and birds who are not countable too.

      No people counter will ever be 100% reliable.
      To be hones. No sensor every will be.

      I got your points and you are right, but in my opinion you should adjust your expectations within the context. I did not advertised a 100% reliable but a reliable system. But i added some "" to make the title not to confusing

      posted in My Project
      Kai Bepperling
      Kai Bepperling
    • RE: RooDe - A "reliable" PeopleCounter

      @alowhum @mfalkvidd is totally right. You will get 4 (straight cutted) people parts.

      Because the system needs to be mounted in a doorway or sth. like that it is only possible to count one person at a time. For me it is not a real world problem because i never enter a room with a second body next to me, do you?

      Regarding foolproofnes: It is more or less. The system itself should be plug and play (due to the self calibration function) and the domoticz part (a how to setup guide is included) isnt that complicated.

      posted in My Project
      Kai Bepperling
      Kai Bepperling
    • RooDe - A "reliable" PeopleCounter

      My idea is to provide a kit with everything a user needs to build a RooDe. That would include the enclosure, sensors (pre soldered), cables in the correct length and screws/nuts. Pleas vote šŸ™‚

      Today is finally the day where i write about my lovely project: RooDe.
      RooDe is a fairly low price reliable PeopleCounter using the MySensors library for communication. The project started as a university project about 2 years ago. I started with a scientific research about exisiting products, people counting techniques and so forth.
      The main goal was to built a low price but reliable people counting system for door ways. I tried a lot of diffierent methods and sensors and ended up with a good combination (two SHARP IR sensors). The system is working very well for me and i use it (passive) nearly every day since then.

      After the university project i continued the development, fixed a lot of bugs, made the system even more reliable, modular and cleaner. At the moment i am switching to fairly new sensors, the VL53L0X which are much better for that prupose due to the non analog interface (which caused a lot of problems...). I refactored the whole project and created a new repository on GitHub: https://github.com/Lyr3x/Roode

      Features:

      • Configurable Setup
        • Different measuring sensors
        • OLED support (displaying the counter and boot up Info)
        • PIR for wakeup after sleep
        • Push-Button support for manual counter change on the hardware itself (not finished yet)
      • Calibration system for your own environment
        • Threshold calculation using standard deviation
        • Recalibration via Domoticz
        • Update Counter via Domoticz
      • Domoticz setup to control Roode and automate things
      • BatteryMode - With a pair of 18650 i used the system for about 3 month.
        • Battery management can be improved though!
      • STL files for a 3D printable enclosure (Available via GitHub)

      Hardware used:

      • Any Atmel 328P AVR (Arduino Pro Mini 5V is working well)
      • 2x VL53L0X/VL53L1X
        • The VL53XXX are using I²C and are much more reliable up to 2m/4m
      • HC-SR501
      • 1x NRF24L01+ incl. Power Adapter
        • Alternative: RFM69 or ESP8266 (ESP8266 for MQTT)
      • 1x CP2101 Micro USB TTL Adapter and used as power supply
      • 1x 128x32 OLED Display (Optional)

      When using ESP8266/ESP32 i recommend the wemos d1 mini boards (available with 8266 and 32) as i build another super small enclosure with a pcb to connect all devices. As the Arduino hardware is super limited the project continues on the ESP platform using MQTT as transmitter

      I have a lot more ideas and plans how to improve RooDe and hope some guys will test the system and give me some feedback. I would really appreciate some feedback about the code itself. I think there is a lot to improve.
      Feel free to open issues and contribute to the project!

      Some of my ideas where i would really appreciate some support:

      • Developing one PCB with all the stuff integrated to make the whole system much smaller and less messy -> If anyone with experience wants to help me to achieve this i would very appreciate a message.
      • Developing support for the VL53L1X
        • These new sensors support programmable ROI position -> Its possible to define two ROI's to count people with one sensor or we can cover 4 ROI's with two sensors to make it possible to count 2 people entering simultaneously. Need to get two sensors to implement this.
      • OTA update mechanism (Not sure if this is a good idea though)

      I'll attach some pictures of the development process. Hope you like the idea and implementation Cheers!
      RooDe latest changelog:
      You will always find the lates changes on GitHub. Check always the dev branches!

      Changelog v1.0 - upcoming release

      • Completely new architecture
        • easy to extend due to new abstraction layer for both sensors and transmitter types (MySensors, MQTT, Blynk, whatever)
      • Independent sensor calibration
      • improved detection algorithm
      • ESP Platform
        • Support for MQTT
        • Multicore support for ESP32 - coming soon
        • Web Interface for easy configuration and setup - coming soon
        • OTA update

      Changelog v0.9.6

      • added full VL53L0X support
      • measruing speed improvements
      • Fixed receiving and sending message issues
      • Added OLED brightness config option
      • general bug fixes and improvements

      Thread Changelog:
      2.12.18:

      • Removed the old Circuit plan as it is maybe confusing
      • Updated Goals
      • Added a few more pictures

      Assembled RooDe: https://photos.app.goo.gl/WdYxeUiESCUnJaAfA

      The first self soldered circuit (was working good) prototype
      1_1543592637580_Platine_klein_oben.jpg
      This is the first iteration of enclosure without the OLED panel
      0_1543592637579_Gehaeuse_montiert.jpg

      The new design preview with the VL53L0X-Sensors
      0_1543592812633_be99e35c-d576-41f1-8f38-3001addd06da-image.png

      posted in My Project
      Kai Bepperling
      Kai Bepperling
    • RE: OLED not wroking for me

      Nothing more to say. Sometimes it can be that simple šŸ˜…

      posted in Development
      Kai Bepperling
      Kai Bepperling
    • RE: OLED not wroking for me

      If send had the same signature as the mysensors send it will be endless but it dont. Maybe i should rename my own send function.
      Should i clear the array by hand after the calibration? I thought this is not needed..

      Edit: thanks for the hint with the array. If i init the array with 250 ints the display is working for now.

      What is the best way to "clear/remove" an array?

      posted in Development
      Kai Bepperling
      Kai Bepperling
    • RE: OLED not wroking for me

      I'm using PlatformIO but i think this is what you asked for:

      Program:   15728 bytes (48.0% Full)
      (.text + .data + .bootloader)
      
      Data:        854 bytes (41.7% Full)
      (.data + .bss + .noinit)
      

      roode.cpp

      /*  Room Presence Detection - Microcontroller projects@H-BRS WS16/17
                            Kai Bepperling
      
      */
      // MySensorStuff
      #define MY_DEBUG       //Comment out in production mode
      #define MY_RADIO_NRF24 //use the NRF24L01+ module
      #include <MySensors.h>
      #include <Arduino.h>      //need to be included, cause the file is moved to a .cpp file
      #include <MotionSensor.h> //MotionSensorLib
      //Include and Set Up BatteryMeter Library
      #include <BatteryMeter.h>
      /*
        Version numbers
        Please update frequently
      */
      #define ROODE_VERSION "0.9.3b"
      // #define MYSENSORS_VERSION "2.2.0"
      
      /*Feature selection
        * USE_OLED for OLED 128x32 support
        * USE_BATTERY when powering the controller with an Lithium battery
        * CALIBRATION for calibrating the IR Sensors on startup
      */
      // #define USE_OLED
      // #define USE_BATTERY
      #define CALIBRATION //enables calibration of the irsensors and motion sensor initializing
      
      // battery setup
      #ifdef USE_BATTERY
      BatteryMeter battery(3);                            //BatteryMeter instance
      #define CHILD_ID_BATTERY 2                          //MySensors Battery child ID
      #define BATTERY_FULL 4.2                            // a 18650 lithium ion battery usually give 4.2V when full
      #define BATTERY_ZERO 3.5                            // 2.4V limit for 328p at 16MHz. 1.9V, limit for nrf24l01 without
      MyMessage voltage_msg(CHILD_ID_BATTERY, V_VOLTAGE); //MySensors battery voltage message instance
      #endif
      
      /* MySensors Message types and default settings */
      unsigned long SLEEP_TIME = 0; //sleep forever
      #define CHILD_ID_R 0
      #define CHILD_ID_PC 1
      #define CHILD_ID_THR 3
      MyMessage msg(CHILD_ID_R, V_STATUS);    //room on/off child
      MyMessage pcMsg(CHILD_ID_PC, V_TEXT);   //people counter child
      MyMessage thrMsg(CHILD_ID_THR, V_TEXT); //Threshold child
      
      /* Motion Sensor setup*/
      #define DIGITAL_INPUT_SENSOR 2 // motion sensor digital pin (2 or 3 because just those pins are interrupt pins)
      MotionSensor motion(DIGITAL_INPUT_SENSOR);
      // int pirState = LOW; // we start, assuming no motion detected
      // int val = 0;        // variable for reading the pin status
      // int MotionInit = 2; // set init time in seconds. Should be set to 60s in production mode!
      
      /* IR Sensor setup*/
      #define ANALOG_IR_SENSORR 0 //IR Room Analog Pin
      #define ANALOG_IR_SENSORC 2 //IR Corridor Analog Pin
      #define IR_D_R 7            //IR Sensor Digital Pin for Room - EN Pin
      #define IR_D_C 8            //IR Sensor Digital Pin for Corridor - EN Pin
      #define LTIME 10000         // loop time (should not be lower than 8 seconds)
      #define MTIME 800           // measuring/person
      #define CALIBRATION_VAL 500 //read 500 values (250 from each sensor)
      //#define IR_BOOT 30 // Not needed for the new sensors caused by the enable pin
      
      /* OLED setup 
        For now only the OLED 128x32 monochrom displays are supported without modification
      */
      #ifdef USE_OLED
      // includes for OLED 128x32 and 128x64 support
      #include <SSD1306_text.h>
      SSD1306_text oled;
      
      #endif
      
      // some needed var declarations
      int irrVal = 0;      //analog value store for the room sensor
      int ircVal = 0;      //analog value store for the corridor sensor
      int threshold = 160; //if CALIBRATION is not defined, this threshold is used (okay for a 80cm doorway using reflection foil)
      int inout = -1;      //if inout== 0 -> out; if inout == 1 --> in; THIS STATE WILL BE SENT!
      int peopleCount = 0; //default state: nobody is inside the room
      
      // function prototypes
      // int checkMotion();
      void irSensor();
      int calibration();
      void send();
      
      void setup()
      {
        #ifdef USE_OLED
        // display.begin(SSD1306_SWITCHCAPVCC, 0x3C);  // initialize with the I2C addr 0x3C (for the 128x32)
        // display.display();
        oled.init();
        oled.clear();
        // oled.setTextSize(2);
        // oled.setCursor(0, 0);
        // oled.println("### Roode ###");
        // oled.setCursor(0,15);
        // oled.print("RooDe: ");
        // oled.print(ROODE_VERSION);
        // oled.println("MySensors: 2.2.0");
        #endif
      
        Serial.println("##### RooDe Presence Detection System #####");
      
        //Corridor Sensor Enable PIN
        pinMode(IR_D_C, OUTPUT);
      
        //Room Sensor Voltage Enable PIN
        pinMode(IR_D_R, OUTPUT);
      
        //Motion Sensor
        pinMode(DIGITAL_INPUT_SENSOR, INPUT); // declare motionsensor as input
      
      #ifdef CALIBRATION
        // Serial.println("#### initialize the motion sensor ####");
        //Sensor intialisation
        // for (int i = 0; i < MotionInit; i++) {
        //   wait(1000);
        // }
        motion.Setup(10);
        // Serial.println("#### motion sensor initialized ####");
      
        Serial.println("#### calibrate the ir sensors ####");
        threshold = calibration();
        Serial.print("New threshold is: ");
        Serial.println(threshold);
        send(thrMsg.set(threshold));
        Serial.println("#### calibration done ####");
      #endif
      
        Serial.println("#### Setting the PresenceCounter and Status to OUT (0) ####");
        send(msg.set(0));   //Setting presence status to 0
        send(pcMsg.set(0)); //Setting the people counter to 0
      }
      
      void presentation()
      {
        sendSketchInfo("RooDe", ROODE_VERSION);
        present(CHILD_ID_R, S_BINARY);
        present(CHILD_ID_PC, S_INFO);
      #ifdef USE_BATTERY
        present(CHILD_ID_BATTERY, S_CUSTOM);
      #endif
        present(CHILD_ID_THR, S_INFO);
      }
      
      void loop()
      {
      
        // Sleep until interrupt comes in on motion sensor. Send never an update
      
        if (motion.checkMotion() == LOW)
        {
          irSensor();
          digitalWrite(IR_D_R, LOW);
          wait(1);
          digitalWrite(IR_D_C, LOW);
          sleep(digitalPinToInterrupt(DIGITAL_INPUT_SENSOR), RISING, SLEEP_TIME);
          irSensor();
          while (motion.checkMotion() != LOW)
          {
            irSensor();
          }
        }
      }
      
      // int checkMotion() {
      //   //Motion Sensor
      //   val = digitalRead(DIGITAL_INPUT_SENSOR);  // read input value
      //   if (val == HIGH) {            // check if the input is HIGH
      //
      //     if (pirState == LOW) {      // check if the pir status is LOW
      // #ifdef MY_DEBUG
      //       Serial.println("Motion detected");
      // #endif
      //       pirState = HIGH;          // set pir status to HIGH
      //     }
      //   } else {
      //     if (pirState == HIGH) {     //check if the pir status is HIGH
      // #ifdef MY_DEBUG
      //       Serial.println("No Motion");
      // #endif
      //       pirState = LOW;           // set the pir status to LOW
      //     }
      //   }
      //   return pirState;
      // }
      
      void irSensor()
      {
        int starttime = millis();
        int endtime = starttime;
      
        while ((endtime - starttime) <= LTIME) // do this loop for up to 5000mS
        {
          // turn both sensors on
          digitalWrite(IR_D_R, HIGH);
          wait(1);
          digitalWrite(IR_D_C, HIGH);
          wait(5);
          inout = -1;
      
          irrVal = analogRead(ANALOG_IR_SENSORR);
          wait(10);
          ircVal = analogRead(ANALOG_IR_SENSORC);
      
      #ifdef MY_DEBUG
          Serial.print("IRR:");
          Serial.println(irrVal);
          Serial.print("IRC:");
          Serial.println(ircVal);
      #endif
          if (irrVal > threshold && ircVal < threshold && inout != 1)
          {
            int startR = millis();
            int endR = startR;
            while ((endR - startR) <= MTIME)
            {
              irrVal = analogRead(ANALOG_IR_SENSORR);
              wait(10);
              ircVal = analogRead(ANALOG_IR_SENSORC);
              if (ircVal > threshold && irrVal > threshold)
              {
      #ifdef MY_DEBUG
                Serial.print("In Loop IRR: ");
                Serial.println(irrVal);
                Serial.print("In Loop IRC: ");
                Serial.println(ircVal);
                Serial.print("Delay Time: ");
                Serial.println(MTIME - (endR - startR));
      #endif
                while (irrVal > threshold || ircVal > threshold)
                {
                  irrVal = analogRead(ANALOG_IR_SENSORR);
                  wait(10);
                  ircVal = analogRead(ANALOG_IR_SENSORC);
                  if (ircVal > threshold && irrVal < threshold)
                  {
                    // turn both sensors off
                    digitalWrite(IR_D_R, LOW);
                    wait(1);
                    digitalWrite(IR_D_C, LOW);
                    inout = 0;
                    send();
                    break;
                  }
                  wait(11);
                }
      
                if (inout == 0)
                {
                  wait(150);
                  ircVal = 0;
                  endR = millis();
                  starttime = millis();
                  endtime = starttime;
                  break;
                }
              }
              else
              {
                wait(1);
                endR = millis();
              }
            }
          }
          else
          {
            endtime = millis();
          }
      
          if (ircVal > threshold && irrVal < threshold && inout != 0)
          {
            int startC = millis();
            int endC = startC;
            while ((endC - startC) <= MTIME)
            {
              ircVal = analogRead(ANALOG_IR_SENSORC);
              wait(10);
              irrVal = analogRead(ANALOG_IR_SENSORR);
              if (irrVal > threshold && ircVal > threshold)
              {
      #ifdef MY_DEBUG
                Serial.print("In Loop IRC: ");
                Serial.println(ircVal);
                Serial.print("In Loop IRR: ");
                Serial.println(irrVal);
                Serial.print("Delay Time: ");
                Serial.println(MTIME - (endC - startC));
      #endif
                while (irrVal > threshold || ircVal > threshold)
                {
                  irrVal = analogRead(ANALOG_IR_SENSORR);
                  wait(10);
                  ircVal = analogRead(ANALOG_IR_SENSORC);
                  if (irrVal > threshold && ircVal < threshold)
                  {
                    // turn both sensors off
                    digitalWrite(IR_D_R, LOW);
                    wait(1);
                    digitalWrite(IR_D_C, LOW);
                    inout = 1;
                    send();
                    break;
                  }
                  wait(11);
                }
      
                if (inout == 1)
                {
                  wait(150);
                  irrVal = 0;
                  endC = millis();
                  starttime = millis();
                  endtime = starttime;
                  break;
                }
              }
              else
              {
                wait(11);
                endC = millis();
              }
            }
          }
          else
          {
            endtime = millis();
          }
          wait(11);
        }
      }
      
      void send()
      {
        if (inout == 1)
        {
          peopleCount++;
          send(msg.set(inout));
          wait(30);
          send(pcMsg.set(peopleCount));
        }
        else if (inout == 0)
        {
          if (peopleCount > 0)
          {
            peopleCount--;
          }
          if (peopleCount == 0)
          {
            send(msg.set(inout));
          }
          wait(30);
          send(pcMsg.set(peopleCount));
        }
      
      #ifdef USE_BATTERY
        float voltage = battery.checkBatteryLevel();
        send(voltage_msg.set(voltage, 3)); // redVcc returns millivolts. Set wants volts and how many decimals (3 in our case)
        sendBatteryLevel(round((voltage - BATTERY_ZERO) * 100.0 / (BATTERY_FULL - BATTERY_ZERO)));
      #endif
      }
      
      int calibration()
      {
      
        digitalWrite(IR_D_C, HIGH);
        digitalWrite(IR_D_R, HIGH);
        delay(100);
        int distances[CALIBRATION_VAL];
        int max = 0;
        for (int m = 0; m < CALIBRATION_VAL; m = m + 2)
        {
          delay(8);
          irrVal = analogRead(ANALOG_IR_SENSORR);
          delay(8);
          ircVal = analogRead(ANALOG_IR_SENSORC);
      
          //calculate the max without jumps for the room sensor
          if ((irrVal >= max && (irrVal - max) < 30) || irrVal - max == irrVal)
          {
            Serial.println(irrVal);
            max = irrVal;
            distances[m] = irrVal;
          }
          else
          {
            distances[m] = 0;
          }
      
          //calculate the max without jumps for the corridor sensor
          if (((ircVal >= max) && ((ircVal - max) < 30)) || ((ircVal - max) == ircVal))
          {
            Serial.println(ircVal);
            max = ircVal;
            distances[m + 1] = ircVal;
          }
          else
          {
            distances[m + 1] = 0;
          }
        }
      
        // shutdown both sensors
        digitalWrite(IR_D_C, LOW);
        digitalWrite(IR_D_R, LOW);
        max = 0;
        //calculate the absolute max value to determine the new threshold
        for (int i = 0; i < CALIBRATION_VAL; i++)
        {
          if (distances[i] >= max)
          {
            max = distances[i];
          }
        }
        return max + 30; //add 30 to be super safe
      }
      
      /*
        - Not sure if this function ever will be used... But good idea to have this as backup
        - Tests will be show more about RAM problems
      */
      int freeRam()
      {
        extern int __heap_start, *__brkval;
        int v;
        return (int)&v - (__brkval == 0 ? (int)&__heap_start : (int)__brkval);
      }
      
      
      posted in Development
      Kai Bepperling
      Kai Bepperling
    • RE: OLED not wroking for me

      Ah damn it. I was sure i posted the Log...

      At the beginning everything initializes fine like:

      16 MCO:BGN:INIT NODE,CP=RNNNA---,VER=2.2.0
      25 TSM:INIT
      26 TSF:WUR:MS=0
      33 TSM:INIT:TSP OK
      35 TSF:SID:OK,ID=4
      37 TSM:FPAR
      73 TSF:MSG:SEND,4-4-255-255,s=255,c=3,t=7,pt=0,l=0,sg=0,ft=0,st=OK:
      637 TSF:MSG:READ,0-0-4,s=255,c=3,t=8,pt=1,l=1,sg=0:0
      643 TSF:MSG:FPAR OK,ID=0,D=1
      985 TSF:MSG:READ,3-3-4,s=255,c=3,t=8,pt=1,l=1,sg=0:1
      2080 TSM:FPAR:OK
      2081 TSM:ID
      2082 TSM:ID:OK
      2084 TSM:UPL
      2087 TSF:MSG:SEND,4-4-0-0,s=255,c=3,t=24,pt=1,l=1,sg=0,ft=0,st=OK:1
      2098 TSF:MSG:READ,0-0-4,s=255,c=3,t=25,pt=1,l=1,sg=0:1
      2102 TSF:MSG:PONG RECV,HP=1
      2105 TSM:UPL:OK
      2106 TSM:READY:ID=4,PAR=0,DIS=1
      2111 TSF:MSG:SEND,4-4-0-0,s=255,c=3,t=15,pt=6,l=2,sg=0,ft=0,st=OK:0100
      2118 TSF:MSG:READ,0-0-4,s=255,c=3,t=15,pt=6,l=2,sg=0:0100
      2127 TSF:MSG:SEND,4-4-0-0,s=255,c=0,t=17,pt=0,l=5,sg=0,ft=0,st=OK:2.2.0
      2136 TSF:MSG:SEND,4-4-0-0,s=255,c=3,t=6,pt=1,l=1,sg=0,ft=0,st=OK:0
      2147 TSF:MSG:READ,0-0-4,s=255,c=3,t=6,pt=0,l=1,sg=0:M
      2154 TSF:MSG:SEND,4-4-0-0,s=255,c=3,t=11,pt=0,l=5,sg=0,ft=0,st=OK:RooDe
      2162 TSF:MSG:SEND,4-4-0-0,s=255,c=3,t=12,pt=0,l=6,sg=0,ft=0,st=OK:0.9.3b
      2170 TSF:MSG:SEND,4-4-0-0,s=0,c=0,t=3,pt=0,l=0,sg=0,ft=0,st=OK:
      2179 TSF:MSG:SEND,4-4-0-0,s=1,c=0,t=36,pt=0,l=0,sg=0,ft=0,st=OK:
      2186 TSF:MSG:SEND,4-4-0-0,s=3,c=0,t=36,pt=0,l=0,sg=0,ft=0,st=OK:
      2192 MCO:REG:REQ
      2195 TSF:MSG:SEND,4-4-0-0,s=255,c=3,t=26,pt=1,l=1,sg=0,ft=0,st=OK:2
      2202 TSF:MSG:READ,0-0-4,s=255,c=3,t=27,pt=1,l=1,sg=0:1
      2206 MCO:PIM:NODE REG=1
      2209 MCO:BGN:STP
      

      Then i calibrate my IR Sensors (Analog pins 7 and šŸ˜Ž which fails because:

      1
      1
      2
      11
      11
      15
      15
      43
      47
      48
      56
      72
      79
      95
      111
      125
      New threshold is: 19327
      

      i am just calculating an average... After that the sensor does not detect movement through both sensors which results in not sending anything or i just getting a TNR.

      When reading values like IRR:770
      IRC:376
      wihtout the included library the sensor will send a new state. This is a very strange behavior.

      posted in Development
      Kai Bepperling
      Kai Bepperling
    • OLED not wroking for me

      I am trying to get an 128x32 OLED (I2C) working with MySensors 2.2.0

      When i include the lib (regardless if i'm trying the Adafruit lib, U8g2lib or the shorted lib from https://forum.mysensors.org/topic/2360/temperature-humidity-node-with-oled-display/5) my sensor is not working anymore. I dont need to use the lib, including is enough.

      I'm using an NRF24L01+ with an Arduino Nano and here are my includes

      #define MY_DEBUG       //Comment out in production mode
      #define MY_RADIO_NRF24 //use the NRF24L01+ module
      #include <MySensors.h>
      #include <Arduino.h>      //need to be included, cause the file is moved to a .cpp file
      #include <MotionSensor.h> //MotionSensorLib
      //Include and Set Up BatteryMeter Library
      #include <BatteryMeter.h>
      #define USE_OLED
      #ifdef USE_OLED
      // includes for OLED 128x32 and 128x64 support
      #include <SSD1306_text.h>
      //SSD1306_text oled;
      
      #endif
      
      void setup(){
      ...
      }
      
      posted in Development
      Kai Bepperling
      Kai Bepperling