Beta version of GLCD library version 3

Thanks mem. It seems atmega644pa with sanguino bootloader will give me a beefed up version of atmega328. I'll fiddle with this idea once I get a sanguino kit.

Just my 2 cents, but at this point in time, I don't see the value of the Sanguino now that the Teensy++ is available and PJRC has a teensy plugin for the arduino IDE.

Teensyduino s/w includes re-written digital i/o routines
(digitalWrite(), PinMode(), etc...) that are MUCH
faster than the standard libraries provided by Arduino.

Teensy++ board hardware has
Double the flash, Double the RAM, double the EEPROM, same analog inputs, more PWM pins, Hardware USB support builtin so you can emulate lots of USB devices with simple s/w (PJRC provides lots of sample code), does not need a USB to serial cable (like an FTDI cable) as USB support is built into the AT90USB1286.

It is also quite a bit cheaper than a Sanguino and comes fully assembled and tested.

The Sanguino is usually a kit which can be a plus for some people as it is kind of fun to solder up a board and you can also replace the processor as they are through hole vs SMT.

I really like the hardware USB support especially for virtual serial communication as not only can the virtual serial interface run much faster but also has built in flow control management because it sits on top of USB.

Just my crazy views & opinions....

--- bill

don't see the value of the Sanguino?

Actually, the Sanguino kit is the same price as the Teensy++ and would be a better choice for applications that need two hardware TTL serial ports (without USB). It's a particularly good choice for hardware hackers - I have a project using the Sanguino circuit (an ATmega644P and a crystal) that was put together for $10 in parts.

That said, the Teensy++ is a good choice for the typical Arduino usage that uses USB connection to a computer.

FYI, it is working perfect into my system:

Arduino Duemilanove
Arduino IDE 17
Windows XP

GLCD model: AGM1264B

Thanks for this new library with a lot of tools... it promises a lot of fun!

Just only one question, is there a way to use shift registers (eg., 74HC595) with GLCD in order to reduce the number of pins used? Thanks!

Cheers,

The library needs to both write and read to the LCD and implementing a read/write shift register a little tricky. For a similar component cost you could probably use a second ATmega168 to run the library code that communicates with a master Arduino via something like I2C. Someone else asked about that capability and if it's a popular request then we can put I2C on the wish list for a future release.

Thanks, it could be great.

But in any case, right now, the library is great and a fantastic work.

Well done and thanks so much!

#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.begin(19200);
  nunchuck_setpowerpins();
  nunchuck_init();
  GLCD.Init(NON_INVERTED);
  GLCD.SelectFont(System5x7);
  Serial.print("Wii nunchuck ready");
GLCD.DrawHLine(0, 32, 127); // horizontal line
}

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

        nunchuck_get_data();

        accx  = nunchuck_accelx(); 

       Serial.println((byte)accx,DEC);
    
    
        GLCD.CursorTo(5,5);
        GLCD.println((byte)accx,DEC);
       
    }
    loop_cnt++;
    delay(1);
}

Ive been playing around with code for a few hours and got the nunchuck value to print from 73 to 184 or 185 the same in the serial.
At around 130 the value of accx is level.
My question is which im completely stumbled on is read a value from accx and depending on which state it is in draw a line (like a tilt plain) from level to be at 0, 32. if tilted to the right itd draw a line from 0,0 to 127,63. if tilted from left itd draw a line from 127,0 to 0,63.

OK, Thanks for answers to my Sanguino question. Is there any place where you can cheaply buy (<US$10) an ATMEGA644 with Sanguino bootloader. I will only need the chip. It seems that this chip needs same support as ATMEGA328P to run duino environment (5V DC, 16MHz crystal, caps etc.) I will need to get serial cable/FTDI chip board for other stuff anyway.

@chris, there is an example for drawing angled lines in the FPS example sketch. If you want to draw lines at a specified angle there is an example in the clockface sketch supplied in the download, although that code is highly optimized (it uses a sin table instead of floating point) and is a little obscure.

If RAM or performance are not a concern then you can use trionometry to calculate the coordinates. If you need it, you can find a trig primer here: http://processing.org/learning/trig/

@liudr, Digikey sell the bare chip for $7: http://parts.digikey.co.uk/1/1/822588-ic-mcu-avr-64k-flash-40-dip-atmega644p-20pu.html

Wulfden sell the chip with bootloader, socket, crystal, caps and reset switch for $11
http://www.wulfden.org/TheShoppe/freeduino/rbfk.shtml

But if you need USB then the teensy may be the better choice.

@mem
thank you :slight_smile:

I'm thought of math based on the reading:

#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.begin(19200);
  nunchuck_setpowerpins();
  nunchuck_init();
  GLCD.Init(NON_INVERTED);
  GLCD.SelectFont(System5x7);
  Serial.print("Wii nunchuck ready");
  GLCD.DrawHLine(0, 32, 127);

}

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

        nunchuck_get_data();

        accx  = nunchuck_accelx(); 

       Serial.println((byte)accx,DEC);

    

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

       
    }
    loop_cnt++;
    delay(1);
}

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?

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

   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
   else
       ; // do nothing for values less than 73

@chris,
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.

 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:

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:

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

The next two if statements have a very common error.

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:

if((accx > 100) && (accx < 130)) 
  GLCD.DrawLine(0, 32, 64, 0, BLACK);
else
  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:

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

OR

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

--- bill

Indeed

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 :wink:

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

Gents,

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

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

Mario,
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