Go Down

Topic: program not allways starting (Read 2828 times) previous topic - next topic


got a problem with my speedometer that my brother and i build.
some times when i start, the program doesn't seems to start the lcd just goes blank. it has made this both in car and on the bench when we first wired it up.

it's made of a decimilia card, a lcd display and a hall sender that response to a magnet.

here is the prg.. help please..

#include <LiquidCrystal.h>

// LiquidCrystal display with:
// rs on pin 12
// rw on pin 11
// enable on pin 10
// d0, d1, d2, d3 on pins 5, 4, 3, 2
LiquidCrystal lcd(12, 11, 10, 5, 4, 3, 2);
int inPin = 7;   // choose the input pin (for a pushbutton)
int val = 0;     // variable for reading the pin status
int preval = 0;
unsigned long hastighet = 0;
unsigned long time = 0;
unsigned long nytime = 0;
unsigned long varvtid;

void setup() {
   pinMode(inPin, INPUT);    // declare pushbutton as input
   lcd.setCursor(3, 0);
   lcd.print ("hey ho");
   lcd.setCursor (5, 1);
   lcd.print("let's go");

void loop(){
 val = digitalRead(inPin);  // read input value
 if (val != preval) {
 if (val == LOW) {    // check if the input is low (button released)
   //lcd.setCursor(0, 0);
   //lcd.print("high");  // turn LED OFF
   preval = val;
   nytime = millis();
   varvtid = (nytime - time);
   time = nytime;
   lcd.setCursor(0, 1);
   lcd.setCursor(4, 1);
   lcd.print("rpm pa utg");
   hastighet = (((60000/varvtid)/3.25*0.2*0.6));
   lcd.setCursor(0, 0);
   lcd.print(hastighet );
   lcd.setCursor(10, 0);
 } else {
   //lcd.setCursor(0, 0);
   //lcd.print("low");  // turn LED ON
   preval = val;


The start-up delays inside the LiquidCrystal library are not quite long enough for some types of LCD controller chip.  You may have to go into the source code for that library and make the delays longer.



Apr 07, 2009, 12:43 pm Last Edit: Apr 07, 2009, 12:44 pm by anachrocomputer Reason: 1
You'll need to find the source code files for LiquidCrystal.  They'll be in a subdirectory under the main Arduino directory.  Once you've done that, look for the code that is the constructor for LiquidCrystal objects.  In there, you'll find a number of calls to 'delayMicroseconds()', which need to be changed.  After making the changes, restart the Arduino IDE to force it to recompile the class.


Apr 07, 2009, 04:24 pm Last Edit: Apr 07, 2009, 04:29 pm by freiman Reason: 1
been looking in the folders. found something in the "liquidcrystal.cpp" file, it said delayMicroseconds(2000) is this the right place? and if so how much is recomended to add?



You need to go into the folder containing the Arduino IDE and all it's components. Then go into -> Hardware -> Libraries -> LiquidCrystal -> LiquidCrystal.cpp
"C++ : Where friends have access to your private members." - Gavin Russell Baker


found something in the "liquidcrystal.cpp" file

Yes, that's it!

delayMicroseconds(2000) is this the right place?


how much is recomended to add?

The correct delays are documented in the HD44780 data sheet, but to begin with, you could try doubling all the delays (they're all a few milliseconds) and then recompiling.  Test it to see if it's more reliable and if not, double them again...

I'll look up the proper delays at home, where I have the data sheet.


Apr 09, 2009, 04:18 pm Last Edit: Apr 09, 2009, 04:22 pm by freiman Reason: 1
been testing to change the delay time, from 2000ms to 6000, 8000 and 10000ms but without any luck..

what happends is that when i turn on the power is: the top row(it's a 16x2 lcd) goes all black then if i'm lucky it goes on to the "hey ho let's go" message and the speedo start show the speed. but.. sometimes it only get blank after the top row been all black..

anything else i can try?

here is the lcd, under "dokument" is an pdf about it..



hi, so i should try and replace what's in "liquidcrystal.ccp" with the text? or am i having bad luck during thinking?



You may want to try the modification to LiquidCrystal suggested in this thread: http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1236566774/8#8


Apr 13, 2009, 11:20 am Last Edit: Apr 13, 2009, 12:42 pm by Sandrino Reason: 1
If you are using 4-bits mode, i suggest you this modified version of liquidcrystal.cpp i wrote for my display DE-LM002 (sureelectronics.net):

Code: [Select]
#include "LiquidCrystal.h"

#include <stdio.h>
#include <string.h>
#include <inttypes.h>
#include "WProgram.h"

LiquidCrystal::LiquidCrystal(uint8_t rs, uint8_t rw, uint8_t enable,
 uint8_t d0, uint8_t d1, uint8_t d2, uint8_t d3) :
 _rs_pin(rs), _rw_pin(rw), _enable_pin(enable)
 _data_pins[0] = d0;
 _data_pins[1] = d1;
 _data_pins[2] = d2;
 _data_pins[3] = d3;
 pinMode(_rs_pin, OUTPUT);
 pinMode(_rw_pin, OUTPUT);
 pinMode(_enable_pin, OUTPUT);
 for (int i = 0; i < 4; i++){
   pinMode(_data_pins[i], OUTPUT);
 // Reset, 4 bits operation (do not use delay(x) command):
 command(0x30);  // function set: 8 bits
 command(0x30);  // function set: 8 bits
 command(0x30);  // function set: 8 bits
 command(0x20);  // function set: 4 bits
 command(0x28);  // function set: 4 bits, 1 line, 5x8 dots
 command(0x0C);  // display control: turn display on, cursor off, no blinkingcommand(0x0C)
 command(0x06);  // entry mode set: increment automatically, display shift, right shift

void LiquidCrystal::clear()
 command(0x01);  // clear display, set cursor position to zero
 // again, cursor off command:
 command(0x0C);  // display control: turn display on, cursor off, no blinkingcommand(0x0C)


void LiquidCrystal::home()
 command(0x02);  // set cursor position to zero

void LiquidCrystal::setCursor(int col, int row)
 int row_offsets[] = { 0x00, 0x40, 0x14, 0x54 };
 command(0x80 | (col + row_offsets[row]));


void LiquidCrystal::command(uint8_t value) {
 send(value, LOW);

void LiquidCrystal::write(uint8_t value) {
 send(value, HIGH);

void LiquidCrystal::send(uint8_t value, uint8_t mode) {
 digitalWrite(_rs_pin, mode);
 digitalWrite(_rw_pin, LOW);

   for (int i = 0; i < 4; i++) {
     digitalWrite(_data_pins[i], (value >> (i + 4)) & 0x01);
   digitalWrite(_enable_pin, HIGH);
   digitalWrite(_enable_pin, LOW);
   for (int i = 0; i < 4; i++) {
     digitalWrite(_data_pins[i], (value >> i) & 0x01);

   digitalWrite(_enable_pin, HIGH);
   digitalWrite(_enable_pin, LOW);


ok, will try it tomorrow. thanks!!

Go Up