Navigation

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

    Best posts made by tbully

    • RE: Relay actuator + water meter pulse sensor sketch

      Here's my code in case you're interested:

      //
      // Use this sensor to measure volume and flow of your house watermeter.
      // You need to set the correct pulsefactor of your meter (pulses per m3).
      // The sensor starts by fetching current volume reading from gateway (VAR 1).
      // Reports both volume and flow back to gateway.
      //
      // Unfortunately millis() won't increment when the Arduino is in 
      // sleepmode. So we cannot make this sensor sleep if we also want  
      // to calculate/report flow.
      //
      // Sensor on pin 3
      
      #include <MySensor.h>
      #include <SPI.h>
      
      
      #define DIGITAL_INPUT_SENSOR 3                  // The digital input you attached your sensor.  (Only 2 and 3 generates interrupt!)
      //#define PULSE_FACTOR 12500                       // Nummber of blinks per m3 of your meter (One rotation/liter)
      #define PULSE_FACTOR 288000
      #define SLEEP_MODE false                        // flowvalue can only be reported when sleep mode is false.
      #define MAX_FLOW 25                             // Max flow (l/min) value to report. This filetrs outliers.
      #define INTERRUPT DIGITAL_INPUT_SENSOR-2        // Usually the interrupt = pin -2 (on uno/nano anyway)
      #define CHILD_ID 0                              // Id of the sensor child
      #define RELAY_1  4  // Arduino Digital I/O pin number for first relay
      #define NUMBER_OF_RELAYS 1 
      #define RELAY_ON 1
      #define RELAY_OFF 0
      unsigned long SEND_FREQUENCY = 10000;              // Minimum time between send (in miliseconds). We don't want to spam the gateway.
      
      MySensor gw;
      
      double ppl = ((double)PULSE_FACTOR)/1000;        // Pulses per liter
      
      volatile unsigned long pulseCount = 0;   
      volatile unsigned long lastBlink = 0;
      volatile double flow = 0;
      boolean pcReceived = false;
      unsigned long oldPulseCount = 0;
      unsigned long newBlink = 0;   
      double oldflow = 0;
      double volume;                     
      double oldvolume;
      unsigned long lastSend;
      unsigned long lastPulse;
      unsigned long currentTime;
      boolean metric;
      
      MyMessage flowMsg(CHILD_ID,V_FLOW);
      MyMessage volumeMsg(CHILD_ID,V_VOLUME);
      MyMessage pcMsg(CHILD_ID,V_VAR1);
      
      void setup()  
      {  
        //gw.begin(incomingMessage, AUTO, true);
        //gw.begin(incomingMessage, AUTO, false, AUTO, RF24_PA_LOW);
        gw.begin(incomingMessage, AUTO, false, AUTO);
        //  gw.send(pcMsg.set(0));
        //  gw.send(volumeMsg.set(0.000, 3));
        //Water meter setup
        //Serial.print("PPL:");
        //Serial.print(ppl);
      
        // Send the sketch version information to the gateway and Controller
        gw.sendSketchInfo("Water Meter and Valve", "1.0");
      
        // Register this device as Waterflow sensor
        gw.present(CHILD_ID, S_WATER);      
      
        // Fetch last known pulse count value from gw
        gw.request(CHILD_ID, V_VAR1);
        //pulseCount = oldPulseCount = 0;
      
        //Serial.print("Last pulse count from gw:");
        //Serial.println(pulseCount);
      
        attachInterrupt(INTERRUPT, onPulse, RISING);
        lastSend = millis();
      
        //RELAY SETUP
        for (int sensor=1, pin=RELAY_1; sensor<=NUMBER_OF_RELAYS;sensor++, pin++) {
          // Register all sensors to gw (they will be created as child devices)
          gw.present(sensor, S_LIGHT);
          // Then set relay pins in output mode
          pinMode(pin, OUTPUT);   
          // Set relay to last known state (using eeprom storage) 
          digitalWrite(pin, gw.loadState(sensor)?RELAY_ON:RELAY_OFF);
        }
      
      }
      
      
      void loop()     
      { 
        gw.process();
        currentTime = millis();
        bool sendTime = currentTime - lastSend > SEND_FREQUENCY;
        if (pcReceived && (SLEEP_MODE || sendTime)) {
          // New flow value has been calculated  
          if (!SLEEP_MODE && flow != oldflow) {
            // Check that we dont get unresonable large flow value. 
            // could hapen when long wraps or false interrupt triggered
            if (flow<((unsigned long)MAX_FLOW)) {
              gw.send(flowMsg.set(flow, 2));        // Send flow value to gw
            }
      
            //Serial.print("g/min:");
            // Serial.println(flow);
            oldflow = flow;
          }
      
          // No Pulse count in 2min 
          if(currentTime - lastPulse > 20000){
            flow = 0;
          } 
      
      
          // Pulse count has changed
          if (pulseCount != oldPulseCount) {
            gw.send(pcMsg.set(pulseCount));                  // Send  volumevalue to gw VAR1
            double volume = ((double)pulseCount/((double)PULSE_FACTOR)*264.172);
            //double volume = ((double)pulseCount/((double)PULSE_FACTOR));     
            oldPulseCount = pulseCount;
            if (volume != oldvolume) {
              gw.send(volumeMsg.set(volume, 3));               // Send volume value to gw
              oldvolume = volume;
            } 
          }
          lastSend = currentTime;
        } 
        else if (sendTime) {
          // No count received. Try requesting it again
          gw.request(CHILD_ID, V_VAR1);
          lastSend=currentTime;
        }
      
        if (SLEEP_MODE) {
          gw.sleep(SEND_FREQUENCY);
        } 	
      
      
      }
      
      
      void onPulse()     
      { 
        if (!SLEEP_MODE) {
          unsigned long newBlink = micros();   
          unsigned long interval = newBlink-lastBlink;
          lastPulse = millis();
          if (interval < 2080) {       // Sometimes we get interrupt on RISING,  500000 = 0.5sek debounce ( max 120 l/min)  WAS 2080
            return;   
          }
      
          flow = ((60000000.0 /interval) / ppl)*.264172;
          //flow = ((60000000.0 /interval) / ppl);
          // Serial.print("interval:");
          // Serial.println(interval);
          lastBlink = newBlink;
          // Serial.println(flow, 4);
        }
        pulseCount++;
      
      }
      
      void incomingMessage(const MyMessage &message) {
        if (message.type==V_VAR1) {  
          pulseCount = oldPulseCount = message.getLong();
          Serial.print("Received last pulse count from gw:");
          Serial.println(pulseCount);
          pcReceived = true;
        }
        if (message.type==V_LIGHT) {
          // Change relay state
          digitalWrite(message.sensor-1+RELAY_1, message.getBool()?RELAY_ON:RELAY_OFF);
          // Store state in eeprom
          gw.saveState(message.sensor, message.getBool());
          // Write some debug info
          Serial.print("Incoming change for sensor:");
          Serial.print(message.sensor);
          Serial.print(", New status: ");
          Serial.println(message.getBool());
        } 
      
      }
      
      posted in Development
      tbully
      tbully
    • RE: Iboard - Cheap Single board Ethernet Arduino with Radio

      To close the loop on this (and to help future dwellers), a new board solved the issue. Not sure what wasn't working properly on the old board but I'm up and running again (with the same old radio, supply, etc).

      Also, since I've learned a little and now understand a few of the configs better since my original iBoard build, I was able to do this WITHOUT the hardware mod.

      I set the following in MyConfig.H:

      const uint8_t SOFT_SPI_MISO_PIN = 6; 
      const uint8_t SOFT_SPI_MOSI_PIN = 5; 
      const uint8_t SOFT_SPI_SCK_PIN = 7;
      

      My failure from several months ago was not setting the CE and SS pins properly in my sketch. I also took @Dwalt 's advice and updated my inclusion and LED pins (even though I didn't use them):

      #define INCLUSION_MODE_TIME 1 // Number of minutes inclusion mode is enabled
      #define INCLUSION_MODE_PIN  14 // Digital pin used for inclusion mode button A0
      
      #define RADIO_CE_PIN        3  // radio chip enable
      #define RADIO_SPI_SS_PIN    8  // radio SPI serial select
      
      #define RADIO_ERROR_LED_PIN 15  // Error led pin A1
      #define RADIO_RX_LED_PIN    16  // Receive led pin A2
      #define RADIO_TX_LED_PIN    17  // the PCB, on board LED A3
      posted in Hardware
      tbully
      tbully
    • RE: Laser Christmas Light Control - 433MHZ

      @petewill ARGH! Of course! That was it! OK, this should get me going for a bit. Thanks so much!

      I will work on this more and report back! Love these forums and how helpful they are. Hopefully, I will be able to return the favor someday!

      posted in General Discussion
      tbully
      tbully
    • RE: [Tutorial] Raspberry Pi NRF24l01 direct connection

      @mfalkvidd said in Step-by-step procedure to connect the NRF24L01 to the GPIO pins and use the Raspberry as a Serial Gateway.:

      @Eawo Yes, it should work. I ran Domoticz and MySensors Gateway on my Raspberry Pi 1 when I first tried MySensors. If I remember correctly I had to connect CE to pin 15 instead of 22 but I am not sure why. Try using the same connections as on your Raspberry Pi 2 first, and switch CE pin if you get "check wires". Please report back here how it goes, so I can add the necessary information to the original post.

      For what it's worth, this is correct. I'm currently running on a Pi 1 and put CE on 15.

      I followed these instructions and it worked perfectly with no fuss: http://forum.mysensors.org/topic/1151/tutorial-raspberry-pi-nrf24l01-direct-connection

      posted in Controllers
      tbully
      tbully
    • RE: How to scan rf remote

      Echoing what @emc2 said. RCSwitch worked great for my 433 project a few months ago.

      https://forum.mysensors.org/topic/4962/laser-christmas-light-control-433mhz/14

      posted in Development
      tbully
      tbully