Poll
Question: Would like the 160x128 GLCD f/sparkfun ported to GLCD v.3?
Would liKe it to be included. - 33 (84.6%)
Don't care. - 5 (12.8%)
Wouldn't like it to be included. - 1 (2.6%)
Total Voters: 16

Pages: 1 2 3 [4] 5 6 ... 8   Go Down
Author Topic: Beta version of GLCD library version 3  (Read 22034 times)
0 Members and 1 Guest are viewing this topic.
0
Offline Offline
Sr. Member
****
Karma: 0
Posts: 417
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I'm thought of math based on the reading:
Code:
#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?
« Last Edit: August 03, 2010, 12:54:21 am by frostin » Logged

London
Offline Offline
Tesla Member
***
Karma: 10
Posts: 6255
Have fun!
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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:
  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  
« Last Edit: August 03, 2010, 01:53:19 am by mem » Logged

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

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


The next two if statements have a very common error.

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


Code:

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

OR

Code:

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


--- bill
« Last Edit: August 03, 2010, 02:36:02 am by bperrybap » Logged

London
Offline Offline
Tesla Member
***
Karma: 10
Posts: 6255
Have fun!
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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  smiley-wink
« Last Edit: August 03, 2010, 02:58:04 am by mem » Logged

0
Offline Offline
Sr. Member
****
Karma: 0
Posts: 417
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

NL
Offline Offline
Newbie
*
Karma: 0
Posts: 37
Arduino rocks
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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




Logged

London
Offline Offline
Tesla Member
***
Karma: 10
Posts: 6255
Have fun!
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Mario, good to hear you have it going, thanks for the feedback.
Is it really 132 pixels wide?
« Last Edit: August 04, 2010, 04:06:40 pm by mem » Logged

NL
Offline Offline
Newbie
*
Karma: 0
Posts: 37
Arduino rocks
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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

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

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
Logged

NL
Offline Offline
Newbie
*
Karma: 0
Posts: 37
Arduino rocks
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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


Logged

Devon, UK
Offline Offline
Full Member
***
Karma: 4
Posts: 234
Arduino rocks my socks, yes the socks are rocking!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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

London
Offline Offline
Tesla Member
***
Karma: 10
Posts: 6255
Have fun!
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

graymalkin, do you have me confused with someone else smiley-wink

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.
« Last Edit: August 04, 2010, 10:23:25 pm by mem » Logged

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

graymalkin,

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
« Last Edit: August 05, 2010, 01:05:14 am by bperrybap » Logged

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

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

@mario,
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:

http://www.instructables.com/id/Bare-Bones-Breadboard-Arduino-Labels/

http://www.shadetreeee.com/2009/10/12/a-microcontroller-cheat-sheet-arduino-stickers/


--- bill
Logged

NL
Offline Offline
Newbie
*
Karma: 0
Posts: 37
Arduino rocks
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

[offtopic]
@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 smiley-sad 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.

Mario
Logged

Pages: 1 2 3 [4] 5 6 ... 8   Go Up
Jump to: