Im making a project using a DHT22 sensor and a LCD1602 I2c 16x2 module and was trying to put the temperature and humidity values on the screen but the screen wont display anything. Heres the link to it I2C 16x2 LCD Module | The Pi Hut
The screen is on but on the top line are black blocks and the bottom is just blank.
also here is the code.
I am using an Arduino uno r3 with arduino ide
#include <dht.h>
#include <LiquidCrystal_I2C.h>
#define dataPin 2 // Defines pin number to which the sensor is connected
dht DHT; // Creats a DHT object
LiquidCrystal_I2C lcd(0x27, 20, 4);
void setup()
{ lcd.init(); // Initialize the LCD
}
void loop()
{
int readData = DHT.read22(dataPin); // DHT22/AM2302
float t = DHT.temperature; // Gets the values of the temperature
float h = DHT.humidity; // Gets the values of the humidity
lcd.backlight(); // Turn on the backlight
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("temperature= ");
lcd.print((int)t); // Display temperature on the LCD
lcd.setCursor(0,1);
lcd.print("humidity= ");
lcd.print((int)h); // Display humidity on the LCD
lcd.print("%");
delay(2000);
}
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
// Set the LCD address to 0x27 for a 16 chars and 2 line display
LiquidCrystal_I2C lcd(0x27, 16, 2);
void setup()
{
// initialize the LCD
lcd.begin();
// Turn on the blacklight and print a message.
lcd.backlight();
lcd.print("Hello, world!");
}
void loop()
{
// Do nothing here...
}
C:\Users\EM.ZEE\Downloads\LCD1602_I2C_Module_code\LCD1602_I2C_Module_code\Arduino\test\test.ino: In function 'void setup()':
C:\Users\EM.ZEE\Downloads\LCD1602_I2C_Module_code\LCD1602_I2C_Module_code\Arduino\test\test.ino:10:12: error: no matching function for call to 'LiquidCrystal_I2C::begin()'
lcd.begin();
^
In file included from C:\Users\EM.ZEE\Downloads\LCD1602_I2C_Module_code\LCD1602_I2C_Module_code\Arduino\test\test.ino:2:0:
C:\Users\EM.ZEE\Documents\Arduino\libraries\LiquidCrystal_I2C/LiquidCrystal_I2C.h:58:8: note: candidate: void LiquidCrystal_I2C::begin(uint8_t, uint8_t, uint8_t)
void begin(uint8_t cols, uint8_t rows, uint8_t charsize = LCD_5x8DOTS );
^~~~~
C:\Users\EM.ZEE\Documents\Arduino\libraries\LiquidCrystal_I2C/LiquidCrystal_I2C.h:58:8: note: candidate expects 3 arguments, 0 provided
exit status 1
Compilation error: no matching function for call to 'LiquidCrystal_I2C::begin()'
You are not following the instructions on the link you posted! That is why it is not working.
The libraries and code you are using assume the LCD has an HD44780 display driver chip and a PCF8574 i2c adapter chip on a backpack. This is the most common setup used with Arduino.
Your LCD is completely different. It uses a AiP31068L driver chip which has a native i2c interface.
Re-visit the shop and follow the links to the Waveshare site.
Read all relevant information and download some files.
Do the demo and learn how to use this.
Now you'll be ready to go on with your project.
Lots of success.
The hd44780.h library by Bill Perry also comes with an i/o class for the LCDs that have a native i2c interface using the AIP31068 chips
It is available through the library manager.
Try to run the Hello World example sketch for that class of display.
// ----------------------------------------------------------------------------
// HelloWorld - simple demonstration of lcd
// Created by Bill Perry 2016-07-02
// bperrybap@opensource.billsworld.billandterrie.com
//
// This example code is unlicensed and is released into the public domain
// ----------------------------------------------------------------------------
//
// This sketch is for LCD modules that have a native I2C interface such as
// PCF2119x, PCF2116, or certain RayStar LCDs rather than those LCD modules that
// use an i/o expander chip based based backpack.
// NOTE:
// These devices usually need external pullups as they typically are not on
// the module.
// WARNING:
// Use caution when using 3v only processors like arm and ESP8266 processors
// when interfacing with 5v modules as not doing proper level shifting or
// incorrectly hooking things up can damage the processor.
//
// Sketch prints "Hello, World!" on the lcd
//
// If initialization of the LCD fails and the arduino supports a built in LED,
// the sketch will simply blink the built in LED.
//
// ----------------------------------------------------------------------------
// LiquidCrystal compability:
// Since hd44780 is LiquidCrystal API compatible, most existing LiquidCrystal
// sketches should work with hd44780 hd44780_I2Clcd i/o class once the
// includes are changed to use hd44780 and the lcd object constructor is
// changed to use the hd44780_I2Clcd i/o class.
#include <Wire.h>
#include <hd44780.h>
#include <hd44780ioClass/hd44780_I2Clcd.h> // i2c LCD i/o class header
// Note, i2c address can be specified or automatically located
// If you wish to use a specific address comment out this constructor
// and use the constructor below that specifies the address
// declare the lcd object for auto i2c address location
hd44780_I2Clcd lcd;
//
// enter address of LCD.
// Addresses seen so far include:
// - 0x3a, 0x3b (PCF2119x)
// - 0x3c (unknwon chip)
// - 0x3d (unknwon chip)
// - 0x3e (unknwon chip)
// - 0x3f (unknwon chip)
// declare i2c address and constructor for specified i2c address
//const int i2c_addr = 0x3e;
//hd44780_I2Clcd lcd(i2c_addr); // use device at this address
// LCD geometry
const int LCD_COLS = 16;
const int LCD_ROWS = 2;
void setup()
{
int status;
// initialize LCD with number of columns and rows:
// hd44780 returns a status from begin() that can be used
// to determine if initalization failed.
// the actual status codes are defined in <hd44780.h>
// See the values RV_XXXX
//
// looking at the return status from begin() is optional
// it is being done here to provide feedback should there be an issue
//
status = lcd.begin(LCD_COLS, LCD_ROWS);
if(status) // non zero status means it was unsuccesful
{
// begin() failed so blink error code using the onboard LED if possible
hd44780::fatalError(status); // does not return
}
// Print a message to the LCD
lcd.print("Hello, World!");
}
void loop() {}
That's new to me so good to hear that.
I prefer Bill Perry's library because of the superior possibilities and it's autodetect functionality.
Thanks for pointing this out, if not TS, you still helped someone with your reply.