Hello i'm new to this and not sure why the display isnt displaying anything, if i load a sample into the board it will display the words. Helloworld. but when i try my code i get nothing. im trying to build a temp sensor with a display. heres the code im using can someone point me in the right direction.
thanks
//ANDRELCD
//Compile with the Arduino IDE 1.0
//Libary version:1.1
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27,20,4); // set the LCD address to 0x27 for a 16 chars and 2 line display
const int analogInPin = A0;
const int SensorValueLow = 463;
const int SensorValueDiff = 36; // differance between high and low sensor value
const int TempValueDiff = 42; // differance between high and low Temp value
const int TempValueLow = 9;
int sensorValue = 0;
double Temp = 0;
void setup()
{
lcd.begin(20,2);
lcd.backlight();
}
void loop()
{
sensorValue = analogRead(analogInPin);
Temp = sensorValue-SensorValueLow;
Temp = Temp/SensorValueDiff;
Temp = Temp*TempValueDiff;
Temp = Temp+TempValueLow;
lcd.setCursor(0,0);
lcd.print("Value = ");
lcd.setCursor(7,0);
lcd.print(sensorValue);
lcd.setCursor(0,1);
lcd.print("Temp = ");
lcd.setCursor(7,1);
lcd.print(Temp);
delay(200);
}[code]
So take that code, remove everything in loop() and just put the "Hello World" and delay(2000); in and tell us what you get?
While you are at it, first things first.
Please go and read the instructions, then go back and modify your post (use the "More --> Modify" option to the bottom right of the post) to mark up the code (but it needs to be the complete code) as such so we can examine it conveniently and accurately. Do not post a ".ino" file as an attachment - that means that you are expecting people to actually load it to their IDE to look at it and that is extra unnecessary labour. In fact, attachments do not always show properly on different operating systems.
If you do not mark it up as code, the code you post could well be garbled and is certainly anything but easy to read, so you will find little enthusiasm for assistance with it.
Note: Also mark up any data in the same way. This includes error output that you get from the IDE.
And - before you post any code, use "Auto Format" in the Tools menu of the IDE to properly present the code.
Try and avoid unnecessary white space (blank lines). You should only use these to separate functional blocks of code.
ok so i cleaned up the code alittle bit and it compiles fine and loads with no errors but im still not getting anything on the display.
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27,20,4);
const int analogInPin = A0;
const int SensorValueLow = 463;
const int SensorValueDiff = 36; // differance between high and low sensor value
const int TempValueDiff = 42; // differance between high and low Temp value
const int TempValueLow = 9;
int sensorValue = 0;
double Temp = 0;
void setup()
{ Serial.begin(9600);
}
void loop()
{
sensorValue = analogRead(analogInPin);
Temp = sensorValue-486;
Temp = Temp/49;
Temp = Temp*60.5;
Temp = Temp+11.5;
Serial.print("Sensor = ");
Serial.print(sensorValue);
Serial.print(" ,Temp = ");
Serial.println(Temp);
delay(200);
}
if i load this code it works just fine and displays hello world.
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27,20,4); // set the LCD address to 0x27 for a 16 chars and 2 line display
void setup()
{
lcd.init(); // initialize the lcd
lcd.init();
// Print a message to the LCD.
lcd.backlight();
lcd.setCursor(3,0);
lcd.print("Hello, world!");
lcd.setCursor(2,1);
lcd.print("Ywrobot Arduino!");
lcd.setCursor(0,2);
lcd.print("Arduino LCM IIC 2004");
lcd.setCursor(2,3);
lcd.print("Power By Ec-yuan!");
}
Well, my point is that you are demonstrating two completely different pieces of code.
Try my original suggestion: Take the code that does not display, remove everything in loop() and just put the "Hello World" and delay(2000); in to the loop() and tell us what you get?
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27,20,4); // set the LCD address to 0x27 for a 16 chars and 2 line display
const int analogInPin = A0;
const int SensorValueLow = 463;
const int SensorValueDiff = 36; // differance between high and low sensor value
const int TempValueDiff = 42; // differance between high and low Temp value
const int TempValueLow = 9;
int sensorValue = 0;
double Temp = 0;
void setup()
{
lcd.begin(20,4);
lcd.backlight();
}
void loop()
{
"HelloWorld";
delay(2000);
}
sorry missed a part i fixed the code and tried it and still no display.
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27,20,4); // set the LCD address to 0x27 for a 16 chars and 2 line display
const int analogInPin = A0;
const int SensorValueLow = 463;
const int SensorValueDiff = 36; // differance between high and low sensor value
const int TempValueDiff = 42; // differance between high and low Temp value
const int TempValueLow = 9;
int sensorValue = 0;
double Temp = 0;
void setup()
{
lcd.begin(20,4);
lcd.backlight();
}
void loop()
{
lcd.print("Hello, World!");
delay(2000);
}
Why not install HD44780.h library via the IDE Library Manager ?
Connect SDA, SCL, 5V, GND. Run the examples. You will be working within minutes.
When you are happy, we can explain the reason for your current problem.
But the explanation is a bit complicated and historical. Ask if you really want to know.
95% of backpacks use RS on PCF8574 D0.
5% of backpacks use RS on PCF8574 D4.
Malpartida library defaults to RS on PCF8574 D4
Other backpack libraries might call themselves LiquidCrystal_I2C and may or may not default to different wiring.
PCF8574 Slave addresses are 0x20-0x27
PCF8574A Slave addresses are 0x38-0x3F
This all becomes complicated. Bill Perry's HD44780 library diagnoses and configures automatically.
It is a mystery why we still get the same LiquidCrystal_I2C questions.
HD44780 resolves most problems. And possesses diagnostic sketches for the rest.