send V_TEXT to LCD1602 Display
-
hi,
i woud to use this sketch to show messages fron my pimatic controller on a 1602 Display.
This sketch use the V_TEXT variabel to show messages.How i can use V_TEXT in pimatic to push messages to the display?
//Credits: https://forum.mysensors.org/topic/1957/lcd-clock-and-text-sensor-node-with-new-v_text //Soft signing. //#define MY_SIGNING_SOFT //#define MY_SIGNING_REQUEST_SIGNATURES //#define MY_SIGNING_SOFT_RANDOMSEED_PIN 7 #define MY_RADIO_NRF24 #define MY_DEBUG #define MY_NODE_ID 3 #include <TimeLib.h> #include <Wire.h> #include <LiquidCrystal_I2C.h> #include <SPI.h> #include <MySensors.h> char lastLCD1[16] = "Line1"; //Line 1 always showing current time char lastLCD2[16] = "Line2"; //20 whitespace characters used to clear your LCD line before printing to it. //Change to fit your LCD. Don't forget to change number of chars in the writeScreen function if needed. String LINE_BLANK = " "; boolean timeReceived = false ; unsigned long lastUpdate = 0, lastRequest = 0, lastDisplay = 0; const byte LCD1_CHILD = 1; // Child ID for LCD line 1 const byte LCD2_CHILD = 2; // Child ID for LCD line 2 MyMessage textMsg(0, V_TEXT); // Initialize display. Google the correct settings for your display. // The follwoing setting should work for the recommended display in the MySensors "shop". LiquidCrystal_I2C lcd(0x27, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE); void before() { Wire.begin(); // I2C. lcd.begin(16, 2); // LCD with 20 chars, 4 lines. lcd.setBacklight(HIGH); // Make sure backlight is on. writeScreen(0, "Waiting for GW.."); // Print initial text before contact with GW. } void setup(void) { Serial.begin(115200); // Start serial. requestTime(); // Request time from controller. } void presentation() { sendSketchInfo("Domoticz LCD", "1.0"); // Send the sketch version information to the gateway and Controller present(LCD1_CHILD, S_INFO, "LCD_line1"); wait(500); present(LCD2_CHILD, S_INFO, "LCD_line2"); wait(500); send(textMsg.setSensor(LCD1_CHILD).set("-")); // initialize the V_TEXT at controller for sensor to none (trick for Domoticz) send(textMsg.setSensor(LCD2_CHILD).set("-")); } void loop() { // timer for loop delays unsigned long now = millis(); // If no time has been received yet, request it every 10 second from controller // When time has been received, request update every hour if ((!timeReceived && (now - lastRequest > 10 * 1000)) || (now - lastRequest > 3600000UL)) { // request update from GW every hour to keep in sync // Request time from controller. Serial.println("Requesting time..."); timeReceived = false; requestTime(); lastRequest = now; } // Update sensors every 5 seconds if (now - lastDisplay > 5000) { lastDisplay = now; request(LCD1_CHILD, V_TEXT, 0); // request new values from controller request(LCD2_CHILD, V_TEXT, 0); // request new values from controller } // Update LCD time every second if (now - lastUpdate > 1000) { LCD_time(); lastUpdate = now; } } // This is called when a message is received void receive(const MyMessage &message) { if (message.type == V_TEXT) { // Text messages only Serial.print("Message: "); Serial.print(message.sensor); Serial.print(", Message: "); Serial.println(message.getString()); // Write some debug info if (message.sensor == LCD1_CHILD) { writeScreen(0, message.data); } // Don't forget to change "if" to "else if" when controlling all 4 lines: else if (message.sensor == LCD2_CHILD) { writeScreen(1, message.data); } } } void receiveTime(unsigned long ts) { setTime(ts); timeReceived = true; } void LCD_time(void) { lcd.setCursor(0, 0); if (timeReceived) { lcd.print(day()); lcd.print("."); printDigits(month()); lcd.print("."); printDigits(year()); lcd.print(" "); printDigits(hour()); lcd.print(":"); printDigits(minute()); } else { writeScreen(0, "Waiting for time..."); } } void printDigits(int digits) { //add leading 0 if digit = 0-9 if (digits < 10) lcd.print('0'); lcd.print(digits); } void writeScreen(int line, String text) { // Remove anything over 20 char in text. if (text.length() > 19) { text.remove(20); } // Clear the line lcd.setCursor(0, line); lcd.print(LINE_BLANK); // Set Line lcd.setCursor(0, line); lcd.print(text); }```
Suggested Topics
-
SmartClock
pimatic • • Dheeraj