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
skatunS

Kim Skåtun

@skatun
About
Posts
63
Topics
8
Shares
0
Groups
0
Followers
1
Following
1

Posts

Recent Best Controversial

  • RS485/RS232/Serial transport class for mysensors.org
    skatunS skatun

    Today the new rs485 shield arrived, i will solder it up over the weekend and start testing early next week:)

    Development rs485 serial rs485

  • Power Measurements
    skatunS skatun

    i came across this one: https://github.com/FriedCircuits/ADE7753/tree/master/ADE7753_Breakout_v.2

    I want it in this form

    alt text

    http://download.schneider-electric.com/files?p_Reference=CA9SS048E&p_EnDocType=Application solutions&p_File_Id=5047423337&p_File_Name=CA9SS048E (web).pdf

    or something like this
    https://www.aliexpress.com/item/Free-shipping-DDS6866-5-30-A-230V-50HZ-Single-phase-Din-rail-KWH-Watt-hour-din/32324079915.html?spm=2114.01010208.3.54.D7Ft8i&ws_ab_test=searchweb0_0,searchweb201602_1_116_10065_117_10068_114_115_113_10000009_10084_10083_10080_10082_10081_10060_10061_10062_10056_10055_10054_10059_10099_10078_10079_427_10103_10073_10102_10096_10052_10050_10051-10102,searchweb201603_9,afswitch_3&btsid=81065051-9d8f-4742-afff-05bace226fa6

    or this one, but it seems to output serial data, how many software serial can you have on one arduino?
    https://www.aliexpress.com/item/Mini-Multifuncion-power-energy-amp-voltage-monitor-meter-communication-module-with-CT-coil-AC-80-260V/32512169668.html?spm=2114.01010208.3.156.Hh7LxY&ws_ab_test=searchweb0_0,searchweb201602_1_116_10065_117_10068_114_115_113_10000009_10084_10083_10080_10082_10081_10060_10061_10062_10056_10055_10054_10059_10099_10078_10079_427_10103_10073_10102_10096_10052_10050_10051-10050_114,searchweb201603_9,afswitch_3&btsid=810667df-39e8-4801-a123-f3cd7ca3456a

    Hardware

  • Power Measurements
    skatunS skatun

    @Yveaux which power meter ic do you suggest?

    Hardware

  • Power Measurements
    skatunS skatun

    @Talat-Keleş I am not going to use 230V to power the arduino.

    The point is to get power you need P=U*I and for accuracy U is not 220V but varies quite a bit(210-230 typ), hence you need to measure it.

    So for
    current: 20A +-0.01A
    voltage: 220+-0.1V

    we will get 20/1024 *220 = 5W resolution. In addition we need to add accuracy of sensors, so lets say 7W, so then if we pull 300W, we have only 300W+-23%..

    So maybe we need to add an adc(10bit) or skip mesuring peaks(10A sensor?)

    I have 20 circuit breakers so I can easily measure how much: heating is using,water heater, oven top etc...

    Hardware

  • Power Measurements
    skatunS skatun

    Hi everyone,
    I would like to measure my electric power usage in my flat. In my fusebox I have several fuses like this one,
    alt text

    Does other have same kind of fuses?

    So reading on the forum here and other places, to achieve some kind of realistic result you need measure both current and voltage. So my idea is to make a small pcb with two tabs that fits in the fuse(put wires and pcb int he screw terminals on the fuse) in order to measure voltage, then for one of the wire it goes through one of this:
    alt text

    As output from the pcb it will then be 2 analog signal between 0-5v and it needs 5v and gnd so the interface will be some kind of 4 pin connector(rj11 or screw terminals).

    So I was wondering if others might have interest of such a sensor, then I would also like input of which sensor to use(I guess 20 A sensor such as TA12-100 for current) but what to use for voltage sensing, just resistors?
    alt text

    I hope such a pcb fully assembled would come out below 10usd.

    Then lets say you have 6 fuses you wire up 6 of these pcb to one arduino nano node, which then transmit both current and voltage to the gatway.

    Hardware

  • rs485 on nano
    skatunS skatun

    @wimd include debug and remove inclusion from the sketches and it should be ok. I have ordered new rs485 shield, i expect that to be the issue..

    General Discussion

  • rs485 on nano
    skatunS skatun

    Implemented fixed node ID without success, I think maybe the rs485 adapter on gateway is broken, will test more tomorrow

    General Discussion

  • rs485 on nano
    skatunS skatun

    @pjr @consul58 Have been away the last 5 days, will update the thread with the result tomorrow. Can anyone lighten me up on benefit of having inclusion button, and what inclusion time should be set to?

    General Discussion

  • rs485 on nano
    skatunS skatun

    @dbemowsk so i added the usb device, it produces gibberish:

    ~þx
    

    different baud-rates, gibberish changes.....

    gibberish from the node, but nothing from gateway, I also changed gateway to uno as a test without success, here is the code on gateway which i commented out:

    
    // Flash leds on rx/tx/err
    //#define MY_LEDS_BLINKING_FEATURE
    // Set blinking period
    //#define MY_DEFAULT_LED_BLINK_PERIOD 300
    
    // Enable inclusion mode
    //#define MY_INCLUSION_MODE_FEATURE
    // Enable Inclusion mode button on gateway
    //#define MY_INCLUSION_BUTTON_FEATURE
    // Set inclusion mode duration (in seconds)
    //#define MY_INCLUSION_MODE_DURATION 60 
    // Digital pin used for inclusion mode button
    //#define MY_INCLUSION_MODE_BUTTON_PIN  3 
    
    //#define MY_DEFAULT_ERR_LED_PIN 4  // Error led pin
    //#define MY_DEFAULT_RX_LED_PIN  5  // Receive led pin
    //#define MY_DEFAULT_TX_LED_PIN  6  // the PCB, on board LED
    
    General Discussion

  • rs485 on nano
    skatunS skatun

    @dbemowsk What do you mean by + to + and - to - between nodes.? Isnt that just to power the max 485 chip?

    I do have a usb dongle like u mentioned laying around somewhere, so I can just add that as a 3rd rs485 node, and use arduino serial monitor for it?

    on the gateway i commented all the led and inclusion code, this doesnt effect the rs485 right?

    My setup is shown below:
    0_1481507952218_IMG_20161212_014106.jpg

    @m26872 I have now enabled debug mode, see output below

    0_1481508017785_Capture.JPG

    General Discussion

  • rs485 on nano
    skatunS skatun

    hi,
    I haved hooked up a mega as my serial to rs485 gateway, it shows nicely up in my myscontroller as node0-gateway, to this I have connected a rs485 shield(same as here: https://www.mysensors.org/build/rs485)
    so i connected DE and RE on shield to digital pin 2
    on gateway i connected DI to 46 and R0 to 48 similiar my node which is nano is connected with DI to 9 and R0 to 8. They have not vcc or GND in common.

    I downloaded the gateway and motion sensor example from link above, but the motion sensor node does not show up, did I wire something wrong?

    General Discussion

  • Serial gateway, which example to follow??
    skatunS skatun

    @tekka Thats correct, i am only running locally attached sensor:) I was luckily enough to run sth like 35 cables to my gateway, I might add radio in the future to reach down to my basement.

    Development

  • Serial gateway, which example to follow??
    skatunS skatun

    @tekka Thanks for the feedback, does that implies if I download the dev branch from git now it should be fixed?

    here is the output from my serial monitor when i enabled logging:

    0;255;3;0;9;Starting gateway (R-NGA-, 2.0.0-beta)
    0;255;3;0;14;Gateway startup complete.
    0;2;2;0;24;
    0;255;3;0;9;No registration required
    0;255;3;0;9;Init complete, id=0, parent=0, distance=0, registration=1
    0;2;2;0;24;
    

    I am trying to get my RGB lights to work:

    
    #define CHILD_ID_RGB_START 30
    #define NUM_LEDS_STRIPS 5
    
    void presentation() {
      // Present locally attached sensors
    
      //RGB 0,30,1,0,40,ff0000\n
      sendSketchInfo("RGB Led", "1.2");
      Serial.println("Lets present some RGB");
      for (byte CHILD_ID_RGB = CHILD_ID_RGB_START; CHILD_ID_RGB < NUM_LEDS_STRIPS; CHILD_ID_RGB++) {
        Serial.print("RGB ID: ");
        Serial.println(CHILD_ID_RGB);
        present(CHILD_ID_RGB, S_RGB_LIGHT);
      }
    

    How can I add logging to Serial monitor to gateway, because Serial.println("Lets present some RGB"); does not produce any output?

    shouldn't this line registered my lights as sensors in MYSController?

    
    present(CHILD_ID_RGB, S_RGB_LIGHT);
    

    So I am afraid there is something wrong with my for loop, even though i can not spot the mistake.

    Development

  • Serial gateway, which example to follow??
    skatunS skatun

    @hek
    I am making great progress on my gateway:) I am almost done wiring everything and software is coming along. So my sensors sends out data nicely to the controller, however I can not receive commands, which is essentials for my RGB led strips.

    I am trying to send this from the Serial Monitor in arduino: 0,30,1,0,40,ff0000\n

    However the received method never gets called, what am I missing?

    // Enable debug prints to serial monitor
    //#define MY_DEBUG
    
    // Enable serial gateway
    #define MY_GATEWAY_SERIAL
    
    
    #include <SoftwareSerial.h>
    #include <SPI.h>
    #include <MySensors.h>
    #include <ChainableLED.h>
    
    SoftwareSerial mySerial(10, 11); // RX, TX
    
    
    MyMessage msg1(1, V_LIGHT);
    
    //RGB
    int NUM_LEDS = 34;
    ChainableLED leds(5, 6, NUM_LEDS);  // CLK, DATA, LEDS
    
    //PowerMeter
    #define DIGITAL_INPUT_SENSOR 3  // The digital input you attached your light sensor.  (Only 2 and 3 generates interrupt!)
    #define PULSE_FACTOR 1000       // Nummber of blinks per KWH of your meeter
    #define SLEEP_MODE false        // Watt-value can only be reported when sleep mode is false.
    #define MAX_WATT 10000          // Max watt value to report. This filetrs outliers.
    
    
    #define CHILD_ID_POWER 2       // Id of the sensor child
    #define CHILD_ID_RGB_START 30
    #define NUM_LEDS_STRIPS 5
    
    
    int counter[NUM_LEDS_STRIPS];
    int current[NUM_LEDS_STRIPS][3];
    int step[NUM_LEDS_STRIPS][3];
    
    
    unsigned long SEND_FREQUENCY = 20000; // Minimum time between send (in milliseconds). We don't wnat to spam the gateway.
    double ppwh = ((double)PULSE_FACTOR) / 1000; // Pulses per watt hour
    boolean pcReceived = false;
    volatile unsigned long pulseCount = 0;
    volatile unsigned long lastBlink = 0;
    volatile unsigned long watt = 0;
    unsigned long oldPulseCount = 0;
    unsigned long oldWatt = 0;
    double oldKwh;
    unsigned long lastSend;
    MyMessage wattMsg(CHILD_ID_POWER, V_WATT);
    MyMessage kwhMsg(CHILD_ID_POWER, V_KWH);
    MyMessage pcMsg(CHILD_ID_POWER, V_VAR1);
    
    
    void setup() {
    
      //Set up all our software serial ports...
      mySerial.begin(9600);
      // Setup locally attached sensors
    
    
      //RGB
    
      leds.init();
      for (byte CHILD_ID_RGB = CHILD_ID_RGB_START; CHILD_ID_RGB < NUM_LEDS_STRIPS; CHILD_ID_RGB++) {
        counter[CHILD_ID_RGB] = 0;
        current[CHILD_ID_RGB][0] = 0;
        current[CHILD_ID_RGB][1] = 0;
        current[CHILD_ID_RGB][2] = 0;
        step[CHILD_ID_RGB][0] = 0;
        step[CHILD_ID_RGB][1] = 0;
        step[CHILD_ID_RGB][2] = 0;
        leds.setColorRGB(CHILD_ID_RGB, current[CHILD_ID_RGB][0], current[CHILD_ID_RGB][1], current[CHILD_ID_RGB][2]); // Turn of on startup
      }
    
    
      // Power Meter
      // Fetch last known pulse count value from gw
      request(CHILD_ID_POWER, V_VAR1);
    
      // Use the internal pullup to be able to hook up this sketch directly to an energy meter with S0 output
      // If no pullup is used, the reported usage will be too high because of the floating pin
      pinMode(DIGITAL_INPUT_SENSOR, INPUT_PULLUP);
    
      attachInterrupt(digitalPinToInterrupt(DIGITAL_INPUT_SENSOR), onPulse, RISING);
      lastSend = millis();
    
    }
    
    void presentation() {
      // Present locally attached sensors
    
      //RGB 0,30,1,0,40,ff0000\n
      sendSketchInfo("RGB Led", "1.2");
      for (byte CHILD_ID_RGB = CHILD_ID_RGB_START; CHILD_ID_RGB < NUM_LEDS_STRIPS; CHILD_ID_RGB++) {
        present(CHILD_ID_RGB, S_RGB_LIGHT);
      }
    
    
      //RELAY
      sendSketchInfo("Relay & Button", "1.0");
    
      // Register all sensors to gw (they will be created as child devices)
      present(1, S_LIGHT);
    
    
      //POWER METER
      // Send the sketch version information to the gateway and Controller
      sendSketchInfo("Energy Meter", "1.0");
    
      // Register this device as power sensor
      present(CHILD_ID_POWER, S_POWER);
    
    
    }
    
    void loop() {
      // Send locally attached sensor data here
      //send(msg1.set(true), true); // Send new state and request ack back
      if (mySerial.available()) {
        Serial.write(mySerial.read());
      }
    
      //RGB
      for (byte CHILD_ID_RGB = CHILD_ID_RGB_START; CHILD_ID_RGB < NUM_LEDS_STRIPS; CHILD_ID_RGB++) {
        if (counter[CHILD_ID_RGB] >= 0) {
          counter[CHILD_ID_RGB]--;
          int i = 1020 - counter[CHILD_ID_RGB];
          current[CHILD_ID_RGB][0] = calculateVal(step[CHILD_ID_RGB][0], current[CHILD_ID_RGB][0], i);
          current[CHILD_ID_RGB][1] = calculateVal(step[CHILD_ID_RGB][1], current[CHILD_ID_RGB][1], i);
          current[CHILD_ID_RGB][2] = calculateVal(step[CHILD_ID_RGB][2], current[CHILD_ID_RGB][2], i);
    
          leds.setColorRGB(CHILD_ID_RGB, current[CHILD_ID_RGB][0], current[CHILD_ID_RGB][1], current[CHILD_ID_RGB][2]);
        }
      }
    
      //POWER
      unsigned long now = millis();
      // Only send values at a maximum frequency or woken up from sleep
      bool sendTime = now - lastSend > SEND_FREQUENCY;
      if (pcReceived && (SLEEP_MODE || sendTime)) {
        // New watt value has been calculated
        if (!SLEEP_MODE && watt != oldWatt) {
          // Check that we dont get unresonable large watt value.
          // could hapen when long wraps or false interrupt triggered
          if (watt < ((unsigned long)MAX_WATT)) {
            send(wattMsg.set(watt));  // Send watt value to gw
          }
          Serial.print("Watt:");
          Serial.println(watt);
          oldWatt = watt;
        }
    
        // Pulse cout has changed
        if (pulseCount != oldPulseCount) {
          send(pcMsg.set(pulseCount));  // Send pulse count value to gw
          Serial.print("PulseCount:");
          Serial.println(pulseCount);
          double kwh = ((double)pulseCount / ((double)PULSE_FACTOR));
          oldPulseCount = pulseCount;
          if (kwh != oldKwh) {
            send(kwhMsg.set(kwh, 4));  // Send kwh value to gw
            oldKwh = kwh;
            Serial.print("KWh:");
            Serial.println(kwh);
          }
        }
        lastSend = now;
      } else if (sendTime && !pcReceived) {
        // No count received. Try requesting it again
        request(CHILD_ID_POWER, V_VAR1);
        Serial.println("requesting a new value");
        lastSend = now;
      }
    
    }
    
    
    
    //PowerMeter
    void onPulse() {
      unsigned long newBlink = micros();
      unsigned long interval = newBlink - lastBlink;
      if (interval < 10000L) { // Sometimes we get interrupt on RISING
        return;
      }
      watt = (3600000000.0 / interval) / ppwh;
      lastBlink = newBlink;
    
      pulseCount++;
    }
    
    //RGB
    void setColor(byte led, int R, int G, int B) {
      step[led][0] = calculateStep(current[led][0], R);
      step[led][1] = calculateStep(current[led][1], G);
      step[led][2] = calculateStep(current[led][2], B);
    
      counter[led] = 255;
    }
    
    int calculateStep(int prevValue, int endValue) {
      int step = endValue - prevValue; // What's the overall gap?
      if (step) {                      // If its non-zero,
        step = 255 / step;            //   divide by 1020
      }
      return step;
    }
    
    int calculateVal(int step, int val, int i) {
    
      if ((step) && i % step == 0) { // If step is non-zero and its time to change a value,
        if (step > 0) {              //   increment the value if step is positive...
          val += 1;
        }
        else if (step < 0) {         //   ...or decrement it if step is negative
          val -= 1;
        }
      }
      // Defensive driving: make sure val stays in the range 0-255
      if (val > 255) {
        val = 255;
      }
      else if (val < 0) {
        val = 0;
      }
      return val;
    }
    
    
    
    
    
    void receive(const MyMessage & msg) {
      Serial.println("Hello");
    
      //send(msg1.set(true), true);
    
      if (msg.type == V_RGB) {
        String hexstring = msg.getString();
        long number = (long) strtol( &hexstring[0], NULL, 16);
        int colorR = number >> 16;
        int colorG = number >> 8 & 0xFF;
        int colorB = number & 0xFF;
    
        // Write some debug info
        Serial.print("Incoming change for sensor:");
        Serial.print(msg.sensor);
        Serial.print(", Red: ");
        Serial.print(colorR);
        Serial.print(", Green: ");
        Serial.print(colorG);
        Serial.print(", Blue: ");
        Serial.print(colorB);
        Serial.print(", New status: ");
        Serial.println(msg.getString());
    
        setColor(msg.sensor, colorR, colorG, colorB);
        //leds.setColorRGB(message.sensor, colorR, colorG, colorB);
      }
    
      //POWER
      if (msg.type == V_VAR1) {
        pulseCount = oldPulseCount = msg.getLong();
        Serial.print("Received last pulse count from gw:");
        Serial.println(pulseCount);
        pcReceived = true;
      }
    
      //Locally attached sensor......
      if (msg.destination == 0) {
    
      }
    
      //We forward our message on software serial
      else if (msg.destination == 10) {
        Serial.println("halla 3");
        //mySerial.write(msg.getStream()); //is this the complete message??
      }
    
      // send it out on the radio modem, to be implemented later
      else {
    
      }
    
    }
    
    Development

  • Serial gateway, which example to follow??
    skatunS skatun

    @AWI

    Quote:"means of the wired protocol"
    I was so fortunate that I could connect most of my nodes and sensors wired, more reliable, no need to change battery so I tried todo so with most of my nodes and sensors.

    Quote : "Then if you want to combine this with radio communication you need a different gateway"
    Why do I need two gateways, why cant one gateway handle both wired and radio? For now I don't need the radio, just locally and wired connection

    Quote:" Each of these nodes needs a different node number."
    Yupp thats why I try to give them static node numbers: So the one on balcony gets ID 11 the one in the bar is 13 and so on. (my idea was to group ID numbers, 0 locally sensor, 10-19 software serial, >20 radio nodes, >50 wifi nodes ,>70 rs485 nodes)

    The benefit of using MySensor is that the Openhab has a binding for it, I can use the example codes for my nodes(like the relay with button sketch) and I need some format of the string sended/received from the controller to my nodes anyway, so why not use the mysensor format?

    so My orignally Idea was to use the serial event:

    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;
        }
      }
    }
    

    and then use the Message class to split the input buffer the string based "," like in vba I would just use arrayMy = split(inputBuffer,",")

    Then If ID=11 forward the whole thing to software serial to the balcony, then the code on that node would be exactly the same as if the message came over the radio link.

    That was my orginally idea, but then @hek suggested that I should rather use the receive method since this grab the buffer from serial somehow.

    I am open to all solutions:) I just have limited space on some of my nodes which makes it hard to implement a radio link on them as well as an rs485 shield. (even using nano is hard)

    Development

  • Serial gateway, which example to follow??
    skatunS skatun

    @AWI
    Basically I have my Gateway(Mega, might swap to Due, higher resolution ADC), on my gateway I have:
    1 radio modem connected,
    7 Arduino nano which are soldered to tx/rx(I might need to resolder those?),
    12 motion sensors,
    1 pulsePowerMeter,
    6 ledstrips
    1 IR generator(simulate my tv /stereo,etc remote)

    So if my controller Openhab:
    sends or receive CHildID = 0 then send/receive data to locally attached sensor
    sends or receive CHildID = 10-16 then send/receive data on software serial to the 7 arduino nano(Basically relay sensor nodes)
    sends or receive CHildID = 20-31 then send/receive data on radio to my radio nodes(temperature mainly)

    My problem is that I can not figure out how to set up software serial with my sensor.

     If msg.destination =16 sendTo software Serial on pin 34
    

    Below is a picture of my Gateway setup:
    0_1468414835666_IMG_20160713_145404[1].jpg

    Development

  • Serial gateway, which example to follow??
    skatunS skatun

    Its not something in the transport class I need to change right?

    Development

  • RS485/RS232/Serial transport class for mysensors.org
    skatunS skatun

    @LeoDesigner
    Hi, I am trying to do almost the same, but I would like to use softwareSerial instead of altsoft. The reason why I would do this is that i can barely fit the arduino nano inside my case, and an additional rs485 module would not fit and that I have 8 nodes connected on the softwareserial . I have tested software serial on arduino and it seems to work fine up to 15meters, I also adjusted the baudrate to 9600 since my node does not send out/receive large amount of data. I read that you did some work on software serial and were wondering if you could take a look at this thread.

    Development rs485 serial rs485

  • Serial gateway, which example to follow??
    skatunS skatun

    @hek
    So finally I got home to grab my arduino so I can do some hardware testing and not just software!

    It seems like the receive method is not running on the gateway, I have read through everything on the library api three times now, but I still can not figure out how the receive method are working. It runs inside the main loop, hence you can not use any sleep routine as far as I understood.
    0_1468333270528_Screenshot_1.png image url)

    What can I do to get the receive method to run?

    Development

  • [SOLVED] Gateway without radio not working on current development branch
    skatunS skatun

    @chrlyra
    If I am not completely wrong, this fix is only to 2.0

    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