Wiero Screen Problem.
hi all,
i have strange problem 20x4 lcd screen when uploading arduino. when add following lines of code , upload them sends screen crazy random japanese type characters though compiles fine.
if remove above lines of code arduino project works perfectly. above code in main loop body of code show below.
does have idea's i'm mystified.
i have strange problem 20x4 lcd screen when uploading arduino. when add following lines of code , upload them sends screen crazy random japanese type characters though compiles fine.
code: [select]
if (movesteps < 0){
lcd.print (" left ");
}
if (movesteps > 0){
lcd.print (" right ");
}if remove above lines of code arduino project works perfectly. above code in main loop body of code show below.
does have idea's i'm mystified.
code: [select]
//include button library
#include <button.h>
// include library code:
#include <liquidcrystal.h>
// initialize library numbers of interface pins
liquidcrystal lcd(12, 11, 5, 4, 3, 2);
#include <pololuwheelencoders.h>
pololuwheelencoders encoder;
char val1, val2;
char s;
int = 0;
button button_left = button(6,pullup);
//button button_ent = button (7, pullup);
button button_right = button(7,pullup);
int buttonloop;
unsigned long previousmillis;
void setup()
{
lcd.begin(20, 4);
pinmode(8, output);
pinmode(9, output);
digitalwrite(8, low);
digitalwrite(9, low);
pinmode(13,output);
digitalwrite(13,low);
//initialize encoder pins 10,13
encoder.init(10,13,255,255);
serial.begin(9600);
lcd.setcursor(0,0);
lcd.print("********************");
lcd.setcursor(0,1);
lcd.print("* asrtosky *");
lcd.setcursor(0,2);
lcd.print("* dome runner *");
lcd.setcursor(0,3);
lcd.print("********************");
delay (4000);
lcd.setcursor(0,0);
lcd.print(" ");
lcd.setcursor(0,1);
lcd.print(" ");
lcd.setcursor(0,2);
lcd.print(" ");
lcd.setcursor(0,3);
lcd.print(" ");
lcd.setcursor(0,0);
lcd.print("astrosky domerunner");
lcd.setcursor(0,1);
lcd.print("====================");
lcd.setcursor(6,3);
lcd.print("az: ");
//lcd.setcursor(11,3);
//lcd.print(" deg");
}
const int max_len = 4; // max digits in number plus decimal point
char strvalue[max_len + 1]; // add 1 terminating null
int index = 0;
int value1;
int value2;
int diffvall;
int movesteps;
void loop()
{
//serial.print("current millis : ");
//serial.println(millis());
lcd.setcursor(10,3);
lcd.print(value1);
getaz();
value1 = value2;
lcd.setcursor(10,3);
lcd.print(value1);
buttonpress();
llegirpos();
if (millis() - previousmillis > 15000){
previousmillis = millis();
getvalue2();
lcd.setcursor(15,2);
lcd.print(" ");
diffvall = (value2 - value1);
lcd.setcursor(15,2);
lcd.print(diffvall);
movesteps = (diffvall * 10);
lcd.setcursor(0,0);
lcd.println(movesteps);
if (movesteps < 0){
lcd.print (" left ");
}
if (movesteps > 0){
lcd.print (" right ");
}
}
}
void getaz(){
if( serial.available())
{
char ch = serial.read();
if(index < max_len && ch != 13) // 13 ascii value of carriage return
{
strvalue[index++] = ch; // add ascii character string;
}
else
{
// here when buffer full or on first non digit
strvalue[index] = '\0'; // terminate string 0
index = 0; // reset index next string
lcd.setcursor(10,3);
//serial.println(strvalue);
//lcd.print(value);
}
}
}
void getvalue2(){
value2 = atoi(strvalue); // use atof convert string float
lcd.setcursor(15,3);
lcd.print(value2);
previousmillis = millis();
//serial.print("previous millis : ");
//serial.print(previousmillis);
//serial.println();
}
void buttonpress() {
while(button_left.ispressed()) {
digitalwrite(8, high);
digitalwrite(9, high);
lcd.setcursor(1,3);
lcd.print("<--- ");
}
digitalwrite(8, low);
lcd.setcursor(1,3);
lcd.print(" ");
while(button_right.ispressed()) {
digitalwrite(8, high);
digitalwrite(9, low);
lcd.setcursor(15,3);
lcd.print("---> ");
}
digitalwrite(8, low);
lcd.setcursor(15,3);
lcd.print(" ");
}
//capture encoder counts.
void llegirpos() {
lcd.setcursor(1,2);
lcd.print("encoder: ");
lcd.print( encoder.getcountsm1(), dec );
lcd.print (" ");
}
ribuck,
the top part of code not source of problem. it's somewhere deep dark down inside code. i'll try , see.
this code works fine test top part of post.
:-?
the top part of code not source of problem. it's somewhere deep dark down inside code. i'll try , see.
this code works fine test top part of post.
code: [select]
#include <liquidcrystal.h>
liquidcrystal lcd(12, 11, 10, 5, 4, 3, 2);
int movesteps = -1;
void setup() {
lcd.begin(16,2);
}
void loop() {
if (movesteps < 0){
lcd.print (" left ");
}
if (movesteps > 0){
lcd.print (" right ");
}
lcd.home();
}
:-?
Arduino Forum > Forum 2005-2010 (read only) > Software > Syntax & Programs > Wiero Screen Problem.
arduino
Comments
Post a Comment