Show Posts
Pages: [1]
1  Using Arduino / Displays / Re: Uno R3 + 20x4 I2C LCD - screen freezes / garbage on: December 02, 2012, 10:02:07 pm
Give it a shot with a 2K2 resistor and check how the LCD is grounded. If you have long lead going to the LCD you may have added too much capacitance to the line and a 4k7 may be a bit too much. How long are your wires going to the LCD?
Do you have other i2c devices connected?

I've had this cabled up with 40cm leads for the power pins (one 20cm female-female and one 20cm male-male combined into a 40cm male-female) with the leads going to the ground and +5V rails on a breadboard. From there I'm using short (~10cm) breadboard wires to the +5V and GND pins of the Arduino.) The SDA and SCL leads are 20cm from LCD to breadboard, and 20cm from breadboard to Arduino.

I've now replaced the leads with single 20cm male-female leads and connected them all directly to the Arduino, and the counter's now going for about a minute before the display corrupts, so it looks like I'm on the right track with this.

I've also tried 2k2 and 4k7 pullup resistors, where the wiring is: 20cm lead from LCD VCC to breadboard +5v; 20cm lead from LCD GND to Arduino GND; 20cm SDA and SCL leads from LCD to breadboard and from breadboard to Arduino; resistor from breadboard signal to breadboard +5v. This gives about the same result as above, i.e. the counter runs for about a minute before the screen corrupts.

I don't have any other I2C devices connected at the moment. I do have a DS1307 RTC that I'm planning to use with this project and seems to function correctly in the test sketches I've used with it, i.e. I can set its clock and sync to its clock.
2  Using Arduino / Displays / Re: Uno R3 + 20x4 I2C LCD - screen freezes / garbage on: December 01, 2012, 01:26:27 am
OK, I've trimmed this down as much as I can. The "hello world" printed to the LCD in setup() works fine, and then the mills() counter starts. On the serial line it continues fine, but on the LCD it gets as far as ~4k to ~6k (i.e. 4 to 6 seconds) and then stops.

I'm using the IDE version 1.0.2 on Mac OSX Mountain Lion on a 2012 macbook Pro 15". I've copied the new LiquidCrystal library V1.2.1 (from here https://bitbucket.org/fmalpartida/new-liquidcrystal/downloads) into my libraries folder.

I've tried this with 4k7 pull-up resistors between SDA and +5V and between SDL and +5V.

Code:
//DFRobot.com
//Compatible with the Arduino IDE 1.0
//Library version:1.1
#include <Wire.h>
#include <LCD.h>
#include <LiquidCrystal_I2C.h>  // F Malpartida's NewLiquidCrystal library

#define I2C_ADDR    0x20  // Define I2C Address where the PCF8574A is

#define BACKLIGHT_PIN     7
#define En_pin  4
#define Rw_pin  5
#define Rs_pin  6
#define D4_pin  0
#define D5_pin  1
#define D6_pin  2
#define D7_pin  3

#define  LED_OFF  0
#define  LED_ON  1
 
LiquidCrystal_I2C  lcd(I2C_ADDR,En_pin,Rw_pin,Rs_pin,D4_pin,D5_pin,D6_pin,D7_pin);

void setup()
{
  Serial.begin(9600);
 
  lcd.begin (20,4);  // initialize the lcd
  // Switch on the backlight
  lcd.setBacklightPin(BACKLIGHT_PIN,NEGATIVE);
  lcd.setBacklight(LED_ON);
 
  lcd.setCursor(0, 0);
  lcd.print("Hello world");
  delay(1000);
  lcd.setCursor(0, 0);
  lcd.print("           "); 
}

void loop()
{
delay(1000);

  Serial.println(millis());
 
  lcd.setCursor ( 0, 0 );
  lcd.print(millis());
}
3  Using Arduino / Displays / Re: Uno R3 + 20x4 I2C LCD - screen freezes / garbage on: November 30, 2012, 09:24:40 pm
I'm starting to think this must be a hardware problem.

I'm now using the sketch below to test this display. The LCD is from DX.com, part number GY-LCD-V1. This thread gives the code for setting the screen up: http://arduino.cc/forum/index.php/topic,106655.0.html.

This sketch is based on the sketch in that thread. It basically prints the number of seconds since startup to the serial line and the LCD display. The serial line keeps counting, but the screen gets about as far as 4 or 6 and then just stops. Pressing the reset button on the board restarts the sketch and the serial line begins counting from 1, but the screen won't re-initialise - I have to remove the USB cable to do that.

Code:
//DFRobot.com
//Compatible with the Arduino IDE 1.0
//Library version:1.1
#include <Wire.h>
#include <LCD.h>
#include <LiquidCrystal_I2C.h>  // F Malpartida's NewLiquidCrystal library
#include <Time.h>

#define I2C_ADDR    0x20  // Define I2C Address where the PCF8574A is

#define BACKLIGHT_PIN     7
#define En_pin  4
#define Rw_pin  5
#define Rs_pin  6
#define D4_pin  0
#define D5_pin  1
#define D6_pin  2
#define D7_pin  3

#define  LED_OFF  0
#define  LED_ON  1

#define printByte(args)  write(args);

uint8_t bell[8]  = {0x4,0xe,0xe,0xe,0x1f,0x0,0x4};
uint8_t note[8]  = {0x2,0x3,0x2,0xe,0x1e,0xc,0x0};
uint8_t clock[8] = {0x0,0xe,0x15,0x17,0x11,0xe,0x0};
uint8_t heart[8] = {0x0,0xa,0x1f,0x1f,0xe,0x4,0x0};
uint8_t duck[8]  = {0x0,0xc,0x1d,0xf,0xf,0x6,0x0};
uint8_t check[8] = {0x0,0x1,0x3,0x16,0x1c,0x8,0x0};
uint8_t cross[8] = {0x0,0x1b,0xe,0x4,0xe,0x1b,0x0};
uint8_t retarrow[8] = { 0x1,0x1,0x5,0x9,0x1f,0x8,0x4};
 
LiquidCrystal_I2C  lcd(I2C_ADDR,En_pin,Rw_pin,Rs_pin,D4_pin,D5_pin,D6_pin,D7_pin);

void setup()
{
  Serial.begin(9600);
 
  lcd.begin (20,4);  // initialize the lcd
  // Switch on the backlight
  lcd.setBacklightPin(BACKLIGHT_PIN,NEGATIVE);
  lcd.setBacklight(LED_ON);
 
  lcd.createChar(0, bell);
  lcd.createChar(1, note);
  lcd.createChar(2, clock);
  lcd.createChar(3, heart);
  lcd.createChar(4, duck);
  lcd.createChar(5, check);
  lcd.createChar(6, cross);
  lcd.createChar(7, retarrow);
  lcd.home();
 
  lcd.setCursor(0, 0);
  for(int i = 0;i < 20; i++)  lcd.printByte(6);
  lcd.setCursor(0, 1);
  lcd.printByte(6);
  lcd.print("   Hello world    ");
  lcd.printByte(6);
  lcd.setCursor(0, 2);
  lcd.printByte(6);
  lcd.print("  i ");
  lcd.printByte(3);
  lcd.print(" arduinos!   ");
  lcd.printByte(6);
  lcd.setCursor(0, 3);
  for(int i = 0;i < 20; i++)  lcd.printByte(6);
//  lcd.clear();

delay(1000);
  lcd.setCursor(2, 1);
  lcd.print("                ");
  lcd.setCursor(2, 2);
  lcd.print("                ");

}

void loop()
{
delay(1000);

  Serial.println(second());
 
  lcd.setCursor ( 9, 1 );
  lcd.print(second());
}
4  Using Arduino / Displays / Re: Uno R3 + 20x4 I2C LCD - screen freezes / garbage on: November 29, 2012, 02:53:20 pm
Thanks for taking a look at this.

I had done a fair amount of the code before I got this LCD screen. I do have a 16x2 non-I2C screen lying around, so I could possible try that. What I will do is strip out a bunch of code and see if I still have the same problem with a smaller project.

I'm calling the freeRam() function at the entry to each function. It looks like this:-

Code:
int freeRam () {
  extern int __heap_start, *__brkval;
  int v;
  return (int) &v - (__brkval == 0 ? (int) &__heap_start : (int) __brkval);
}

and comes from here: http://arduino.cc/playground/Code/AvailableMemory.

I'll post again when I've had a chance to try this with a smaller project.

Cheers,

Jon

5  Using Arduino / Displays / Uno R3 + 20x4 I2C LCD - screen freezes / garbage on: November 29, 2012, 06:42:53 am
Hello folks,

I'm tearing my hair out trying to get my project to work. I have an Arduino Uno R3 clone (Freetronics 100% compatible) with a 20x4 I2C LCD from DX (part number GY-LCD-V1). I also have four pushbuttons connected via the analog pins (in digital mode.) Other than that I have nothing connected to the arduino other than power via USB to my Mac.

My problem is that the screen freezes or starts showing garbage after a couple of minutes of the sketch running. Sometimes it seems that the screen gets half way through redrawing then just stops (in which case nothing updates the screen until I disconnect/reconnect the power) or starts drawing garbage to the screen, which also takes a cold boot to fix. Either way, the sketch continues running, i.e. the buttons produce output via the serial monitor and the heartbeat LED on pin 13 continues flashing (the main loop flashes it every second). Occasionally the sketch crashes, i.e. no response to button pushes and the LED stops flashing. If I reset the unit (either via the reset button or by closing/reopening the serial monitor) the screen sometimes won't re-initialise, i.e. the last drawn screen remains and won't redraw until the power is cycled.

Initially I thought this might be a memory problem. The sketch is big (about 28KB compiled without debug/info defines) and very nearly 32Kb with them compiled in. Free RAM is about 800bytes according to the debug statements. I've been mounting the hardware (LCD + buttons so far) in an enclosure, and I had a few days of the sketch running flawlessly, but now it's back to the normal problems.

I'd greatly appreciate any pointers on how to troubleshoot this.

I've attached the sketch - it's in a few files. It's too big to to put into this post in code tags.

Cheers,

Jon
6  Using Arduino / Programming Questions / Re: Time Maths [SOLVED] on: November 25, 2012, 09:48:21 pm
Thanks for the pointers folks.

time_t is indeed already in seconds When I first tried this, I got some unexpected results manipulating the time_t directly (e.g. adding 3600 seconds to it to increment the hour) so I thought there must be a reason why I couldn't do that. I've tried this again now and it's working as expected. Fortunately that means I don't need to check for overflows now.

My button read function does only register a button press once.

Edit: For the sake of completeness, here's the working function...

Code:
time_t ModifyScreenElementTime(time_t InputTime)

  if (ReadButton(LEFT) == BUTTON_PRESS) InputTime += 60;         // Increment Input time by 1 minute
  if (ReadButton(RIGHT) == BUTTON_PRESS) InputTime -= 60;        // Decrement Input time by 1 minute
  if (ReadButton(LEFT) == BUTTON_PRESS_HOLD) InputTime += 3600;  // Increment Input time by 1 hour
  if (ReadButton(RIGHT) == BUTTON_PRESS_HOLD) InputTime -= 3600; // Decrement Input time by 1 hour
 
  if (InputTime < now()) InputTime = now(); //Timer can't start before now
  return InputTime;
}

Cheers,

Jon
7  Using Arduino / Programming Questions / Re: Time Maths on: November 21, 2012, 06:10:07 pm
Thanks. I'll put in checks to fix that. Does that have any other consequences other than I get a value of 255 when I decrement from 0?
8  Using Arduino / Programming Questions / Time Maths on: November 21, 2012, 05:57:24 pm
Hi,

I'm trying to set a timer - the time is displayed on an LCD screen, and I use push buttons to adjust the hours and minutes. Here's the function that's called by the screen display function:-

Code:
time_t ModifyScreenElementTime(time_t InputTime) {
  tmElements_t tmSet;
  breakTime(InputTime, tmSet);
  
//  byte YYYY = tmSet.Year;
//  byte MM = tmSet.Month;
  byte DD = tmSet.Day;
  byte hh = tmSet.Hour;
  byte mm = tmSet.Minute;
  //byte ss = tmSet.Second;
  
  if (ReadButton(LEFT) == BUTTON_PRESS) {
    mm++;
//    DebugMessage_P(PSTR("Screen element incremented by 1 min"));
  }
  if (ReadButton(RIGHT) == BUTTON_PRESS) {
    mm--;
//    DebugMessage_P(PSTR("Screen element decremented by 1 min"));
  }
  if (ReadButton(LEFT) == BUTTON_PRESS_HOLD) {
    hh++;
//    DebugMessage_P(PSTR("Screen element incremented by 1 hour"));
  }
  if (ReadButton(RIGHT) == BUTTON_PRESS_HOLD) {
    hh--;
//    DebugMessage_P(PSTR("Screen element decremented by 1 hour"));
  }
  
  if (mm > 59) {
    mm = 0;
    hh++;
  }
   if (hh > 23) {
    hh = 0;
    DD++;
  }
  //  byte YYYY = tmSet.Year;
//  byte MM = tmSet.Month;
  tmSet.Day = DD;
  tmSet.Hour = hh;
  tmSet.Minute = mm;
  tmSet.Second = 0;
  
  return makeTime(tmSet);
}

My trouble is with rollover from minutes to hours to days etc.. What I'd really like to do is convert from time_t to Unix time (i.e. seconds since 1/1/1970) so that I can manipulate the seconds value and then convert it back. I know of a function to convert to seconds (I think that's in the Time library) but I can't fine one to convert back i.e. form seconds to time_t.

I'd appreciate any help. I'm new with Arduino and programming in general, so if I've got the whole approach glaringly wrong, please advise how I should approach it.

Cheers,

Jon
Pages: [1]