Basic Lcd Node



  • Is there someone who can tell me where I'm going wrong, here I can't seem to get the data from another node, Am I missing something here or do I have to put something in on my transmitting node, not sure where to go from here.😕 HELP! Please.
    Thanks Andy

    
    #include <SPI.h>
    #include <MySensor.h>
    #include <LiquidCrystal_I2C.h>
    #include <Wire.h>
    #include <DHT.h>  
    
    
    #define CHILD_ID_HUM 0
    #define CHILD_ID_TEMP 1
    #define CHILD_ID_LIGHT 2
    #define HUMIDITY_SENSOR_DIGITAL_PIN 3
    #define LIGHT_SENSOR_ANALOG_PIN 0
    
    
    unsigned long SLEEP_TIME = 100; // Sleep time between reads (in milliseconds) (We do calculations and wait 5 ms between readings)
    int readingscounter      = 0;
    
    
    
    MySensor gw;
    
    LiquidCrystal_I2C lcd(0x27, 16, 2);
    
    //DHT dht;
    float lastTemp;
    float lastHum;
    boolean metric = true; 
    
    MyMessage msgHum(CHILD_ID_HUM, V_HUM);
    MyMessage msgTemp(CHILD_ID_TEMP, V_TEMP);
    MyMessage msgLight(CHILD_ID_LIGHT, V_LIGHT_LEVEL);
    int lastLightLevel;
    
    
    
    
    void setup()
    {
    
    
      // Register all sensors to gateway (they will be created as child devices)
      gw.begin();
      
      //DHT.setup(HUMIDITY_SENSOR_DIGITAL_PIN); 3
    
      // Send the Sketch Version Information to the Gateway
      gw.sendSketchInfo("Hum-Temp-Light-Lcd", "1.0");
    
      // Register all sensors to gw (they will be created as child devices)
      gw.present(CHILD_ID_HUM, S_HUM);
      gw.present(CHILD_ID_TEMP, S_TEMP);
      gw.present(CHILD_ID_LIGHT, S_LIGHT_LEVEL);
      
      
      
      metric = gw.getConfig().isMetric;
      
      
      
      
      gw.present(CHILD_ID_LIGHT, V_HUM);
      gw.present(CHILD_ID_TEMP, V_TEMP);
    
      
      
      delay(3000);
    
    }
    
    
    
    void loop()
    {
    
       int lightLevel = (1023-analogRead(LIGHT_SENSOR_ANALOG_PIN))/10.23; 
      Serial.println(lightLevel);
      if (lightLevel != lastLightLevel) {
         // gw.send(msg.set(lightLevel));
          lastLightLevel = lightLevel;
      }
    
      lcd.init();
      lcd.clear();
      lcd.backlight() ;
      lcd.setCursor(0, 0);
      lcd.print("Temperature: ");
      lcd.print("C ");
      lcd.print(V_TEMP );
      lcd.setCursor(0, 1);
      lcd.print("Humidity:    ");
      lcd.print("% ");
      lcd.print(V_HUM );
    
    }```

  • Hardware Contributor

    It is just a bunch of code from the internet.... maybe it is useful for you 😃

    #include <SPI.h>
    #include <MySensor.h>
    #include <Time.h>
    #include <Wire.h>
    #include <LiquidCrystal_I2C.h>
    #include <Timezone.h>    //https://github.com/JChristensen/Timezone
    #include <DS1307RTC.h>  // a basic DS1307 library that returns time as a time_t
    
    
    //Central European Time (Frankfurt, Paris)
    TimeChangeRule CEST = {"CEST", Last, Sun, Mar, 2, 120};     //Central European Summer Time
    TimeChangeRule CET = {"CET ", Last, Sun, Oct, 3, 60};       //Central European Standard Time
    Timezone CE(CEST, CET);
    
    MySensor gw;
    boolean timeReceived = false;
    unsigned long lastUpdate = 0, lastRequest = 0;
    
    // Sensor IDs
    #define ID_LINE2 1
    #define ID_LINE3 2
    #define ID_LINE4 3
    
    #define LINE_LENGTH 20
    
    
    LiquidCrystal_I2C lcd(0x27, 20, 4);
    
    TimeChangeRule *tcr;        //pointer to the time change rule, use to get the TZ abbrev
    
    time_t utc;
    
    void setup()
    {
       // Attach RTC
     setSyncProvider(RTC.get);   // the function to get the time from the RTC
     setSyncInterval(60);
     if (timeStatus() != timeSet)
       Serial.println("Unable to sync with the RTC");
     else
       Serial.println("RTC has set the system time");
       
     Serial.println("Starte Gateway");
     gw.begin(incomingMessage, AUTO, true);
    
     // Send the sketch version information to the gateway and Controller
     gw.sendSketchInfo("Display Sensor 4x20", "1.0");
     gw.present(ID_LINE2, S_CUSTOM);
     gw.present(ID_LINE3, S_CUSTOM);
     gw.present(ID_LINE4, S_CUSTOM);
    
    
    
     // Request latest time from controller at startup
     gw.requestTime(receiveTime);
    
     Serial.println("Starte LCD");
     // initialize the lcd for 16 chars 2 lines and turn on backlight
     lcd.begin();
    }
    
    void incomingMessage(const MyMessage &message) {
     if ((message.sensor >= ID_LINE2) && (message.sensor <= ID_LINE4)) {
       int iline = message.sensor - ID_LINE2 + 1;
       lcd.setCursor(0, iline);
       String sLine = message.getString();
       if (sLine.length() > LINE_LENGTH) {
         sLine = sLine.substring(0, 19);
       }
       
       lcdPrint(sLine);
       
       // Todo: Check if this is efficient enough
       for (int i = sLine.length(); i < LINE_LENGTH; i++) lcd.print(" ");
    
     }
    }
    
    // This is called when a new time value was received
    void receiveTime(unsigned long controllerTime) {
     // Ok, set incoming time
     Serial.print("Time value received: ");
     Serial.println(controllerTime);
     RTC.set(controllerTime); // this sets the RTC to the time from controller - which we do want periodically
     setTime(controllerTime);
     timeReceived = true;
    }
    
    void loop()
    {
     unsigned long now = millis();
     gw.process();
    
     // 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)
         || (timeReceived && now - lastRequest > 120 * 1000 * 60)) {
       // Request time from controller.
       Serial.println("requesting time");
       gw.requestTime(receiveTime);
       lastRequest = now;
     }
    
     // Update display every second
     if (now - lastUpdate > 1000) {
       updateDisplay();
       lastUpdate = now;
     }
    }
    
    
    void updateDisplay() {
    
     // Print date and time
     lcd.home();
     utc = now();
     printTime(CE.toLocal(utc, &tcr), tcr -> abbrev, "Zurich");
    }
    
    
    void printTime(time_t t, char *tz, char *loc)
    {
     sPrintI00(hour(t));
     sPrintDigits(minute(t));
     sPrintDigits(second(t));
     lcd.print(' ');
     sPrintI00(day(t));
     lcd.print('.');
     sPrintI00(month(t));
     lcd.print('.');
     lcd.print(year(t));
    }
    
    void sPrintI00(int val)
    {
     if (val < 10) lcd.print('0');
     lcd.print(val, DEC);
     return;
    }
    
    void sPrintDigits(int val)
    {
     lcd.print(':');
     if (val < 10) lcd.print('0');
     lcd.print(val, DEC);
    }
    
    
    
    void lcdPrint(String line)
    //  for HD44780 controller with ROM character set A00 
    {
     
     for(byte i=0;i<line.length();i++)
     {
       Serial.println((byte)line.charAt(i));
       
       switch ((byte)line.charAt(i))
       {
       case 0xC2: Serial.print("C2");
       break;
       case 0xC3: Serial.print("C3");
       break;
       case 0xCE: Serial.print("CE");
       break;
       case 0xCF: Serial.print("CF");
       break; // filtering UTF-8 highbyte  
       case 164: lcd.print('\xE1');break; // translate UTF-8 lowbyte
       case 182: lcd.print('\xEF');break; // translate UTF-8 lowbyte
       case 188: lcd.print('\xF5');break; // translate UTF-8 lowbyte
       case 176: lcd.print('\xDF');break; // degree symbol
       default: lcd.print(line.charAt(i));
       }
     }  
    }
    
    

    It is for a 4x20 LCD and uses an RTC. On the first line of the LCD you can see date an time. The other lines can show whatever you want....

    This code only works, if you have a gateway implementing requestTime and with a DS1307RTC.



  • @FotoFieber Thank you for your response much appreciated I'm not much of a coder but I can feel my way through if I have examples to work from and this will help a bit .
    Thank you Andy.



  • Having a bit of problem receiving Data from another node am I missing something here or do I need to add something to the transmitting node. Just can't think where to go from here.😕 HELP! Please.
    Andy.

    
    #include <SPI.h>
    #include <MySensor.h>
    #include <LiquidCrystal_I2C.h>
    #include <Wire.h>
    #include <DHT.h>  
    
    
    #define CHILD_ID_HUM 0
    #define CHILD_ID_TEMP 1
    #define CHILD_ID_LIGHT 2
    #define HUMIDITY_SENSOR_DIGITAL_PIN 3
    #define LIGHT_SENSOR_ANALOG_PIN 0
    
    
    unsigned long SLEEP_TIME = 100; // Sleep time between reads (in milliseconds) (We do calculations and wait 5 ms between readings)
    int readingscounter      = 0;
    
    
    
    MySensor gw;
    
    LiquidCrystal_I2C lcd(0x27, 16, 2);
    
    //DHT dht;
    float lastTemp;
    float lastHum;
    boolean metric = true; 
    
    MyMessage msgHum(CHILD_ID_HUM, V_HUM);
    MyMessage msgTemp(CHILD_ID_TEMP, V_TEMP);
    MyMessage msgLight(CHILD_ID_LIGHT, V_LIGHT_LEVEL);
    int lastLightLevel;
    
    
    
    
    void setup()
    {
    
    
      // Register all sensors to gateway (they will be created as child devices)
      gw.begin();
      
      //DHT.setup(HUMIDITY_SENSOR_DIGITAL_PIN); 3
    
      // Send the Sketch Version Information to the Gateway
      gw.sendSketchInfo("Hum-Temp-Light-Lcd", "1.0");
    
      // Register all sensors to gw (they will be created as child devices)
      gw.present(CHILD_ID_HUM, S_HUM);
      gw.present(CHILD_ID_TEMP, S_TEMP);
      gw.present(CHILD_ID_LIGHT, S_LIGHT_LEVEL);
      
      
      
      metric = gw.getConfig().isMetric;
      
      
      
      
      gw.present(CHILD_ID_LIGHT, V_HUM);
      gw.present(CHILD_ID_TEMP, V_TEMP);
    
      
      
      delay(3000);
    
    }
    
    
    
    void loop()
    {
    
       int lightLevel = (1023-analogRead(LIGHT_SENSOR_ANALOG_PIN))/10.23; 
      Serial.println(lightLevel);
      if (lightLevel != lastLightLevel) {
         // gw.send(msg.set(lightLevel));
          lastLightLevel = lightLevel;
      }
    
      lcd.init();
      lcd.clear();
      lcd.backlight() ;
      lcd.setCursor(0, 0);
      lcd.print("Temperature: ");
      lcd.print("C ");
      lcd.print(V_TEMP );
      lcd.setCursor(0, 1);
      lcd.print("Humidity:    ");
      lcd.print("% ");
      lcd.print(V_HUM );
    
    }
    

  • Hero Member

    @andyuno , if you want to send Temp data from your sensor to the gateway/controller, you need uncomment the gw.send line at your code above.

    Maybe you also want to include a gw.sleep at end of loop process, to avoid too many pooling at the sensor (causes temperature increase as well as drains the battery very fast). Something like a 5-15min sleep between every loop?



  • @rvendrame thanks I think I get what you mean I'll give that a go still not sure if I'm On the right path.



  • Did you ever get this going if so can you share the code? My project is similar have a few temp sensors around and send them to an lcd screen node. Lcd can be a repeater to the gateway for logging on domoticz, also if so what extra code did you add on the temp sensor side?


Log in to reply
 

Suggested Topics

  • 4
  • 5
  • 3
  • 274
  • 933
  • 14

0
Online

11.2k
Users

11.1k
Topics

112.5k
Posts