@dynamite nice!
all sketches in this thread ?
-
Share your MySensors project
-
i need the sketch for Soil Moisture Sensors have everyone this sketch for me ?
-
you could try out following code for a 2.0 moisture sensor, its untested but it gets compilled
//********** CONFIG ********************************** #define MY_NODE_ID 3 // ID of node #define CHILD_ID 1 // ID of sensor #define VCC_PIN 4 // VCC-Pin of Moisture Sensor #define INPUT_PIN 3 // OUT-Pin of Moisture Sensor // #define MAX_LIGHT 750 // Max light value of LDR (0%) #define SLEEP_TIME 60000 // Sleep time between reads (seconds) #define MIN_V 2000 // empty voltage (0%) #define MAX_V 3200 // full voltage (100%) //#define MY_DEBUG // Debug //**************************************************** #define MY_RADIO_NRF24 #include <SPI.h> #include <MySensors.h> #include <readVcc.h> MyMessage msg(CHILD_ID, V_LEVEL); int oldBatteryPcnt = -1; int sentValue; boolean forceSend = false; void setup() { sendSketchInfo("Moisture Sensor", "2.0"); present(CHILD_ID, S_MOISTURE); } void loop() { digitalWrite(VCC_PIN, HIGH); // turn on moisture sensor int value = analogRead(INPUT_PIN); // get Moisture int percent = map(value, 0, 700, 0, 100); // remapping bits to percent resend(msg.set(percent), 2); // send moisture percent to gateway sentValue = percent; // Send batterylevel sendBattery(); digitalWrite(VCC_PIN, LOW); // Turn off Moisture sensor // Sleep 1 hour sleep(3600000); // sends node to sleep one hour } // FUNCTIONS void sendBattery() // send battery percentage to gateway { forceSend++; int batteryPcnt = min(map(readVcc(), MIN_V, MAX_V, 0, 100), 100); // Get VCC and convert to percentage if (batteryPcnt != oldBatteryPcnt || forceSend >= 20) { // If battery percentage has changed sendBatteryLevel(batteryPcnt); // Send battery percentage to gateway oldBatteryPcnt = batteryPcnt; forceSend = 0; } } void resend(MyMessage &msg, int repeats) // resend messages if not received by GW { int repeat = 0; int repeatDelay = 0; boolean ack = false; while ((ack == false) and (repeat < repeats)) { if (send(msg)) { ack = true; } else { ack = false; repeatDelay += 100; } repeat++; delay(repeatDelay); } }
-
I think this line should be changed
#define NODE_ID 3 // ID of node
to
#define MY_NODE_ID 3 // ID of node
otherwise it will not use a static ID
-
@rikki78 thank you, changed.
-
Hi all,
I would like to introduce my MySensors Display node.
Last year I built the following weather station as presented in the MySensors forum:
solar powered weater station
This station is working great and I found only using the Pimatic browser to view the weather station data inconvenient.
So I decided to build a MySensors Display node with approach sensor to activate the back light of an LCD display.The Display is an ordinairy node receiving data from Pimatic using the ‘send’ command in a rule triggered by a variable change. In this case when one of the weather station sensors changes value.
Not visible now is the rain sensor indicator, but when raining a rain symbol will be shown after the Humidity percentage.The case is 3D printed from one of the many LCD 12864 cases available on the net. I dremmeled the holes for the approach sensor.
{ "id": "zend-weerstation-luchtdruk-naar-display", "name": "Zend weerstation luchtdruk naar display", "rule": "when $weerstation.Barometer gets updated then send custom \"V_VAR1\" nodeid: \"100\" sensorid: \"3\" cmdcode: \"$weerstation.Barometer\"", "active": true, "logging": true },
I use the approach sensor to fade in and out the backlight of the display.
This is the sketch I use:
// Enable debug prints to serial monitor #define MY_DEBUG // Enable and select radio type attached #define MY_RADIO_NRF24 //#define MY_RADIO_RFM69 // Enable repeater functionality for this node #define MY_REPEATER_FEATURE // ********** CONFIG ************************************************************************ #define MY_NODE_ID 100 // ID of node #define CHILD_ID 1 // ID of sensor #define TRIGGER_PIN 6 // Arduino pin tied to trigger pin on the ultrasonic sensor. #define ECHO_PIN 5 // Arduino pin tied to echo pin on the ultrasonic sensor. #define BACKLIGHT_PIN 3 // LCD backlight fade in/out control pin #define RS_PIN 8 // LCD12864 RS #define RW_PIN 7 // LCD12864 R/W #define E_PIN 4 // LCD12864 E (data) #define MAX_DISTANCE 75 // Maximum distance to ping for (in cm). Max sensor distance is rated 400-500cm. // ****************************************************************************************** #include <SPI.h> #include <MySensors.h> #include <Wire.h> #include <NewPing.h> #include <U8glib.h> NewPing sonar(TRIGGER_PIN, ECHO_PIN, MAX_DISTANCE); // NewPing setup of pins and maximum distance. MyMessage msg(CHILD_ID, V_DISTANCE); bool metric = true; int lastDist; int backlightOnDist = 60; // Minimum distance to turn backlight on int backlightOnTime = 0; int maxBacklightOnTime = 50; // Maximum delay for backlight to turn off float recTemperature; float recHumidity; float recPressure; int recLight; bool recRain; int recBattery; int maxBrightLCD = 100; // Maximum brightness backlight LCD // Initialize 12864 display. U8GLIB_ST7920_128X64 u8g(E_PIN, RW_PIN, RS_PIN, U8G_PIN_NONE); // Define rain symbol const uint8_t rain_bitmap[] U8G_PROGMEM = { B11111111, B11111111, B00100000, B00100000, B01000100, B01000100, B10001000, B10001000, B00010000, B00010000, B00000010, B00000010, B01000100, B01000100, B10001000, B10001000 }; void draw() { // U8GLIB graphic commands to redraw the complete screen should be placed here u8g.setFont(u8g_font_helvR08); // digits width 6 pixel, decimal seperator width 2 pixel, int skipDigit = 6; int corNegSign = 2; int startColumn = 72; // start position data int digitOffset = 0; // offset for digit correction int unitOffset = 23; // offset for unit label char degree[2] = " "; degree[0] = 176; // Degree-sign in this font type enum {BufSize=6}; // max characters char buf[BufSize]; u8g.drawStr( 2, 11, "Weerstation balkon"); u8g.drawHLine( 0, 12, 128); u8g.drawStr( 2, 25, "Temperatuur:"); u8g.drawStr( 2, 36, "Vochtigheid:"); u8g.drawStr( 2, 47, "Luchtdruk:"); u8g.drawStr( 2, 58, "Zonlicht:"); u8g.drawStr( startColumn + unitOffset, 25, degree); u8g.drawStr( startColumn + unitOffset + 4, 25, "C"); u8g.drawStr( startColumn + unitOffset, 36, "%"); u8g.drawStr( startColumn + unitOffset, 47, "mbar"); u8g.drawStr( startColumn + unitOffset, 58, "lux"); // value temperature dtostrf(recTemperature, 0, 1, buf); if (recTemperature < 10 and recTemperature > 0) { digitOffset = digitOffset + skipDigit; } if (recTemperature < 0) { digitOffset = digitOffset + corNegSign; // compensate smaller minus sign if (recTemperature < -10) { digitOffset = digitOffset - skipDigit; } } u8g.drawStr(startColumn + digitOffset, 25, buf); // value humidity digitOffset = 0; dtostrf(recHumidity, 0, 1, buf); u8g.drawStr(startColumn, 36, buf); // value pressure digitOffset = -2 * skipDigit; dtostrf(recPressure, 0, 0, buf); if (recPressure < 1000) { digitOffset = digitOffset + skipDigit; } u8g.drawStr(startColumn + digitOffset, 47, buf); // value light digitOffset = -2 * skipDigit; dtostrf(recLight, 0, 0, buf); if (recLight < 1000) { digitOffset = digitOffset + skipDigit; if (recLight < 100) { digitOffset = digitOffset + skipDigit; if (recLight < 10) { digitOffset = digitOffset + skipDigit; } } } u8g.drawStr(startColumn + digitOffset, 58, buf); // rain if (recRain) { u8g.drawBitmapP( 108, 28, 2, 8, rain_bitmap); } // battery u8g.drawFrame(110, 5, 12, 6); u8g.drawVLine(122, 7, 2); u8g.drawBox(111, 6, (int)recBattery/10, 4); } void fade(bool in) { int brightLCD; for (brightLCD = 0; brightLCD <= maxBrightLCD; brightLCD++) { analogWrite(BACKLIGHT_PIN, in? brightLCD: maxBrightLCD - brightLCD); delay(20); } } void setup() { // initialize the lcd12864 // assign default color value if ( u8g.getMode() == U8G_MODE_R3G3B2 ) u8g.setColorIndex(255); // white else if ( u8g.getMode() == U8G_MODE_GRAY2BIT ) u8g.setColorIndex(3); // max intensity else if ( u8g.getMode() == U8G_MODE_BW ) u8g.setColorIndex(1); // pixel on metric = getControllerConfig().isMetric; } void presentation() { // Send the sketch version information to the gateway and Controller sendSketchInfo("Display", "1.0"); present(CHILD_ID, S_DISTANCE); } void loop() { int dist = metric?sonar.ping_cm():sonar.ping_in(); // Serial.print("Ping: "); // Serial.print(dist); // Convert ping time to distance in cm and print result (0 = outside set distance range) // Serial.println(metric?" cm":" in"); if (abs(dist - lastDist) > backlightOnDist) { send(msg.set(dist)); lastDist = dist; } if (dist < backlightOnDist and dist > 0) { if (backlightOnTime == 0) { // New in range: start backlight on period // Backlight fade in fade(true); } backlightOnTime = 1; // Still in range: restart backlight on period } if (backlightOnTime > 0) { backlightOnTime++; if (backlightOnTime >= maxBacklightOnTime) { backlightOnTime = 0; // Out range for maxBacklightOnTime: set backlight off // Backlight fade out fade(false); } } // picture loop u8g.firstPage(); do { draw(); } while( u8g.nextPage() ); } void receive(const MyMessage &message) { // Explore message switch (message.sensor) { case 0: // Humidity sensor { recHumidity = message.getFloat(); break; } case 1: // Temperature sensor { recTemperature = message.getFloat(); break; } case 2: // Light sensor { recLight = message.getUInt(); break; } case 3: // Barometer sensor { recPressure = message.getFloat(); break; } case 4: // Barometer Temperature sensor { break; } case 5: // Rain sensor { recRain = message.getUInt(); break; } case 6: // Battery { recBattery = message.getUInt(); break; } } }
-
UWAGA: Błędny folder .ci w bibliotece 'MySensors’
UWAGA: Błędny folder .mystools w bibliotece 'MySensors’
sketch_nov14a:8:22: error: MySensor.h: No such file or directorycompilation terminated.
exit status 1
MySensor.h: No such file or directory -
@szybki946 you are missing the MySensor.h file in your working directory.
-
In file included from C:\Users\Przemek\AppData\Local\Temp\arduino_modified_sketch_894108\sketch_nov15a.ino:8:0:
C:\Users\Przemek\Documents\Arduino\libraries\MySensors/MySensors.h:405:2: 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.
^
exit status 1
Błąd kompilacji dla płytki Arduino Nano. -
@szybki946 you need to define a radio in your sketch…