Pages: [1]   Go Down
Author Topic: program not allways starting  (Read 725 times)
0 Members and 1 Guest are viewing this topic.
hönsa
Offline Offline
Newbie
*
Karma: 0
Posts: 6
me rocks not allways
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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
    lcd.clear();
    preval = val;
    nytime = millis();
    varvtid = (nytime - time);
    time = nytime;
    lcd.setCursor(0, 1);
    lcd.print(60000/varvtid);
    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);
    lcd.print("km/h");
    
  } else {
    //lcd.clear();
    //lcd.setCursor(0, 0);
    //lcd.print("low");  // turn LED ON
    preval = val;
  }
  }
}




Logged

Bristol, UK
Offline Offline
Edison Member
*
Karma: 0
Posts: 1197
Exhibitor at UK Maker Faire
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

hönsa
Offline Offline
Newbie
*
Karma: 0
Posts: 6
me rocks not allways
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

ok, how can i do that?
Logged

Bristol, UK
Offline Offline
Edison Member
*
Karma: 0
Posts: 1197
Exhibitor at UK Maker Faire
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
« Last Edit: April 07, 2009, 05:44:34 am by anachrocomputer » Logged

hönsa
Offline Offline
Newbie
*
Karma: 0
Posts: 6
me rocks not allways
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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?

/johan
« Last Edit: April 07, 2009, 09:29:36 am by freiman » Logged

Keynsham, UK
Offline Offline
Full Member
***
Karma: 0
Posts: 224
I like for loops and walks on the beach,
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

You need to go into the folder containing the Arduino IDE and all it's components. Then go into -> Hardware -> Libraries -> LiquidCrystal -> LiquidCrystal.cpp
Logged

"C++ : Where friends have access to your private members." - Gavin Russell Baker

Bristol, UK
Offline Offline
Edison Member
*
Karma: 0
Posts: 1197
Exhibitor at UK Maker Faire
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
found something in the "liquidcrystal.cpp" file

Yes, that's it!

Quote
delayMicroseconds(2000) is this the right place?

Yes.

Quote
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.
Logged

hönsa
Offline Offline
Newbie
*
Karma: 0
Posts: 6
me rocks not allways
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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..

http://www1.elfa.se/elfa~se_sv/go.jsp?s=se-sv&a=48CB550CE142453BE10000000A0A036A
« Last Edit: April 09, 2009, 09:22:08 am by freiman » Logged

hönsa
Offline Offline
Newbie
*
Karma: 0
Posts: 6
me rocks not allways
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

/johan
Logged

London
Offline Offline
Faraday Member
**
Karma: 8
Posts: 6240
Have fun!
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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
Logged

Rimini (Italy)
Offline Offline
Newbie
*
Karma: 0
Posts: 15
Arduino rocks
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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:
#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):
  delayMicroseconds(15000);
  command(0x30);  // function set: 8 bits
  delayMicroseconds(4100);
  command(0x30);  // function set: 8 bits
  delayMicroseconds(100);
  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
  clear();
}

void LiquidCrystal::clear()
{
  command(0x01);  // clear display, set cursor position to zero
  delayMicroseconds(2000);
  // 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
  delayMicroseconds(2000);
}

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);
}

« Last Edit: April 13, 2009, 05:42:55 am by Sandrino » Logged

hönsa
Offline Offline
Newbie
*
Karma: 0
Posts: 6
me rocks not allways
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

ok, will try it tomorrow. thanks!!
Logged

Pages: [1]   Go Up
Jump to: