Pages: [1]   Go Down
Author Topic: Problems with GLCD and Arduino Mega (1280)  (Read 1595 times)
0 Members and 1 Guest are viewing this topic.
0
Offline Offline
Jr. Member
**
Karma: 0
Posts: 63
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hey guys! Merry Christmas!

I'm working with one of these:
http://www.sparkfun.com/products/710

on an arduino mega, I used the output set A on these instructions:
http://www.arduino.cc/playground/Code/GLCDks0108

and I wired it according to this diagram:
http://www.arduino.cc/playground/uploads/Code/KS0108_wiring.jpg

I uploaded the sketch to my mega and all I get on the screen is a bunch of random horizontal lines, so what I did was put in serial.println commands to see at what point the code was failing, I found that it was stopping at :
Code:
 GLCD.DrawBitmap(ArduinoIcon, 32,0, BLACK); //draw the bitmap at the given x,y position
  delay(3000);

Also I notice that I cannot upload the sketch if the reset button is wired into what is labeled as the correct port (line 14 > the reset button next to the 5v+)

Any ideas from anyone? Also I've tried both the GLCD v3 RC2 and RC3 and I included #define __AVR_ATmega1280__ in the headers for the sketch.

EDIT: also here is my sketch code with the diagnostics, I tried commenting out the DrawBitmap command and it error'ed out at the next Draw command in the while() loop so I'm figuring it must be something to do with my wiring, also I will upload a vid of my LCD freaking out momentarily.

Code:
  #include <ks0108.h>  // library header
  #include <Arial14.h>  // font definition for 14 point Arial font.
  #include "SystemFont5x7.h"   // system font
  #include "ArduinoIcon.h"     // bitmap 
  #define __AVR_ATmega1280__

  unsigned long startMillis;
  unsigned int iter = 0;

void setup(){
  Serial.begin(9600);
  Serial.println("start checkpoint NEW");
  GLCD.Init(NON_INVERTED);   // initialise the library
  Serial.println("start checkpoint 1");
  GLCD.ClearScreen(); 
  Serial.println("start checkpoint 2");
  GLCD.DrawBitmap(ArduinoIcon, 32,0, BLACK); //draw the bitmap at the given x,y position
  delay(3000);
  Serial.println("start checkpoint 3");
  GLCD.ClearScreen();
  GLCD.SelectFont(System5x7);       // select fixed width system font
  Serial.println("start checkpoint");
}

void loop(){ // run over and over again
  Serial.println("checkpoint 1");
  startMillis = millis();
  Serial.println("checkpoint 2");
  while( millis() - startMillis < 1000){ // loop for one second
    Serial.println(startMillis);
    GLCD.DrawRect(0, 0, 64, 61, BLACK); // rectangle in left side of screen
    GLCD.DrawRoundRect(68, 0, 58, 61, 5, BLACK);  // rounded rectangle around text area   
    for(int i=0; i < 62; i += 4)
      GLCD.DrawLine(1,1,63,i, BLACK);  // draw lines from upper left down right side of rectangle 
    GLCD.DrawCircle(32,31,30,BLACK);   // draw circle centered in the left side of screen 
    GLCD.FillRect(92,40,16,16, WHITE); // clear previous spinner position 
    GLCD.CursorTo(5,5);               // locate curser for printing text
    GLCD.PrintNumber(++iter);         // print current iteration at the current cursor position
  }
  Serial.println("checkpoint 3");
  // display number of iterations in one second
  GLCD.ClearScreen();               // clear the screen 
  GLCD.CursorTo(13,2);              // positon cursor 
  GLCD.Puts("FPS= ");               // print a text string 
  GLCD.PrintNumber(iter);           // print a number
 }
« Last Edit: December 25, 2011, 02:40:22 pm by dashdanw » Logged

Dallas, TX USA
Offline Offline
Faraday Member
**
Karma: 70
Posts: 2766
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I've run your exact sketch on a Teensy board (I don't have a 1280 based board)
and it works fine on Arduino 0022 and 1.0 using glcd v3 RC3.
(after I modified the includes for v3)

BTW, you should not turn on the __AVR_ATmega1280__ define
The compiler will set the various CPU type flags based on the command line options
will normally be set by the IDE or by the Makefile if you are not using the IDE.

The best thing to do is use glcd v3 RC3.
v3 is much faster than v2 and has many more features, including
a diagnostic sketch in the examples.

When switching to glcd from ks0108 make sure to remove the ks0108 directory
or move it somewhere else as it may confuse the IDE.

Then run the glcd v3  GLCDdiags sketch that is included in the examples with the library
and look at the serial output for any errors.
If you get any errors post the serial output here and I can help walk you through
getting the display up and running.

--- bill

Logged

Dallas, TX USA
Offline Offline
Faraday Member
**
Karma: 70
Posts: 2766
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

With respect to the reset signal on the glcd (pin 14 on your glcd), you can either tie it to vcc
(which may or may not work depending on the glcd - I'm not sure about your glcd as I don't have one)
or use a software pin to control the glcd reset line (better).
To use a software pin, you must edit glcd/config/ks0108_Mega.h
Uncomment the line that looks like this:
Code:
//#define glcdRES         30    // Reset Bit
by removing the leading to slashes
Then hook up pin 30 on the mega board to the reset pin on the glcd module (pin 14)




There is one other thing that you may want to keep in mind when using debugging print statements.
With 1.0 the serial output is buffered, so the print()/println() returns immediately and does
not wait for the output to be sent if there is room in the tx buffer (currently 64 bytes).

So you can no longer assume that the events are occurring in the order you see the
printed messages. For example, in you example code, the code could be calling GLCD.ClearScreen()
*before* the message "start checkpoint NEW" is fully sent out the serial port.

To get the pre 1.0 synchronous tx behavior on Arduino 1.0, you must call
Serial.flush() to flush out the transmitted characters after each print() call to
wait for them to be transmitted.
However, on pre 1.0 Serial.flush() purges the input buffer.
It is one of those very annoying non backward compatible changes in 1.0



--- bill
« Last Edit: December 25, 2011, 09:52:26 pm by bperrybap » Logged

0
Offline Offline
Jr. Member
**
Karma: 0
Posts: 63
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I'm also assuming that pin4...7 on the duelmilanove is the same as on the mega, is that correct? also it seems from the schematic that the enable lines are swiched? is that right? Because when I look at the ks0108_Mega file, I see the pinouts are labeled completely different.
Logged

0
Offline Offline
Jr. Member
**
Karma: 0
Posts: 63
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

also after removing the ks0801 library from the library folder, and replacing my glcd rc2 with rc3, it is not able to find the ks0108.h file included in the headers for the sketch, did the filename change with glcd?

EDIT:

I edited the header files to read:
  #include <glcd.h>  // library header
  #include <fonts/Arial14.h>  // font definition for 14 point Arial font.
  #include "fonts/SystemFont5x7.h"   // system font
  #include "bitmaps/ArduinoIcon.h"     // bitmap 

i assumed that ks0108.h changed to glcd.h and had to include the filepaths inside of libary/glcd/ to get them to work, i'll try it with the wiring implied by the glcd mega header
« Last Edit: December 26, 2011, 07:44:32 am by dashdanw » Logged

0
Offline Offline
Jr. Member
**
Karma: 0
Posts: 63
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hmm, still issues, when I wire it corresponding to the pins labeled in ks0801_Mega.h (ie, #define CS1 32 would go from CS1 on the LCD pinout to pin 32 on the mega) I get no result
Logged

Dallas, TX USA
Offline Offline
Faraday Member
**
Karma: 70
Posts: 2766
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Time to take a step back and take a closer read of the glcd library documentation. smiley-wink
(The glcd-arduino google code download page points to the readme file in glcd/readme.txt
for further instructions and also points out the library documentation in glcd/doc/GLCDref.htm)

The Arduino pins used on Mega and on m328 Arduino when using the "as shipped" auto configuration files
are not the same.
This has always been true for the library whether v2 or v3.

If using a mega based Arduino board, you need to use the mega pins.
The idea was that on the mega, the glcd could use pins not available on the m328 arduino
so that it would not interfere with other arduino shields.

The GLCD Panel Pinouts table on the ks0108 playground site:
http://www.arduino.cc/playground/Code/GLCDks0108
and in the v3 included html documentation (glcd/doc/GLCDref.htm)
in section "GLCD Graphical LCD Library"->Wiring->KS01018 Family

outline the pin connections based on a "panel type".
If you are more comfortable reading a datasheet and looking
a source header file, then wire the pins according to the data
sheet and the mega pin config file:
glcd/config/ks0108_Mega.h


There is a wealth of information in the included HTML documentation.
It has sections on how to wire up panels, the diagnostic sketch and how to troubleshoot
issues, all the API functions,  and even sections on how to migrate sketches
from the ks0108 v2 library to the newer v3 library.


But most importantly, once you have the panel wired up,
run the supplied v3 GLCDdiags sketch.
It is a known working sketch that will print out the pin configuration
and verify that that glcd is hooked up correctly and working properly.

The information from this sketch and the visuals you see on the panel
when running the sketch are the best way diagnose any wiring issues.

--- bill






Logged

Pages: [1]   Go Up
Jump to: