LCD-I2C | - Rain Sensors
Maybe your like
Menu Skip to content
LCD Connectors:
Note that the RG has the same pins from the last tutorial, everything done is built upon the serial output example.
The LCD screen requires 5v and MUST be powered by the arduino and not an external power supply as I2C requires this.
When raining the total screen should show up like this:
Once it starts raining(you can simulate rain by tapping on the RG lense) the device should show images like this.
The screen should be switching to a different statistic every 5 seconds from Event Acc to Total Acc. It’s also normal to not see anything in top right all the time as we only show accumulation when it is greater than 0.
RG Guides
- RG Arduino Guide
- Reading Serial Data With Arduino
- Reading Serial Data Part II
- Using Continuous Mode
- Logging Rain Data Into SD Card
- Access The Rain Gauge Through WiFi
- Database Guide
- InfluxDB
- Thingsboard
- Creating A Thingsboard Server
- RG Arduino Library Guide
- Hydreon Arduino Library
- Serial Output
- LCD-I2C
- Home
- RG Guides
- RG Arduino Library Guide
- LCD-I2C
- This example shows how to take the serialized data from the RG device and show it on a 16×2 LCD Screen.
- Before starting this make sure you have completed the RG Serial Output tutorial.
- Materials: Arduino, RG-15, mUSB cable, 8 connector wires (ground x2, 5v, V+, Rx, Tx, SDA, SCL), 16×2 LCD screen with IC2 Interface installed, and Breadboard.
- Note: If using the Arduino 33 IoT nano you must jump the VUSB on back of board. See here
Installation
- Please install the LCD Library.
- In Arduino IDE go to File->Examples and find RG15Examples (near bottom).
- For this tutorial we will be using LCDScreen.
Build
Arduino nano 33 IoT:
RG Connectors:| Color | Arduino nano | Arduino Mega | Arduino UNO | RG-15 |
|---|---|---|---|---|
| Red | 5v | 5v | 5v | V+ |
| Green | Ground(4) | GND | GND | G |
| Orange | Rx(1) | 10 | 2 | SO |
| Yellow | Tx(0) | 11 | 3 | SI |
| Color | Arduino nano | Arduino Mega | Arduino UNO | LCD-IC2 |
|---|---|---|---|---|
| Red | 5v | 5v | 5v | VCC |
| Black | Ground(~4) | GND | GND | GND |
| Orange | A4 | SDA | SDA | SDA |
| Yellow | A5 | SCL | SCL | SCL |
Note that the RG has the same pins from the last tutorial, everything done is built upon the serial output example.
The LCD screen requires 5v and MUST be powered by the arduino and not an external power supply as I2C requires this. Code
This is a follow along for the examples provided in the Hydreon Arduino library. If you just want it working and don’t need a detailed explanation, run the example after getting to this step and It will work as is. Verify it is working by comparing your screen output with the images found in the conclusion step near the bottom. The LCD screen should post clear and clean information about the RG sensor data. Using the LCD library values can easily be printed on the screen. First we need to assign the LCD address: LiquidCrystal_I2C lcd(0x27, 16, 2); This line represents a 16×2 LCD screen on address 0x27 Note: If 0x27 does not work for you, please try finding your IC2 address by scanning using this. Remember if you switch address off of 0x27 you must wire your arduino differently then the tutorial. The next step is to initialize the LCD screen: void setup() { lcd.begin(); ... mySerial.begin(9600); rg15.setStream(&mySerial); } The above code is pretty simple, initialize LCD screen and then set the stream for the RG-15. createChar() is also in setup and will look confusing right now but it will be explained later. Lets take apart the loop: void loop() { ... if(rg15.eventAcc > 0) { lcd.clear(); display("Event" , rg15.eventAcc, true); //Accumulation since last pole display. //Only shown if it is greater then 0. if(rg15.acc > 0) { lcd.setCursor(12,1); lcd.print("+"); lcd.print(rg15.acc * 1000, 0); lcd.print("mI"); } //IPH display lcd.setCursor(8,0); lcd.print(rg15.rInt,3); lcd.print("IPH"); delay(5000); //wait a bit before changing screens. } } The LCD screen will have two screens:- Displays total accumulation and an icon of the current weather
- Displays Event Accumulation, IPH, and Accumulation since last read.
- Event Accumulation.
- If rg15.acc is present(accumulation since last poll) then we display in bottom left.
- Display IPH on top right of screen.
Custom Rain Drop and Sun Icon
To make custom characters hex arrays are created to represent which pixels should be on. The example provides 7 hex arrays to create an image of a sun and create an icon of rain: uint8_t drop[8] = {0x4, 0x4, 0xe, 0xe, 0x1f, 0x1f, 0x1f, 0xe}; //sun symbol binary data for cosmetic purposes. uint8_t sun0[8] = {0x4,0x2,0x1,0x0,0x0,0x3,0x0,0x0}; uint8_t sun1[8] = {0x4,0x4,0x0,0xe,0x1f,0x1f,0x1f,0xe}; uint8_t sun2[8] = {0x0,0x8,0x10,0x0,0x0,0x1c,0x0,0x0}; uint8_t sun3[8] = {0x2,0x4,0x0,0x0,0x0,0x0,0x0,0x0} ; uint8_t sun4[8] = {0x4,0x4,0x8,0x0,0x0,0x0,0x0,0x0}; uint8_t sun5[8] = {0x18,0x04,0x0,0x0,0x0,0x0,0x0,0x0}; Register the hex arrays with lcd.createChar(): //make drop icon. lcd.createChar(0, drop); //make sun icon. lcd.createChar(1, sun0);https://rainsensors.com/wp-admin/tools.php lcd.createChar(2, sun1); lcd.createChar(3, sun2); lcd.createChar(4, sun3); lcd.createChar(5, sun4); lcd.createChar(6, sun5); lcd.home(); //end sun icon After assigning the custom character addresses we can call then with the lcd.write() function to display rain and sun these helper functions are in the example: void displayRain() { lcd.setCursor(11, 0); lcd.write(0); lcd.setCursor(9, 1); lcd.write(0); lcd.setCursor(0,0); } void displaySun() { lcd.setCursor(10,0); lcd.write(1); lcd.write(2); lcd.write(3); lcd.setCursor(10,1); lcd.write(4); lcd.write(5); lcd.write(6); lcd.setCursor(0,0); }Conclusion
When the RG boots, it should show a sun Icon on the screen. This icon should only be shown when no rain event is detected. The screen should look something like this:
When raining the total screen should show up like this:
Once it starts raining(you can simulate rain by tapping on the RG lense) the device should show images like this.
The screen should be switching to a different statistic every 5 seconds from Event Acc to Total Acc. It’s also normal to not see anything in top right all the time as we only show accumulation when it is greater than 0. Doc navigation
← Serial Output Was this article helpful to you? Yes 1 No 1 How can we help? Name Email subject messageTag » Arduino Nano Lcd I2c Example
-
LCD I2C | Arduino Tutorial
-
Interface I2C 16x2 LCD With Arduino Uno (Just 4 Wires)
-
Character I2C LCD With Arduino Tutorial (8 Examples)
-
How To Connect An I2C LCD Display To An Arduino NANO - YouTube
-
I2c LCD Arduino Tutorial And Example Code
-
Connect I2C LCD 16×2 Display To Arduino Nano - Linux Articles
-
In-Depth: Interfacing An I2C LCD With Arduino
-
Arduino Nano: I2C 2 X 16 LCD Display With Visuino - Instructables
-
I2C LCD On Arduino - Stunningly Easily Setup And Control
-
Arduino I2C LCD Tutorial - Circuit Geeks
-
I2C LCD With ESP32 On Arduino IDE - ESP8266 Compatible
-
Arduino LCD I2C Tutorial For Beginners - NerdyTechy