In your configuration try leaving the "--my-controller-ip-address=127.0.0.1" out of configuration. Another thing to try is to power the radio connected to the pi by a separate 3.3v power supply. also when i built my first controller/gateway i spent 2 days trying to figure out why it didn't work when in the end it was a bad jumper wire. Unhook everything and double check your wiring. Hope something helps!
Posts made by MGHaff
-
RE: Raspberry Pi Zero W gateway + NRF24L01+ Radio + MQTT - Radio failing
-
RE: edited: 4 diy dimmer module. should i make icsp or serial programming connections, both?
Thanks, I guess what i am trying to find out is how i get my sensors code to use the Adafruit_PWMServoDriver code to do the same as you than. I would like to control 5 sets of RGB strips by 5 separate V_RGB faders in domoticz using my sensors. But i cant figure out how to get mysensors to tell the PCA9685 chip how to controll the channels.
-
RE: edited: 4 diy dimmer module. should i make icsp or serial programming connections, both?
@joerideman what code are you using to run the 9685 chip? I'm looking to build a multi rgb strip controller but having problems finding mysensors code to use as an example to talk to the 9685. Any help is greatly appreciated! thanks.
-
RE: Newbie, adding more than one relay to nodemanager
@user2684 said in Newbie, adding more than one relay to nodemanager:
relay1.setInvertValueToWrite(true);
relay2.setInvertValueToWrite(true);WOW Thanks Again! This is really fun and easy to work with! Thank you!!!!
-
RE: [SOLVED] Raspberry Pi serial gateway NRF24 - !TSM:INIT:TSP FAIL
@badisensors I did try your config and it works just as mine does. Just wondering if the adding this --my-rf24-ce-pin=22 --my-rf24-cs-pin=24 to the config was necessary. But from the my test it is not. Thanks.
-
RE: Newbie, adding more than one relay to nodemanager
@user2684 Another Question.... Thanks in advance!
Where do i put this to get my relay to invert operation?
// [109] Invert the value to write. E.g. if ON is received, write LOW (default: false)
void setInvertValueToWrite(bool value);And how should it be written.
I tried this.
#include <sensors/SensorRelay.h>
SensorRelay relay1(8);
SensorRelay relay2(5);
SensorRelay relay3(6);
SensorRelay relay4(7);
// [109] Invert the value to write. E.g. if ON is received, write LOW (default: false)
SensorRelay setInvertValueToWrite(true); -
RE: [SOLVED] Raspberry Pi serial gateway NRF24 - !TSM:INIT:TSP FAIL
@badisensors 2.0.0 not really 2 years ago more like 1 1/2. Why do you ask?
-
RE: [SOLVED] Raspberry Pi serial gateway NRF24 - !TSM:INIT:TSP FAIL
@badisensors said in Raspberry Pi serial gateway NRF24 - !TSM:INIT:TSP FAIL:
As kebibg said you must also configure the pins for CE and CS. The configure i used was :
--my-transport=rf24 --my-rf24-pa-level=RF24_PA_LOW --my-gateway=serial --my-serial-is-pty --my-serial-port=/dev/ttyUSB020 --my-rf24-ce-pin=22 --my-rf24-cs-pin=24 --my-rf24-irq-pin=15 --my-leds-err-pin=12 --my-leds-rx-pin=16 --my-leds-tx-pin=18
Also you must connect MISO to pin 21, Mosi to pin 19 and CLK to pin 23 on raspberry
The only pin's I needed to specify on my setup was IRQ and leds. The GW has been working great for 2+ years on my raspberry pie 3b with nrf24+.
Why did I Not have to specify them in my setup? did something change? I am running version 2.3.1.
-
RE: [SOLVED] Raspberry Pi serial gateway NRF24 - !TSM:INIT:TSP FAIL
This is what i use to configure my raspberry pi3 to work vi serial.
--my-transport=rf24 --my-rf24-pa-level=RF24_PA_LOW --my-rf24-irq-pin=15 --my-gateway=serial --my-serial-is-pty --my-serial-pty=/dev/ttyUSB020 --my-leds-err-pin=12 --my-leds-rx-pin=16 --my-leds-tx-pin=18
Built using this page. https://www.mysensors.org/build/raspberry
And when recieving this error "Dec 31 11:07:50 DEBUG !TSM:INIT:TSP FAIL" I had found a bad jumper that I had used. Hope This helps!
-
RE: 2 dallas temp + 4 relays
First of all. thank you guys for all the help! here is what i found out. When testing my hardware i found that alone with the MySensors Dallas sensors sketch i would get readings from my Dallas sensors in serial and at controller. With relay sketch alone i would get All 4 relays working in controller and in serial. But combined no Dallas temp in serial or controller. I rewired with new sensors, Arduino nano, radio! Finally digging through my stuff i found a new board from a batch ordered 2 years ago, wired it up on bread board and wallah! Apparently the last batch or boards i ordered must have not passed quality or damaged in shipping!! Thanks again for the support!! On a way brighter note I have address's assigned to my temp sensors now on all my nodes and have learned so much more about the MySensors network!
-
Newbie, adding more than one relay to nodemanager
I just started using nodemanager. GREAT WORK! Might be a dumb question but how do i add more than one relay to the sketch? I would like to control 4 but only can get one to work. Thanks in advance!
-
RE: 2 dallas temp + 4 relays
@rejoe2 When i tried the for loops separate they don't show up at all in my serial. That was the only way to get them to present. I'm trying another sketch that looks more promising for me to build from but it as well doesn't show my temp. I get presentation but no reading.
BTW thanks for the help.
-
RE: 2 dallas temp + 4 relays
@dzjr If i use the mysensors dallas temp that i use for my pool the sensors work just fine. If i use the relay sketch it works fine Alone. Whenever i combine these two sketches is when i have problems. I have been trying sketches that are working for others with no progress myself. I have even rewired twice. I am no programmer i took 2 classes in college but they r not helping me either.
-
RE: 2 dallas temp + 4 relays
I tried to combine a couple other sketches and the closest I got was this one. But it still does not give me values for my Dallas temp. if I try each sketch separate they work fine and present fine with readings. I am a newbie and have luck, yes i call it luck cause my other sensors work just fine.
My debug is
| / |_ / | ___ _ __ ___ ___ _ __ ___
| |/| | | | _ \ / _ \_ \/ __|/ _ \|
_/ __|
| | | | || || | / | | _ \ _ | | _
|| ||_, |/ ___|| ||/_/|| |/
|__/ 2.3.116 MCO:BGN:INIT NODE,CP=RNNNA---,REL=255,VER=2.3.1
26 MCO:BGN:BFR
120 TSM:INIT
121 TSF:WUR:MS=0
129 TSM:INIT:TSP OK
130 TSM:INIT:STATID=8
136 TSF:SID:OK,ID=8
138 TSM:FPAR
174 TSF:MSG:SEND,8-8-255-255,s=255,c=3,t=7,pt=0,l=0,sg=0,ft=0,st=OK:
448 TSF:MSG:READ,0-0-8,s=255,c=3,t=8,pt=1,l=1,sg=0:0
452 TSF:MSG:FPAR OK,ID=0,D=1
2181 TSM:FPAR:OK
2182 TSM:ID
2183 TSM:ID:OK
2185 TSM:UPL
2188 TSF:MSG:SEND,8-8-0-0,s=255,c=3,t=24,pt=1,l=1,sg=0,ft=0,st=OK:1
2195 TSF:MSG:READ,0-0-8,s=255,c=3,t=25,pt=1,l=1,sg=0:1
2200 TSF:MSG:PONG RECV,HP=1
2203 TSM:UPL:OK
2204 TSM:READY:ID=8,PAR=0,DIS=1
2209 TSF:MSG:SEND,8-8-0-0,s=255,c=3,t=15,pt=6,l=2,sg=0,ft=0,st=OK:0100
2217 TSF:MSG:READ,0-0-8,s=255,c=3,t=15,pt=6,l=2,sg=0:0100
2225 TSF:MSG:SEND,8-8-0-0,s=255,c=0,t=17,pt=0,l=5,sg=0,ft=0,st=OK:2.3.1
2233 TSF:MSG:SEND,8-8-0-0,s=255,c=3,t=6,pt=1,l=1,sg=0,ft=0,st=OK:0
2250 TSF:MSG:READ,0-0-8,s=255,c=3,t=6,pt=0,l=1,sg=0:M
2257 TSF:MSG:SEND,8-8-0-0,s=255,c=3,t=11,pt=0,l=18,sg=0,ft=0,st=OK:Temperature Sensor
2268 TSF:MSG:SEND,8-8-0-0,s=255,c=3,t=12,pt=0,l=3,sg=0,ft=0,st=OK:1.2
2276 TSF:MSG:SEND,8-8-0-0,s=1,c=0,t=3,pt=0,l=0,sg=0,ft=0,st=OK:
2283 TSF:MSG:SEND,8-8-0-0,s=21,c=0,t=6,pt=0,l=0,sg=0,ft=0,st=OK:
2290 TSF:MSG:SEND,8-8-0-0,s=2,c=0,t=3,pt=0,l=0,sg=0,ft=0,st=OK:
2298 TSF:MSG:SEND,8-8-0-0,s=21,c=0,t=6,pt=0,l=0,sg=0,ft=0,st=OK:
2306 TSF:MSG:SEND,8-8-0-0,s=3,c=0,t=3,pt=0,l=0,sg=0,ft=0,st=OK:
2314 TSF:MSG:SEND,8-8-0-0,s=21,c=0,t=6,pt=0,l=0,sg=0,ft=0,st=OK:
2321 TSF:MSG:SEND,8-8-0-0,s=1,c=0,t=3,pt=0,l=0,sg=0,ft=0,st=OK:
2328 TSF:MSG:SEND,8-8-0-0,s=22,c=0,t=6,pt=0,l=0,sg=0,ft=0,st=OK:
2336 TSF:MSG:SEND,8-8-0-0,s=2,c=0,t=3,pt=0,l=0,sg=0,ft=0,st=OK:
2343 TSF:MSG:SEND,8-8-0-0,s=22,c=0,t=6,pt=0,l=0,sg=0,ft=0,st=OK:
2352 TSF:MSG:SEND,8-8-0-0,s=3,c=0,t=3,pt=0,l=0,sg=0,ft=0,st=OK:
2359 TSF:MSG:SEND,8-8-0-0,s=22,c=0,t=6,pt=0,l=0,sg=0,ft=0,st=OK:
2365 MCO:REG:REQ
2368 TSF:MSG:SEND,8-8-0-0,s=255,c=3,t=26,pt=1,l=1,sg=0,ft=0,st=OK:2
2374 TSF:MSG:READ,0-0-8,s=255,c=3,t=27,pt=1,l=1,sg=0:1
2379 MCO:PIM:NODE REG=1
2382 MCO:BGN:STP
Hello world, I am a sensor.
2383 MCO:BGN:INIT OK,TSP=1
Starting new measurement(s)
Sensor #0 says it is -127.00 degrees
Sensor #1 says it is -127.00 degrees
zzzzZZZZzzzzZZZZzzzz/** The MySensors Arduino library handles the wireless radio link and protocol between your home built sensors/actuators and HA controller of choice. The sensors forms a self healing radio network with optional repeaters. Each repeater and gateway builds a routing tables in EEPROM which keeps track of the network topology allowing messages to be routed to nodes. Created by Henrik Ekblad <henrik.ekblad@mysensors.org> Copyright (C) 2013-2015 Sensnology AB Full contributor list: https://github.com/mysensors/Arduino/graphs/contributors Documentation: http://www.mysensors.org Support Forum: http://forum.mysensors.org This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License version 2 as published by the Free Software Foundation. ******************************* DESCRIPTION Example sketch showing how to send in DS1820B OneWire temperature readings back to the controller http://www.mysensors.org/build/temp The cool thing about this temperature sensor (pun intended) is thay you can attach multiple Dallas temperature sensors outputs to the same arduino pin. They will all automatically be recognised as separate sensors. At the moment of writing (februari 2017) you need older versions of the Dallas and OneWire libraries. Please check the website or forum to see if this is still the case. Modifications by anonymous user so that it can now simultaneously function as a MySensors repeater. */ // Enable debug prints to serial monitor #define MY_DEBUG // Enable and select radio type attached #define MY_RADIO_RF24 // A 2.4Ghz transmitter and receiver, often used with MySensors. //#define MY_RF24_PA_LEVEL RF24_PA_MIN // This sets a low-power mode for the radio. Useful if you use the verison with the bigger antenna, but don' want to power that from a separate source. It can also fix problems with fake Chinese versions of the radio. //#define MY_RADIO_RFM69 // 433Mhz transmitter and reveiver. #define MY_NODE_ID 8 // Choose if you want this sensor to also be a repeater. // #define MY_REPEATER_FEATURE // Just remove the two slashes at the beginning of this line to also enable this sensor to act as a repeater for other sensors. If this node is on battery power, you probably shouldn't enable this. // Are you using this sensor on battery power? //#define BATTERY_POWERED // Just remove the two slashes at the beginning of this line if your node is battery powered. It will then go into deep sleep as much as possible. But when it' sleeping it can' work as a repeater. #include <SPI.h> #include <MySensors.h> #include <DallasTemperature.h> #include <OneWire.h> // These defines and variables can be changed: #define COMPARE_TEMP 1 // Send temperature only if changed? 1 = Yes 0 = No. Can save battery. #define ONE_WIRE_BUS 3 // Pin where Dallas sensor(s) is/are connected. #define MAX_ATTACHED_DS18B20 16 // Maximum amount of teperature sensors you can connect to this arduino (16). #define RELAY_PIN 4 // Arduino Digital I/O pin number for first relay (second on pin+1 etc) #define NUMBER_OF_RELAYS 3 // Total number of attached relays #define RELAY_ON 1 // GPIO value to write to turn on attached relay #define RELAY_OFF 0 // GPIO value to write to turn off attached relay unsigned long measurementInterval = 30000; // Time to wait between reads (in milliseconds). // You should not change these: OneWire oneWire(ONE_WIRE_BUS); // Setup a oneWire instance to communicate with any OneWire devices (not just Maxim/Dallas temperature ICs) DallasTemperature sensors(&oneWire); // Pass the oneWire reference to Dallas Temperature. float lastTemperature[MAX_ATTACHED_DS18B20]; // creates an array to hold the previous temperature measurements for each possible sensor. int numSensors = 0; // variable to contain the number of found attached sensors. boolean metric = true; // old Mysensors?? unsigned long measurementSleepTime = 0; // variable to store the Sleep time if the node is battery powered. // Mysensors settings MyMessage msg(0, V_TEMP); // Sets up the message format that we'l be sending to the MySensors gateway later. void before() { sensors.begin(); // Startup up the OneWire library. It allows multiple sensors to talk over one wire (one pin). for (int sensor = 1, pin = RELAY_PIN; sensor <= NUMBER_OF_RELAYS; sensor++, pin++) { // Then set relay pins in output mode pinMode(pin, OUTPUT); // Set relay to last known state (using eeprom storage) digitalWrite(pin, loadState(sensor) ? RELAY_ON : RELAY_OFF); } } void setup() { for (int i = 0; i < MAX_ATTACHED_DS18B20; i++) { lastTemperature[i] = 0; //Pre-filling array with 0's. } sensors.setWaitForConversion(false); // requestTemperatures() will not block current thread #ifdef BATTERY_POWERED measurementSleepTime = measurementInterval; measurementInterval = 1; // We'll let Sleep take over the scheduling. When the arduino is asleep, millis doesn't increment anymore (time stops as it were). To fix this, we'l set the measurement interval time to 1, so that when the arduino wakes up it will immediately try to measure again. #endif Serial.begin(115200); // for serial debugging. Serial.print("Hello world, I am a sensor. \n "); } void presentation() { sendSketchInfo("Temperature Sensor", "1.2"); // Send the sketch version information to the gateway and Controller numSensors = sensors.getDeviceCount(); // Fetch the number of attached temperature sensors for (int i = 0; i < numSensors && i < MAX_ATTACHED_DS18B20; i++) for (int sensor = 1, pin = RELAY_PIN; sensor <= NUMBER_OF_RELAYS; sensor++, pin++) { // Register all sensors to gw (they will be created as child devices) present(sensor, S_BINARY); present(i+21, S_TEMP); // Present all sensors to controller (16 maximum). } } void loop() { // You should not change these variables: static boolean isMeasuring = true; // Used to indicate when the time is right for a new measurement to be made. static boolean isCalculating = false; // Used to bridge the time that is needed to calculate the temperature values by the Dallas library. static unsigned long currentMillis = 0; // The millisecond clock in the main loop. static unsigned long previousMeasurementMillis = 0; // Used to remember the time of the last temperature measurement. static int16_t conversionTime = 0; // Used to store the time needed to calculate the temperature from measurements. currentMillis = millis(); // The time since the sensor started, counted in milliseconds. This script tries to avoid using the Sleep function, so that it could at the same time be a MySensors repeater. // Let's measure the temperature if (isMeasuring == true && currentMillis - previousMeasurementMillis >= measurementInterval) { // If we're not calculating, and enough time has passed, we'll start again. isMeasuring = false; // We're measuring, so let's take it off our to-do list. Serial.print("Starting new measurement(s)\n"); previousMeasurementMillis = currentMillis; // Mark the time of the initialiation of this measurement. // Fetch temperatures from Dallas sensors sensors.requestTemperatures(); // query conversion time. Apparently it takes a while to calculate. //CONVERSION_TIME = sensors.millisToWaitForConversion(sensors.getResolution()); conversionTime = millisToWaitForConversion(sensors.getResolution()); isCalculating = true; //Next step is to re-calculate the temperature again. } // Next, let's calculate and send the temperature if (isCalculating == true && currentMillis > previousMeasurementMillis + conversionTime ) { isCalculating = false; // check calculating off the to-do list too. for (int i = 0; i < numSensors && i < MAX_ATTACHED_DS18B20; i++) { // Loop through all the attached temperatur sensors. float temperature = static_cast<float>(static_cast<int>((getControllerConfig().isMetric ? sensors.getTempCByIndex(i) : sensors.getTempFByIndex(i)) * 10.)) / 10.; // Fetch and round temperature to one decimal Serial.print("Sensor #"); Serial.print(i); Serial.print(" says it is "); Serial.print(temperature); Serial.print(" degrees\n"); if (temperature != -127.00 && temperature != 85.00) { // avoid working with measurement errors. if (COMPARE_TEMP == 1 && lastTemperature[i] == temperature) { Serial.print("Not sending it though, because it's the same temperature as before.\n"); } else { Serial.print("Sending the temperature to the gateway.\n"); send(msg.setSensor(i).set(temperature, 1)); lastTemperature[i] = temperature; // Save new temperatures to be able to compare in the next round. } } } // Both tasks are done. Time to wait until we should measure again. Serial.print("zzzzZZZZzzzzZZZZzzzz\n"); #ifdef BATTERY_POWERED unsigned long quicktimecheck = millis(); // check how much time has passed during the measurement (can be up to 750 milliseconds), and then calculate from that how long to sleep until the next intended measuring time. unsigned long sleeptime = measurementSleepTime - (quicktimecheck - previousMeasurementMillis); //How much time has passed already during the calculating? Subtract that from the intended interval time. sleep (sleeptime); #endif isMeasuring = true; } } // This function helps to avoid a problem with the latest Dallas temperature library. int16_t millisToWaitForConversion(uint8_t bitResolution) { switch (bitResolution) { case 9: return 94; case 10: return 188; case 11: return 375; default: return 750; } } void receive(const MyMessage &message) { // We only expect one type of message from controller. But we better check anyway. if (message.type == V_STATUS) { // Change relay state digitalWrite(message.sensor - 1 + RELAY_PIN, message.getBool() ? RELAY_ON : RELAY_OFF); // Store state in eeprom 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()); } } /*Last note : celsius/farenheit in dallatemperature lib is not handled by the metric variable. To get the conversion you need to use C or F functions as below. I've not checked how you handle this in sketch. // returns temperature in degrees C float getTempC(const uint8_t*); // returns temperature in degrees F float getTempF(const uint8_t*); // Get temperature for device index (slow) float getTempCByIndex(uint8_t); // Get temperature for device index (slow) float getTempFByIndex(uint8_t); */
-
RE: 2 dallas temp + 4 relays
Would this be my blocking loop?
void presentation() { // Send the sketch version information to the gateway and Controller sendSketchInfo("Fireplace interface", "1.1"); //wait(LONG_WAIT); // Fetch the number of attached temperature sensors numSensors = sensors.getDeviceCount(); // Present all sensors to controller for (int i=0; i<numSensors && i<MAX_ATTACHED_DS18B20; i++) { present(i+5, S_TEMP,"Fireplace Temp"); //wait(SHORT_WAIT); } 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) present(sensor, S_BINARY); //wait(SHORT_WAIT); } }
-
RE: 2 dallas temp + 4 relays
@dzjr I tried to use your sketch to get mine to work and it does not. I might just rebuild it all with new everything and try it again.
-
RE: Combining relay and temperature sketch
@rejoe2 Thanks! I will do that. the code i used was from the examples. My relays work fine but my temp sensors never register. Even in serial. but if i run the Dallas temp my-sensors code separate i always get reading. Its just been mind boggling.
-
RE: Combining relay and temperature sketch
Has anyone had any progress on sensor node with mysensors + multiple dallas temp sensors and multiple relays, combining the two codes? Any help would be greatly appreciated. I have been playing with this for a little more than a week, have tried everything suggested but still not working. A push in the right direction would be great!
-
2 dallas temp + 4 relays
Has anyone had any progress on sensor node with mysensors + multiple dallas temp sensors and multiple relays combining the codes? Any help would be greatly appreciated. I have been playing with this for a little more than a week off and on. a push in the right direction would be great!
Thanks// Enable debug prints to serial monitor #define MY_DEBUG //#define MY_RF24_CE_PIN 49 //#define MY_RF24_CS_PIN 53 // Enable and select radio type attached #define MY_RADIO_NRF24 //#define MY_RADIO_RFM69 #define MY_NODE_ID 6 #include <SPI.h> #include <MySensors.h> #include <DallasTemperature.h> #include <OneWire.h> // Wait times #define LONG_WAIT 500 #define SHORT_WAIT 50 #define COMPARE_TEMP 1 // Send temperature only if changed? 1 = Yes 0 = No #define ONE_WIRE_BUS 3 // Pin where dallase sensor is connected #define MAX_ATTACHED_DS18B20 16 unsigned long SLEEP_TIME = 30000; // Sleep time between reads (in milliseconds) OneWire oneWire(ONE_WIRE_BUS); // Setup a oneWire instance to communicate with any OneWire devices (not just Maxim/Dallas temperature ICs) DallasTemperature sensors(&oneWire); // Pass the oneWire reference to Dallas Temperature. float lastTemperature[MAX_ATTACHED_DS18B20]; int numSensors=0; bool receivedConfig = false; bool metric = true; // Initialize temperature message MyMessage msg(0,V_TEMP); #define RELAY_1 4 // Arduino Digital I/O pin number for first relay (second on pin+1 etc) #define NUMBER_OF_RELAYS 4 // Total number of attached relays #define RELAY_ON 0 // GPIO value to write to turn on attached relay #define RELAY_OFF 1 // GPIO value to write to turn off attached relay void before() { for (int sensor=1, pin=RELAY_1; sensor<=NUMBER_OF_RELAYS; sensor++, pin++) { // Then set relay pins in output mode pinMode(pin, OUTPUT); // Set relay to last known state (using eeprom storage) digitalWrite(pin, loadState(sensor)?RELAY_ON:RELAY_OFF); } // Startup up the OneWire library sensors.begin(); } void setup() { // requestTemperatures() will not block current thread sensors.setWaitForConversion(false); } void presentation() { // Send the sketch version information to the gateway and Controller sendSketchInfo("Fireplace interface", "1.1"); //wait(LONG_WAIT); // Fetch the number of attached temperature sensors numSensors = sensors.getDeviceCount(); // Present all sensors to controller for (int i=0; i<numSensors && i<MAX_ATTACHED_DS18B20; i++) { present(i+5, S_TEMP,"Fireplace Temp"); //wait(SHORT_WAIT); } 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) present(sensor, S_BINARY); //wait(SHORT_WAIT); } } void loop() { // Fetch temperatures from Dallas sensors sensors.requestTemperatures(); // query conversion time and sleep until conversion completed int16_t conversionTime = sensors.millisToWaitForConversion(sensors.getResolution()); // sleep() call can be replaced by wait() call if node need to process incoming messages (or if node is repeater) wait(conversionTime); // Read temperatures and send them to controller for (int i=0; i<numSensors && i<MAX_ATTACHED_DS18B20; i++) { // Fetch and round temperature to one decimal float temperature = static_cast<float>(static_cast<int>((getControllerConfig().isMetric?sensors.getTempCByIndex(i):sensors.getTempFByIndex(i)) * 10.)) / 10.; // Only send data if temperature has changed and no error #if COMPARE_TEMP == 1 if (lastTemperature[i] != temperature && temperature != -127.00 && temperature != 85.00) { #else if (temperature != -127.00 && temperature != 85.00) { #endif // Send in the new temperature send(msg.setSensor(i+5).set(temperature,1)); // Save new temperatures for next compare lastTemperature[i]=temperature; } } } void receive(const MyMessage &message) { // We only expect one type of message from controller. But we better check anyway. if (message.type==V_STATUS) { // Change relay state digitalWrite(message.sensor-1+RELAY_1, message.getBool()?RELAY_ON:RELAY_OFF); // Store state in eeprom 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()); } wait(SLEEP_TIME); }``` And here is my serial print __ __ ____ | \/ |_ _/ ___| ___ _ __ ___ ___ _ __ ___ | |\/| | | | \___ \ / _ \ `_ \/ __|/ _ \| `__/ __| | | | | |_| |___| | __/ | | \__ \ _ | | \__ \ |_| |_|\__, |____/ \___|_| |_|___/\___/|_| |___/ |___/ 2.3.1 16 MCO:BGN:INIT NODE,CP=RNNNA---,REL=255,VER=2.3.1 26 MCO:BGN:BFR 28 TSM:INIT 29 TSF:WUR:MS=0 36 TSM:INIT:TSP OK 37 TSM:INIT:STATID=6 44 TSF:SID:OK,ID=6 45 TSM:FPAR 81 TSF:MSG:SEND,6-6-255-255,s=255,c=3,t=7,pt=0,l=0,sg=0,ft=0,st=OK: 780 TSF:MSG:READ,0-0-6,s=255,c=3,t=8,pt=1,l=1,sg=0:0 785 TSF:MSG:FPAR OK,ID=0,D=1 2089 TSM:FPAR:OK 2091 TSM:ID 2092 TSM:ID:OK 2094 TSM:UPL 2097 TSF:MSG:SEND,6-6-0-0,s=255,c=3,t=24,pt=1,l=1,sg=0,ft=0,st=OK:1 2104 TSF:MSG:READ,0-0-6,s=255,c=3,t=25,pt=1,l=1,sg=0:1 2109 TSF:MSG:PONG RECV,HP=1 2111 TSM:UPL:OK 2113 TSM:READY:ID=6,PAR=0,DIS=1 2117 TSF:MSG:SEND,6-6-0-0,s=255,c=3,t=15,pt=6,l=2,sg=0,ft=0,st=OK:0100 2125 TSF:MSG:READ,0-0-6,s=255,c=3,t=15,pt=6,l=2,sg=0:0100 2132 TSF:MSG:SEND,6-6-0-0,s=255,c=0,t=17,pt=0,l=5,sg=0,ft=0,st=OK:2.3.1 2142 TSF:MSG:SEND,6-6-0-0,s=255,c=3,t=6,pt=1,l=1,sg=0,ft=0,st=OK:0 2158 TSF:MSG:READ,0-0-6,s=255,c=3,t=6,pt=0,l=1,sg=0:M 2165 TSF:MSG:SEND,6-6-0-0,s=255,c=3,t=11,pt=0,l=19,sg=0,ft=0,st=OK:Fireplace interface 2176 TSF:MSG:SEND,6-6-0-0,s=255,c=3,t=12,pt=0,l=3,sg=0,ft=0,st=OK:1.1 2183 TSF:MSG:SEND,6-6-0-0,s=1,c=0,t=3,pt=0,l=0,sg=0,ft=0,st=OK: 2191 TSF:MSG:SEND,6-6-0-0,s=2,c=0,t=3,pt=0,l=0,sg=0,ft=0,st=OK: 2198 TSF:MSG:SEND,6-6-0-0,s=3,c=0,t=3,pt=0,l=0,sg=0,ft=0,st=OK: 2206 TSF:MSG:SEND,6-6-0-0,s=4,c=0,t=3,pt=0,l=0,sg=0,ft=0,st=OK: 2211 MCO:REG:REQ 2215 TSF:MSG:SEND,6-6-0-0,s=255,c=3,t=26,pt=1,l=1,sg=0,ft=0,st=OK:2 2222 TSF:MSG:READ,0-0-6,s=255,c=3,t=27,pt=1,l=1,sg=0:1 2227 MCO:PIM:NODE REG=1 2229 MCO:BGN:STP 2231 MCO:BGN:INIT OK,TSP=1 Re: [Combining relay and temperature sketch](/topic/6782/combining-relay-and-temperature-sketch)
-
RE: Advice for Newbie trying to get started
I started with Domoticz and my sensors. Now I have half my house controlled and monitored by Domoticz. A LOT OF TRIAL AND ERROR! But my god thanks to everyone that has the same passions as I do!!!
-
RE: RFID 522 With added relays for Lighting
@dbemowsk Yes you were right. Got it working the next day! Im new to Arduino and the coding part.... but really liking it! Thank you!
-
RFID 522 With added relays for Lighting
I'm very new to these forums. Always have enjoyed writing programs on my old apple. So sorry if i don't get everything right but i really need to understand why! Amyways
I am trying to add code to the RFID Lock Sensor and domoticz to work with added relays to be controlled by domatics and add swithes to the arduino nano board with a rf24 connected for my transport. and cant seem to see what i am doing wrong?
Here is my code./* * ---------------------------------------------------------------------------- * This is a MFRC522 library example; see https://github.com/miguelbalboa/rfid * for further details and other examples. * * NOTE: The library file MFRC522.h has a lot of useful info. Please read it. * * Released into the public domain. * ---------------------------------------------------------------------------- * Example sketch/program showing how to read data from a PICC (that is: a RFID * Tag or Card) using a MFRC522 based RFID Reader on the Arduino SPI interface. * * When the Arduino and the MFRC522 module are connected (see the pin layout * below), load this sketch into Arduino IDE then verify/compile and upload it. * To see the output: use Tools, Serial Monitor of the IDE (hit Ctrl+Shft+M). * When you present a PICC (that is: a RFID Tag or Card) at reading distance * of the MFRC522 Reader/PCD, the serial output will show the ID/UID, type and * any data blocks it can read. Note: you may see "Timeout in communication" * messages when removing the PICC from reading distance too early. * * If your reader supports it, this sketch/program will read all the PICCs * presented (that is: multiple tag reading). So if you stack two or more * PICCs on top of each other and present them to the reader, it will first * output all details of the first and then the next PICC. Note that this * may take some time as all data blocks are dumped, so keep the PICCs at * reading distance until complete. * * Typical pin layout used: * ----------------------------------------------------------------------------------------- * MFRC522 Arduino Arduino Arduino Arduino Arduino * Reader/PCD Uno Mega Nano v3 Leonardo/Micro Pro Micro * Signal Pin Pin Pin Pin Pin Pin * ----------------------------------------------------------------------------------------- * RST/Reset RST 9 5 D9 RESET/ICSP-5 RST * SPI SS SDA(SS) 10 53 D10 10 10 * SPI MOSI MOSI 11 / ICSP-4 51 D11 ICSP-4 16 * SPI MISO MISO 12 / ICSP-1 50 D12 ICSP-1 14 * SPI SCK SCK 13 / ICSP-3 52 D13 ICSP-3 15 */ /* RFID Garagedoor opener by Bart Eversdijk This sketch is to open a Garage door with an mifare RIFD-tag For an Arduino Nano v3 Connection wiring : - nrf24l01+ as descibed on the MySensors website - MFRC522 reader/writer as described above EXCEPT for pin D9 and D10: connect RST i.s.o. pin D9 to pin D7 and connect SDA(SS) i.s.o. pin D10 to pin D8 - LED with 470ohm resistor between GMD and pin A3 - push button between GND and pin D5 - 5v relays coil between GND and pin D4 -> switch pins of the relays should be connected in parallel with your garage door push button. Features: This project can record up to 18 RFID-"tags" These card IDs are stored in to EEPROM by keeping them next to the RFID reader when the system in program mode. (Slow blinking LED) When a card is accepted as new card the LED will blink fast for a short time. To keep the master-tags (choose your own) next to the RFID reader when pressing the push button. To clear all cards (except the master card) press the push button in program mode for 6 seconds. The LED will now fast blink for a couple of seconds. Your garage your can be opened by keep a registered RFID tag next to the reader or by clicking the open icon on lock node presented by this plugin. By by-passing the alarm node presented by this plug in the RFID will be temporarily disabled. When an incorrect (not registered) RFID tag is scanned the alarm is triggered to detect illegal scan attempts */ // Enable debug prints #define MY_DEBUG #define MY_NODE_ID AUTO // Enable and select radio type attached #define MY_RADIO_NRF24 //#define MY_RF24_CHANNEL AUTO #include <MySensors.h> #include <SPI.h> #include <MFRC522.h> #include <Bounce2.h> #define RF_INIT_DELAY 125 #define ONE_SEC 1000 #define MAX_CARDS 18 #define PROG_WAIT 10 #define HEARTBEAT 10 #define BAUD 115200 /*Pin definitions*/ #define LED_PIN A3 #define GARAGEPIN 4 #define RELAY_PIN 6 #define NUMBER_OF_RELAYS 2 // Total number of attached relays #define RELAY_ON 1 // GPIO value to write to turn on attached relay #define RELAY_OFF 0 // GPIO value to write to turn off attached relay #define SWITCH_PIN 5 #define RST_PIN 7 // MFRC #define SS_PIN 8 // MFRC MFRC522 mfrc522(SS_PIN, RST_PIN); // Create MFRC522 instance MFRC522::Uid olduid; MFRC522::Uid masterkey = { 4,{ 0x00,0x00,0x00,0x00 }, 0 }; byte countValidCards = 0; MFRC522::Uid validCards[MAX_CARDS]; void ShowCardData(MFRC522::Uid* uid); bool sameUid(MFRC522::Uid* old, MFRC522::Uid* check); void copyUid(MFRC522::Uid* src, MFRC522::Uid* dest); bool isValidCard(MFRC522::Uid* uid); int releasecnt = 0; #define CHILD_ID_ALARM 1 #define CHILD_ID_LOCK 2 #define CHILD_ID_RELAY 3 Bounce debouncer = Bounce(); int oldSwitchValue = -1; int switchValue = 0; long timer = -1; bool programmode = false; bool ledon; int programTimer = 0; bool armed = true; unsigned long lastTime = 0; MyMessage lockMsg(CHILD_ID_LOCK, V_LOCK_STATUS); MyMessage lockArmMsg(CHILD_ID_ALARM, V_ARMED); MyMessage wrongMsg(CHILD_ID_ALARM, V_TRIPPED); MyMessage relay(CHILD_ID_RELAY,V_LIGHT); void before() { // Make sure MFRC is disabled from the SPI bus pinMode(RST_PIN, OUTPUT); digitalWrite(RST_PIN, LOW); pinMode(SS_PIN, OUTPUT); digitalWrite(SS_PIN, LOW); } void presentation() { sendSketchInfo("RFID Garage", "1.1"); delay(RF_INIT_DELAY); // Register all sensors to gw (they will be created as child devices) present(CHILD_ID_LOCK, S_LOCK); delay(RF_INIT_DELAY); present(CHILD_ID_RELAY, S_LIGHT); present(CHILD_ID_ALARM, S_MOTION); delay(RF_INIT_DELAY); } void setup() { Serial.begin(BAUD); // Initialize serial communications with the PC pinMode(GARAGEPIN, OUTPUT); // Initialise in/output ports pinMode(RELAY_PIN, OUTPUT); // Make sure MFRC will be disabled on the SPI bus /*pinMode(RST_PIN, OUTPUT); digitalWrite(RST_PIN, LOW); pinMode(SS_PIN, OUTPUT); digitalWrite(SS_PIN, LOW);*/ pinMode(LED_PIN, OUTPUT); digitalWrite(LED_PIN, LOW); // Setup the button pinMode(SWITCH_PIN, INPUT); // Activate internal pull-up digitalWrite(SWITCH_PIN, HIGH); digitalWrite(RELAY_PIN, HIGH); // After setting up the button, setup debouncer debouncer.attach(SWITCH_PIN); debouncer.interval(5); // Init mysensors library /*sendSketchInfo("RFID Garage", "1.1"); delay(RF_INIT_DELAY); // Register all sensors to gw (they will be created as child devices) present(CHILD_ID_LOCK, S_LOCK); delay(RF_INIT_DELAY); present(CHILD_ID_RELAY, S_LIGHT); present(CHILD_ID_ALARM, S_MOTION); delay(RF_INIT_DELAY);*/ recallEeprom(); // Init MFRC RFID sensor SPI.begin(); // Init SPI bus mfrc522.PCD_Init(); // Init MFRC522 ShowReaderDetails(); // Show details of PCD - MFRC522 Card Reader details send(lockArmMsg.set(armed)); Serial.println(F("Init done...")); } void loop() { timer++; delay(HEARTBEAT); debouncer.update(); // Get the update value int switchValue = debouncer.read(); if (switchValue != oldSwitchValue) { // Send in the new value Serial.print(F("Switch ")); Serial.println(switchValue); if (switchValue && programmode) { lastTime = millis() / 1000; } if (!switchValue && programmode && lastTime > 0) { if ((millis() / 1000) - lastTime > 3) { Serial.println(F("Reset all cards")); countValidCards = 0; blinkFast(50); } else { Serial.println(F("Program off")); digitalWrite(LED_PIN, LOW); programmode = false; storeEeprom(); } } if (!switchValue) { programTimer = 0; } oldSwitchValue = switchValue; } if (programmode && ((timer % (ONE_SEC / HEARTBEAT)) == 0)) { ledon = !ledon; digitalWrite(LED_PIN, ledon); programTimer++; // Stop program mode after 20 sec inactivity if (programTimer > PROG_WAIT) { programmode = false; digitalWrite(LED_PIN, false); Serial.println(F("Program expired")); } } if ((timer % (200 / HEARTBEAT)) == 0) { // Look for new cards if (!mfrc522.PICC_IsNewCardPresent()) { if (releasecnt > 0) { releasecnt--; if (!releasecnt) { olduid.size = 0; Serial.println(F("release")); } } return; } releasecnt = 5; // Select one of the cards if (!mfrc522.PICC_ReadCardSerial()) { return; } // Dump debug info about the card; PICC_HaltA() is automatically called //mfrc522.PICC_DumpToSerial(&(mfrc522.uid)); if (!olduid.size || !sameUid(&(mfrc522.uid), &olduid)) { ShowCardData(&(mfrc522.uid)); copyUid(&(mfrc522.uid), &olduid); if (isValidCard(&olduid)) { OpenDoor(programmode); } else { if (sameUid(&(mfrc522.uid), &masterkey)) { // Only switch in program mode when mastercard is found AND the program button is pressed if (switchValue) { Serial.println(F("Program mode")); programmode = true; programTimer = 0; lastTime = 0; } } else { if (programmode) { Serial.println(F("new card")); programTimer = 0; if (countValidCards < MAX_CARDS) { // Add card to list... copyUid(&(mfrc522.uid), &validCards[countValidCards]); countValidCards++; blinkFast(15); } } else { Serial.println(F("Invalid card")); if (armed) { send(wrongMsg.set(1)); delay(2000); send(wrongMsg.set(0)); } } } } } } } void ShowCardData(MFRC522::Uid* uid) { Serial.print(F("Card UID:")); for (byte i = 0; i < uid->size; i++) { if (uid->uidByte[i] < 0x10) { Serial.print(F(" 0")); } else { Serial.print(F(" ")); } Serial.print(uid->uidByte[i], HEX); } Serial.println(); } void copyUid(MFRC522::Uid* src, MFRC522::Uid* dest) { dest->size = src->size; dest->sak = src->sak; for (byte i = 0; i < src->size; i++) { dest->uidByte[i] = src->uidByte[i]; } } bool sameUid(MFRC522::Uid* old, MFRC522::Uid* check) { if (old->size != check->size) { return false; } for (byte i = 0; i < old->size; i++) { if (old->uidByte[i] != check->uidByte[i]) { return false; } } return true; } bool isValidCard(MFRC522::Uid* uid) { for (byte i = 0; i < countValidCards; i++) { if (validCards[i].size != uid->size) { break; } for (int j = 0; j < uid->size; j++) { if (validCards[i].uidByte[j] != uid->uidByte[j]) { break; } if (j == (uid->size - 1)) { return true; } } } return false; } void storeEeprom() { byte address = 0; saveState(address++, countValidCards); for (byte i = 0; i < countValidCards; i++) { saveState(address++, validCards[i].size); for (byte j = 0; j < 10; j++) { saveState(address++, validCards[i].uidByte[j]); } } } void recallEeprom() { byte address = 0; countValidCards = loadState(address++); if (countValidCards > MAX_CARDS) { Serial.println(F("Not a valid EEPROM reading set to default")); countValidCards = 0; storeEeprom(); return; } for (byte i = 0; i < countValidCards; i++) { validCards[i].size = loadState(address++); for (byte j = 0; j < 10; j++) { validCards[i].uidByte[j] = loadState(address++); } } } void blinkFast(int times) { for (int i = 0; i < times; i++) { ledon = !ledon; digitalWrite(LED_PIN, ledon); delay(100); } } void OpenDoor(bool fakeOpen) { Serial.println(F("Open door!")); send(lockMsg.set(false)); if (!fakeOpen) { digitalWrite(LED_PIN, HIGH); digitalWrite(GARAGEPIN, HIGH); } delay(5000); if (!fakeOpen) { digitalWrite(GARAGEPIN, LOW); digitalWrite(LED_PIN, LOW); } send(lockMsg.set(true)); } void ShowReaderDetails() { // Get the MFRC522 software version byte v = mfrc522.PCD_ReadRegister(mfrc522.VersionReg); Serial.print(F("MFRC522 Software Version: 0x")); Serial.print(v, HEX); if (v == 0x91) { Serial.print(F(" = v1.0")); } else if (v == 0x92) { Serial.print(F(" = v2.0")); } else { Serial.print(F(" (unknown)")); } Serial.println(""); // When 0x00 or 0xFF is returned, communication probably failed if ((v == 0x00) || (v == 0xFF)) { Serial.println(F("WARNING: Communication failure, is the MFRC522 properly connected?")); } } void receive(const MyMessage &message) { if (message.type == V_LOCK_STATUS) { // Change relay state if (!message.getBool()) { OpenDoor(false); } // Write some debug info Serial.print(F("Lock status: ")); Serial.println(message.getBool()); } else { if (message.type == V_ARMED) { // Change relay state armed = message.getBool(); // Write some debug info Serial.print(F("Arm status: ")); Serial.println(message.getBool()); } else { // Write some debug info Serial.print(F("Incoming msg type: ")); Serial.print(message.type); Serial.print(F(" id: ")); Serial.print(message.sensor); Serial.print(F(" content: ")); Serial.println(message.getInt()); } } }```