16x2 Green LCD with Soldered I2C/IIC Interface Documentation
The 16x2 Green LCD with Soldered I2C/IIC Interface is a compact and versatile liquid crystal display module designed for use in a wide range of IoT applications. This module features a 16-character x 2-line display with a bright green backlight, making it suitable for both indoor and outdoor use. The soldered I2C/IIC interface allows for easy connection to microcontrollers and other devices, enabling swift integration into various projects.
Display Type: ST7066U 16x2 Character LCD
Backlight: Green LED
Interface: I2C/IIC (soldered)
Operating Voltage: 5V
Operating Current: 10mA (typical)
Dimensions: 80x36mm
### Example 1: Basic LCD Initialization and Text Display using Arduino
This example demonstrates how to initialize the LCD and display a simple message using an Arduino board.
```c
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
// Define the LCD I2C address (may vary depending on the module)
#define LCD_I2C_ADDRESS 0x27
// Initialize the LCD
LiquidCrystal_I2C lcd(LCD_I2C_ADDRESS, 16, 2);
void setup() {
// Initialize the LCD
lcd.init();
lcd.backlight();
lcd.setCursor(0, 0);
lcd.print("Hello, world!");
}
void loop() {
// Do nothing, the message will remain displayed
}
```
### Example 2: Displaying Sensor Data on the LCD using Raspberry Pi (Python)
This example shows how to connect the LCD to a Raspberry Pi and display sensor data using Python. In this example, we'll use a DHT11 temperature and humidity sensor.
```python
import RPi.GPIO as GPIO
import time
import Adafruit_DHT
import smbus
# Define the LCD I2C address
LCD_I2C_ADDRESS = 0x27
# Initialize the I2C bus
bus = smbus.SMBus(1)
# Define the LCD commands
LCD_CLEARDISPLAY = 0x01
LCD_RETURNHOME = 0x02
LCD_SETDDRamADDR = 0x80
# Initialize the LCD
def lcd_init():
bus.write_byte(LCD_I2C_ADDRESS, LCD_CLEARDISPLAY)
bus.write_byte(LCD_I2C_ADDRESS, LCD_RETURNHOME)
# Set the LCD cursor position
def lcd_set_cursor(row, col):
bus.write_byte(LCD_I2C_ADDRESS, LCD_SETDDRamADDR + row 0x40 + col)
# Print a string on the LCD
def lcd_print(string):
for char in string:
bus.write_byte(LCD_I2C_ADDRESS, ord(char))
# Initialize the sensor
dht_sensor = Adafruit_DHT.DHT11
while True:
# Read sensor data
humidity, temperature = Adafruit_DHT.read(dht_sensor, 4)
# Clear the LCD
lcd_init()
# Set the cursor to the first row
lcd_set_cursor(0, 0)
# Print the temperature
lcd_print("Temp: {:.1f}C".format(temperature))
# Set the cursor to the second row
lcd_set_cursor(1, 0)
# Print the humidity
lcd_print("Humidity: {:.1f}%".format(humidity))
# Wait 1 second before updating the display again
time.sleep(1)
```
### Example 3: Scrolling Marquee Text using ESP32 (C++)
This example demonstrates how to create a scrolling marquee text effect on the LCD using an ESP32 board.
```c
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
// Define the LCD I2C address
#define LCD_I2C_ADDRESS 0x27
// Initialize the LCD
LiquidCrystal_I2C lcd(LCD_I2C_ADDRESS, 16, 2);
void setup() {
// Initialize the LCD
lcd.init();
lcd.backlight();
}
void loop() {
// Set the cursor to the first row
lcd.setCursor(0, 0);
// Define the marquee text
char marquee_text[] = "Hello, world! This is a long message that will scroll.";
// Set the scrolling speed (higher values = faster scrolling)
int scroll_speed = 500;
// Scroll the marquee text
for (int i = 0; i < strlen(marquee_text); i++) {
// Clear the LCD
lcd.clear();
// Print the marquee text, starting from the current position
lcd.print(marquee_text + i);
// Wait for the scrolling speed
delay(scroll_speed);
// Move the cursor to the next position
lcd.setCursor(0, 0);
}
}
```
Note: These examples are for illustrative purposes only and may require adjustments to work with your specific setup. Ensure you have the necessary libraries and dependencies installed before attempting to run the code.