Go Down

Topic: Beta version of GLCD library version 3 (Read 25147 times) previous topic - next topic


Aug 03, 2010, 07:52 am Last Edit: Aug 03, 2010, 07:54 am by frostin Reason: 1
I'm thought of math based on the reading:
Code: [Select]

#include <glcd.h>
#include "fonts/Arial14.h"         // proportional font
#include "fonts/SystemFont5x7.h"   // system font
#include <Wire.h> // initialize wire
#include "nunchuck_funcs.h"

int loop_cnt=0;

byte accx;

void setup()
 Serial.print("Wii nunchuck ready");
 GLCD.DrawHLine(0, 32, 127);


void loop()
  if( loop_cnt > 100 ) {
       loop_cnt = 0;


       accx  = nunchuck_accelx();



   if ((byte)accx < 100 > 130) // <== Heres the problem
  GLCD.DrawLine(0, 32, 64, 0); // --
  if ((byte)accx > 99 < 73); //   ---
  GLCD.DrawLine(0, 63, 127, 0); //  ----
  if ((byte)accx < 130 > 186);
  GLCD.DrawLine(127, 63, 0, 0); // ----


It draws a horizontal line in the setup which is the center of the horizon.
But from I can tell is its not reading or updating the data from accx to the glcd (Draws an X).
Definately I know the code is wrong there. Any thoughts?


Aug 03, 2010, 08:52 am Last Edit: Aug 03, 2010, 08:53 am by mem Reason: 1
I am not sure what you want to draw for your range of values but you can use this code as the basis for handling the values

Code: [Select]
  if ( accx  > 186)    
     ; // do nothing  for values greater than 186
     GLCD.DrawLine(0, 63, 127, 0);
  else if ( accx  > 130)
     GLCD.DrawLine(127, 63, 0, 0);  // draw this line for values between 130 and 186    
  else if ( accx  > 100)
     GLCD.DrawLine(0, 63, 127, 0);    // draw this line of values between 100 and 130        
  else if ( accx  > 73)
    GLCD.DrawLine(0, 32, 64, 0);   // draw this line of values between 73 and 100
      ; // do nothing for values less than 73  


Aug 03, 2010, 09:31 am Last Edit: Aug 03, 2010, 09:36 am by bperrybap Reason: 1
A bit of additional information if you have interest why what you had was not working.

The C syntax you have used, while valid, I'm pretty sure is not what you are intending.
Lets look at several of the lines 1 by 1.
Code: [Select]

if ((byte)accx < 100 > 130) // <== Heres the problem
GLCD.DrawLine(0, 32, 64, 0); // --

The compiler will toss this code completely away.
The reason is that the expression inside the if statement will always evaluate to 0/false.
It will first look  accx < 100 part of the expression.
That will evaluate to 0 or 1 depending on the value of accx if it is less than 100.
But it doesn't matter because both 0 and 1 are never greater than 130
so the overall expression evaluates to 0/false. Because of this
the compiler will toss the code.

I'm not exactly sure what you  wanted.
Were you wanting to check for either less than 100 or greater than 130?
(less than 100 *and* greater than 130 doesn't make sense)
If so then to do that in C code you would use:
Code: [Select]

if((accx < 100) || (accx > 130))
 GLCD.DrawLine(0, 32, 64, 0);

Or if accx were greater than 100  and less than 130?
If so you would use:
Code: [Select]

if((accx > 100) && (accx < 130))
 GLCD.DrawLine(0, 32, 64, 0);

The next two if statements have a very common error.

Code: [Select]

if ((byte)accx > 99 < 73); //   ---
  GLCD.DrawLine(0, 63, 127, 0); //  ----

Note the semicolon on the if? That should not be there.
The result of that is that the if statement is thrown away because the statement following  the if is a null statement (the semicolon) and so the statement below the if is outside the if and so it is always executed.

But again, the if syntax needs fixing as well similar to the first if statement.

Those fixes will fix the drawing, or you can use Michael's nested if statement to support different ranges for drawing lines,  but in the larger picture, you may eventually need some additional logic to erase what you have drawn. Otherwise as you move the nunchuk around, all the lines will eventually be drawn.

You can either do this by clearing the entire display each pass through the
loop or you can draw the proper line in black or white (which will erase it) depending if you want the line or not.

for example:

Code: [Select]

if((accx > 100) && (accx < 130))
 GLCD.DrawLine(0, 32, 64, 0, BLACK);
 GLCD.DrawLine(0, 32, 64, 0, WHITE);

But it gets complicated when you have more than one line to ensure that the multiple line erases don't erase pixels in the the new line you want or pixels in your horizontal line.

The easiest thing for now, is to erase the display when you do an update inside your loop() function, then redraw your horizontal line, and then use Michael's nested if example to draw the line you want based on your nunchuk position.

But in using Michael's nested if example, I would HIGHLY recommend
the use of curly braces . I always use curly braces on anything more than a single line simple if statement. It helps preventing unintended accidental logic or syntax errors.
Which BTW, there is an error in the example:
The first part of the if is incorrect. It should be:

Code: [Select]

 if ( accx  > 186)
     ; //  do nothing for values greater than 186
  else if ( accx  > 130)


Code: [Select]

 if ( accx  > 186)
      //  for values greater than 186
     GLCD.DrawLine(0, 63, 127, 0);
  else if ( accx  > 130)

--- bill


Aug 03, 2010, 09:57 am Last Edit: Aug 03, 2010, 09:58 am by mem Reason: 1

In transposing the order of the checks I neglected to delete the first:
 GLCD.DrawLine(0, 63, 127, 0);

This discussion may want to be moved to a new thread  ;)


Moved to http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1280871485



You may add the AV-Display HY-12864K series displays (132x64) to the compatibility list.
Tested with WinXP-pro, IDE 17, ATmega 328 on a breadboard.

I've also tested freeing up pin A4 (moved it to D2) so I2C pins become available.
I now have two displays (a GLCD and a regular LCD) running side by side using the Beta glcd library and my LiquidCrystal_I2C library.
Now I can use the full GLCD resolution for graphics while text is displayed on the 2nd display. :)


Aug 04, 2010, 11:06 pm Last Edit: Aug 04, 2010, 11:06 pm by mem Reason: 1
Mario, good to hear you have it going, thanks for the feedback.
Is it really 132 pixels wide?


Oops, what was I thinking?. You're right, it's 128x64


I assume you meant Arduino Analog pin 4, or Arduino pin 18, or AVR pin C4 as there is no port A on the m328.
BTW, since you are using a breadboard and not an Arduino board with labeled pin numbers, you might find the new pin configuration designation capability useful.
You can now specify pins using a PIN_Pb notation in the GLCD library config files as well as using Arduino pin #s. So if you want to specify AVR pin C4 (PORTC bit 4) you can use PIN_C4 rather than 18 or PIN_D2 rather than 2.

It may be my own ludditeness, but I find the Arduino pin numbering scheme a PITA when trying to specify AVR pins or connect
wires to AVRs that are not on labeled Arduino boards or boards like the Teensy that use AVR port&pin designations in their labels.
I'm not a fan of having to use a decoder ring to configure my code
and then again to hook my wires.

--- bill



Confusion yep, I know what you mean.
In my earlier post I meant IC pin 27 / AVR Port C4 / Arduino analog pin 4
I moved it to IC pin 4 / AVR Port D2 / Arduino Digital pin 2
(I also commented out the glcdCSEL4 statements in the config file)

Funny you mention a decoder. Yesterday I made my own decoder sheet listing al the various names, numbers and descriptions used with these AVR's. I wanted to put it online but my provider seems to be doing maintenance and has disabled ftp access to my website.
(I'll upload it later if you want).

As for using port numbers: I'm not used to thinking in AVR-ports so I prefer the old-fashioned way :)
On the other hand I think I have no choice but to start using them as I really would like to get another GLCD I have working with this great library. As posted earlier this one uses the T6963C controller that is not supported. I found some other libraries for this controller but the code is port based. I also found a Hitachi code sample in an application note but again totally port based.

I you have any advice on how to approach porting this library for use with another controller feel free to lecture me ;)


I love you, mem. You're just so lovable.  But seriously, this looks cool, i'll play with a 192x64 GLCD tomorrow.  Just an idea, but could you put all the port defines in one file, eg ports.h, so it is easy to change them in order to free up analog/i2c Pins, or just rearrange them to make it easier to make a protoboard sheild with for example?


Aug 05, 2010, 05:22 am Last Edit: Aug 05, 2010, 05:23 am by mem Reason: 1
graymalkin, do you have me confused with someone else ;)

The port definitions vary by AVR chip type because various chips have different pins free. For example  the Sanguino uses pins 12 and 13 for serial instead of pins 0 and 1.

Having board specific pin definitions allows an efficient selection of pins to be automatically included using the board type selected in the IDE.

I would think that having one big file with lots of #defines for all the chips would make it more more difficult for people to change the configuration

If you have any suggestions for improvements to the documentation to make configuration changes easier I will be happy to amend it.


Aug 05, 2010, 05:22 am Last Edit: Aug 05, 2010, 08:05 am by bperrybap Reason: 1

The new glcd library is different from the revision 2 ks0108 library in that
any Arduino pin can be used for anything without restriction or consideration for AVR ports or bit number within the AVR port.
If you want to free up a particular pin, simply pick a different
Arduino pin for that glcd function.

Could you explain a bit more what you are wanting?

--- bill


Funny you mention a decoder. Yesterday I made my own decoder sheet listing al the various names, numbers and descriptions used with these AVR's.

One of things that I've seen done before is to create a tiny label
that you stick directly on the back of the m328 that has the pin numbers.
This quite very useful for breadboards when you are using the arduino pin #s. No more having to look up pins in a decoder table and then have to count pins on the physical chip. Here's a few links:



--- bill


Yep I've seen those, but except the Arduino names I also always forget the PWM pin numbers, I2C ports (is SDA pin 27 or 28?) and the INT pins. Since I'm just moving toward using port numbers I think I'll stick to my decoder sheet. http://www.xs4all.nl/~hmario/arduino/various/ATmega_ports.jpg
But thanks for the tip/links anyway. [/offtopic]

Today I got my 240x64 GLCD with T6963c controller connected to another breadboard setup and used the T6963 library for first tests.
The test showed 7 defective rows :( Too bad, this would have been a great display for a future project.

Next I'm going to study the glcd library and hopefully find a way get this T6963 display working with the glcd lib.
So far I think at least the functions readData, writeData, writeCommand, WaitForStatu, goTo, init
need to be adapted for this controller.


Go Up

Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

via Egeo 16
Torino, 10131