Serial gateway with several sensors connected to it
-
@AWI
1: Yes it is, baudrate 115200
2: OK
3: I am using software serial at 9600(long cables) instead of 485 because then i dont need extra hardware.
4: yes, LDR,6 rgb strip,IR sender,IR emitter are connected directlySo from there on...
1: How to modify the code to use software serial instead of radio/485?
2:
bar.ino should then have:MyMessage msgWine(CHILD_ID_SPRIT, V_STATUS); //and in the loop gw.send(msgWine.set(0)); #ifdef MY_DEBUG Serial.println("Sprit opp"); #endifNow it will send that message out everytime the button is pressed, so I need to modify the code a bit to only send it out if it once every 12s(yes you need to hold the button for 12s to run the motor to the end.) I guess the best would be to rewrite the arduino code so that a single push on the button runs the motor for 12s instead of holding it in for 12s.
Thanks for the help so far...
@skatun I have never used a wired connection between two nodes but reading from the RS485 thread it sounds like this class is using the arduino HW serial implementation.
Guess you will need to take a deep dive in the code to change this... -
@skatun: Have a look at this example: https://github.com/mysensors/Arduino/blob/development/libraries/MySensors/examples/GatewaySerialRS485/GatewaySerialRS485.ino
I don't think you have to change the code, just interconnect both Arduinos and keep in mind that PIN 2 is used by the library for DE-PIN management, which you don't need, but can't use for other things.
-
@skatun: Have a look at this example: https://github.com/mysensors/Arduino/blob/development/libraries/MySensors/examples/GatewaySerialRS485/GatewaySerialRS485.ino
I don't think you have to change the code, just interconnect both Arduinos and keep in mind that PIN 2 is used by the library for DE-PIN management, which you don't need, but can't use for other things.
@TimO
From the link:- Arduino Uno 9 8 10
Can I not use rx/tx on my node arduino? (Pin 0/1)
Same goes for my gateway, currently I am using pin 10/11. If I can fix this in software it would be better, then i dont have to resolder my setup, also what happens when you have two rs232 nodes connected to the gateway?
-
In the example SoftSerial (a library) is used and not hardware serial (Pin 0/1).
The node could use hardware serial, if you disable debug and look into the thread about RS485. If I recall it correctly there is a hardware serial implementation but you have to implement it yourself, this is not covered by the library.The GatewaySerialRS485 uses SoftSerial on the connection to the nodes and HardwareSerial on the connection to the controller.
Node <-- (SoftSerial) --> Gateway <-- (HardSerial) --> Controller
With RS485 you're able interconnect more than two devices and use DE_PIN before transmitting data. With RS232 you're limited to two devices or are in need of additional SoftSerial / HardSerial (and therefore additional PINs) depending on your hardware.
-
In the example SoftSerial (a library) is used and not hardware serial (Pin 0/1).
The node could use hardware serial, if you disable debug and look into the thread about RS485. If I recall it correctly there is a hardware serial implementation but you have to implement it yourself, this is not covered by the library.The GatewaySerialRS485 uses SoftSerial on the connection to the nodes and HardwareSerial on the connection to the controller.
Node <-- (SoftSerial) --> Gateway <-- (HardSerial) --> Controller
With RS485 you're able interconnect more than two devices and use DE_PIN before transmitting data. With RS232 you're limited to two devices or are in need of additional SoftSerial / HardSerial (and therefore additional PINs) depending on your hardware.
@TimO
I will look into it, however first I need to get the gateway up running.So I am struggling to see how locally attached sensors work. I guess (reading several forum entry) that gw object is not needed. What is this inclusion mode? Is that part of the code needed?
However I can not get my code to compile:
#include <SPI.h> #include <MySensor.h> // Enable debug prints to serial monitor #define MY_DEBUG // Enable serial gateway #define MY_GATEWAY_SERIAL // 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 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 INTERRUPT DIGITAL_INPUT_SENSOR-2 // Usually the interrupt = pin -2 (on uno/nano anyway) #define CHILD_ID 9 // Id of the sensor child unsigned long SEND_FREQUENCY = 20000; // Minimum time between send (in milliseconds). We don't wnat to spam the gateway. MySensor gw; 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,V_WATT); MyMessage kwhMsg(CHILD_ID,V_KWH); MyMessage pcMsg(CHILD_ID,V_VAR1); void setup() { attachInterrupt(INTERRUPT, onPulse, RISING); lastSend=millis(); } void presentation() { // Present locally attached sensors here // Register this device as power sensor gw.present(CHILD_ID, S_POWER,"Energy Meter"); } void loop() { gw.process(); 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)) { gw.send(wattMsg.set(watt)); // Send watt value to gw } //Serial.print("Watt:"); //Serial.println(watt); oldWatt = watt; } // Pulse cout has changed if (pulseCount != oldPulseCount) { //gw.send(pcMsg.set(pulseCount)); // Send pulse count value to gw double kwh = ((double)pulseCount/((double)PULSE_FACTOR)); oldPulseCount = pulseCount; if (kwh != oldKwh) { gw.send(kwhMsg.set(kwh, 4)); // Send kwh value to gw oldKwh = kwh; } } lastSend = now; } else if (sendTime && !pcReceived) { // No count received. Try requesting it again request(CHILD_ID, V_VAR1); lastSend=now; } if (SLEEP_MODE) { sleep(SEND_FREQUENCY); } } 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; } } void onPulse() { if (!SLEEP_MODE) { 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++; } -
@TimO
I will look into it, however first I need to get the gateway up running.So I am struggling to see how locally attached sensors work. I guess (reading several forum entry) that gw object is not needed. What is this inclusion mode? Is that part of the code needed?
However I can not get my code to compile:
#include <SPI.h> #include <MySensor.h> // Enable debug prints to serial monitor #define MY_DEBUG // Enable serial gateway #define MY_GATEWAY_SERIAL // 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 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 INTERRUPT DIGITAL_INPUT_SENSOR-2 // Usually the interrupt = pin -2 (on uno/nano anyway) #define CHILD_ID 9 // Id of the sensor child unsigned long SEND_FREQUENCY = 20000; // Minimum time between send (in milliseconds). We don't wnat to spam the gateway. MySensor gw; 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,V_WATT); MyMessage kwhMsg(CHILD_ID,V_KWH); MyMessage pcMsg(CHILD_ID,V_VAR1); void setup() { attachInterrupt(INTERRUPT, onPulse, RISING); lastSend=millis(); } void presentation() { // Present locally attached sensors here // Register this device as power sensor gw.present(CHILD_ID, S_POWER,"Energy Meter"); } void loop() { gw.process(); 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)) { gw.send(wattMsg.set(watt)); // Send watt value to gw } //Serial.print("Watt:"); //Serial.println(watt); oldWatt = watt; } // Pulse cout has changed if (pulseCount != oldPulseCount) { //gw.send(pcMsg.set(pulseCount)); // Send pulse count value to gw double kwh = ((double)pulseCount/((double)PULSE_FACTOR)); oldPulseCount = pulseCount; if (kwh != oldKwh) { gw.send(kwhMsg.set(kwh, 4)); // Send kwh value to gw oldKwh = kwh; } } lastSend = now; } else if (sendTime && !pcReceived) { // No count received. Try requesting it again request(CHILD_ID, V_VAR1); lastSend=now; } if (SLEEP_MODE) { sleep(SEND_FREQUENCY); } } 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; } } void onPulse() { if (!SLEEP_MODE) { 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++; }@skatun it looks like you are mixing the development version 2.0 and master branch 1.5 syntax. In development the "class" setup is removed and therefore for "gw." is not used anymore.
Most of the examples use the gw. Structure though. Look at the samples in the development branch as you will probably want/need the new functionality
-
@skatun it looks like you are mixing the development version 2.0 and master branch 1.5 syntax. In development the "class" setup is removed and therefore for "gw." is not used anymore.
Most of the examples use the gw. Structure though. Look at the samples in the development branch as you will probably want/need the new functionality
@AWI
So I copied ower evrything in the library folder of the development branch. When i then try to compile the serial gateway i get this error:Arduino: 1.6.7 (Windows 7), Board: "NodeMCU 1.0 (ESP-12E Module), 80 MHz, Serial, 115200, 4M (3M SPIFFS)" In file included from C:\Program Files (x86)\Arduino\libraries\MySensors\examples\SerialGateway\SerialGateway.ino:50:0: C:\Program Files (x86)\Arduino\libraries\MySensors/MySensor.h:285:4: error: #error No forward link or gateway feature activated. This means nowhere to send messages! Pretty pointless. #error No forward link or gateway feature activated. This means nowhere to send messages! Pretty pointless. ^ In file included from C:\Program Files (x86)\Arduino\libraries\MySensors\examples\SerialGateway\SerialGateway.ino:52:0: C:\Program Files (x86)\Arduino\libraries\PinChangeInt/PinChangeInt.h:103:19: fatal error: new.h: No such file or directory #include <new.h> ^ compilation terminated. exit status 1 Error compiling. This report would have more information with "Show verbose output during compilation" enabled in File > Preferences. -
@AWI
So I copied ower evrything in the library folder of the development branch. When i then try to compile the serial gateway i get this error:Arduino: 1.6.7 (Windows 7), Board: "NodeMCU 1.0 (ESP-12E Module), 80 MHz, Serial, 115200, 4M (3M SPIFFS)" In file included from C:\Program Files (x86)\Arduino\libraries\MySensors\examples\SerialGateway\SerialGateway.ino:50:0: C:\Program Files (x86)\Arduino\libraries\MySensors/MySensor.h:285:4: error: #error No forward link or gateway feature activated. This means nowhere to send messages! Pretty pointless. #error No forward link or gateway feature activated. This means nowhere to send messages! Pretty pointless. ^ In file included from C:\Program Files (x86)\Arduino\libraries\MySensors\examples\SerialGateway\SerialGateway.ino:52:0: C:\Program Files (x86)\Arduino\libraries\PinChangeInt/PinChangeInt.h:103:19: fatal error: new.h: No such file or directory #include <new.h> ^ compilation terminated. exit status 1 Error compiling. This report would have more information with "Show verbose output during compilation" enabled in File > Preferences. -
@skatun It's hard to tell (for me ;-)) from the messages what is going wrong. Which Arduino are you programming for? Are you using the "GatewaySerial.ino" sketch from the development branch examples?
-
@AWI
I just copied all the files in libraries and hardware in the development zip into c:\program files\Arduino\I am trying to get it to run on arduino due and yes I was trying the run the Serial gateway in Library\My Sensor\SerialGateway
-
Hi @skatun did you check this http://www.mysensors.org/about/arduino#installing-the-sensor-libraries ? You install it the same way but download it from https://github.com/mysensors/Arduino (press Download ZIP) and make sure its Branch: Development.
-
Hi @skatun did you check this http://www.mysensors.org/about/arduino#installing-the-sensor-libraries ? You install it the same way but download it from https://github.com/mysensors/Arduino (press Download ZIP) and make sure its Branch: Development.
Well I tried to save it both here:
C:\Program Files (x86)\Arduino\libraries\Mysensor
C:\Program Files (x86)\Arduino\hardware\MySensorsAs well as here as described in your link:
C:\Users\kim\Documents\ArduinoBut I get compile errors no matter where I try to compile serialgateway on due which I found in the C:\Program Files (x86)\Arduino\libraries\MySensors\examples\SerialGateway
Cheers
-
@skatun having the files in multiple folders isnt a good idea.
Maybe you should remove the IDE and all folders and start over? -
@skatun having the files in multiple folders isnt a good idea.
Maybe you should remove the IDE and all folders and start over?@sundberg84
So the IDE by default get installed C:\Program Files (x86)\Arduino but the files folder get default set to this:C:\Users\kim\Documents\Arduino
I guess arduino made it that way so that you can load examples from C:\Program Files (x86)\Arduino then mess around with them and save them here C:\Users\kim\Documents\Arduino
So I never had duplicate files, i tried both locations without sucsess. So which version of the IDE should I use? 1.6.7 is what I have now.
-
@skatun Dont know if there are any version conflicts at the moment.
I dont have the latest version. -
@skatun Dont know if there are any version conflicts at the moment.
I dont have the latest version.@sundberg84
So which directory should i put the files in? BOth hardware and library? -
I install the ide. download and extract mys to same path as ide. That's it.
-
I install the ide. download and extract mys to same path as ide. That's it.
I will then delete C:\Users\kim\Documents\Arduino which the ide creates.. Will upgrtade today, and let you know how it goes
-
I will then delete C:\Users\kim\Documents\Arduino which the ide creates.. Will upgrtade today, and let you know how it goes
Default libraries included in the IDE
User libraries
Its not uncommon to have compile issues when:
-
The IDE is not restarted after uncompressing/copy file to the libraries
-
When upgrading MySensors without deleting the old version first
I have Arduino IDE 1.6.4
Cheers
-
-
Default libraries included in the IDE
User libraries
Its not uncommon to have compile issues when:
-
The IDE is not restarted after uncompressing/copy file to the libraries
-
When upgrading MySensors without deleting the old version first
I have Arduino IDE 1.6.4
Cheers
-