I have an question about an little project i'm making for my school.
I'm just a starting user, and ive got an little background with programming and building cerquit boards.
What is my project?:
I want to put the output of my Optical senor (I can read it out on the serial monitor) on my LCD with an I2C chip.
This is the code ive got so far.
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27,16,2);
const int led = 13;
int tcrt;
void setup(){
// set up the LCD's number of columns and rows:
lcd.init();
lcd.backlight();
// initialize the serial communications:
Serial.begin(9600);
pinMode (led, OUTPUT);
}
void loop(){
tcrt = analogRead(A0);
Serial.println(tcrt);
analogWrite(led, tcrt/4);
// when characters arrive over the serial port...
if (Serial.available()) {
// wait a bit for the entire message to arrive
delay(100);
// clear the screen
lcd.clear();
// read all the available characters
while (Serial.available() > 0) {
// display each character to the LCD
lcd.write(Serial.read());
}
}
}
First of all, please change the quote tags to code tags in your post. It makes it easier for people to read and understand your code The code tags are the "#" button above the row of smileys.
I can read it out on the serial monitor
Your program is doing what you expect when you output to serial monitor, is that right?
This is the code ive got so far.
Tell us what help you need. Does the code compile OK? If so, what happens when it runs, and how is that different from what you need?
if (Serial.available()) {
// wait a bit for the entire message to arrive
delay(100);
// clear the screen
lcd.clear();
// read all the available characters
while (Serial.available() > 0) {
// display each character to the LCD
lcd.write(Serial.read());
}
}
And this code is only writing to the LCD the characters you enter in serial monitor. So you may not need it any more.
The first thing to note is that opening the serial monitor on most Arduinos will reset the board and restart the program so some effect on the LCD is to be expected. What happens if you print some text to the LCD ? Does it work ?
Got it fixed.
But now i'm getting crazy figures instead of nummers.
This is what i see:
And this is the code i'm using:
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27,16,2);
const int led = 13;
int tcrt;
void setup(){
// set up the LCD's number of columns and rows:
lcd.init();
lcd.backlight();
// initialize the serial communications:
Serial.begin(9600);
pinMode (led, OUTPUT);
}
void loop(){
tcrt = analogRead(A0);
Serial.println(tcrt);
lcd.write(tcrt);
analogWrite(led, tcrt/4);
}
Allready thanks for the help so far!
This is an great community
In loop(), instead of lcd.write(tcrt);, try the following, to move the cursor back to home position each time and print the value as a number string, rather than as binary codes:
lcd.home();
lcd.print(tcrt);
delay(1000); // for testing only, wait 1 s before updating LCD with next number
Hackscribble:
In loop(), instead of lcd.write(tcrt);, try the following, to move the cursor back to home position each time and print the value as a number string, rather than as binary codes:
lcd.home();
lcd.print(tcrt);
delay(1000); // for testing only, wait 1 s before updating LCD with next number