Errors Using the SerialGLCD 128X64

First of all I want to say that I am a beginner in Arduino or C language, I bought a Serial GLCD 128X64 from Sparkfun about 2 months ago. I connected it to the Arduino Duemilanove (Atmega 328) and used a example http://www.sparkfun.com/products/9351 in the "Graphic LCD Library". This example works without problems. Below is a few lines of code:

void setup() {
  Serial.begin(115200); //default baudrate of the display, can be changed, consult summoningdark's README that comes with the firmware to change it
  delay(2000);
  
}

serialGLCD lcd; // initialisation

void loop() {
  
  lcd.clearLCD();
  // Allow for a short delay after clearLCD since it takes some time for the backpack to clear the entire screen
  delay(10);
  // Draw the sprite (int x, int y, int mode, int height, int width, byte data)
  // x and y defines the upper left corner to draw from, mode (same modes as text), height and width of the bitmap in pixels. sprite is the array of bytes.
  lcd.drawData(0,0,4,128,64,sprite6);
  delay(2000);  
  lcd.clearLCD();

I tried to adapt it to a program I have written but I got a lot of errors. I have the following code:

void gps_position_print()
  {
   if (GPS_screen==0)
      {
      lcd.clearLCD();
      }
      else
      {
  GPS_screen=1;      
  lcd.gotoPosition(4,0);
  Serial.print("  GPS DATA  ");

And I got the following errors :

" In function 'void gps_position_prin()': " error 'lcd' was not declared in this scope"

In the example code we have the function " lcd.clearLCD(); and it doesn't give error.

Can you please help in and give me some clues to solve the problem.

Thanks Manuel

Hellow all,

I decided to put the entire sketch I wrote, the example I used to test the SerialGLCD s in the Arduino examples menu. The sketch is in 2 post .

The code I wrote is the following ( the display positions may be wrong, but I think this isn’t the problem):

Also you may find a not very well organized code, but, as I said in the first post I am a beginner in the Arduino and C, so, please apologise if you find it weird.
The error the compiler displays is:" In function ‘void gps_position_print()’:
error: ‘lcd’ was not declered in this scope

#include <serialGLCD.h> // Include the library

byte sprite6[] = {
(Due to the sprite be so lon it was cut.)
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
};


char data=0;
int data_count=2;
uint8_t received_byte;
static uint8_t GPS_data[46]={0xB5,0x62,0x01,0x05};
uint8_t frame_count;
uint8_t sync_frame=0;
uint8_t frame_data;


unsigned long barometric_pressure=0;
unsigned long temp_pressure;
unsigned long pressure;
float altitude_barometric=0;
double pressure_zero=101235;
float ref_voltage=25.98;
int ad_voltage=0;
float ref_ad=1024;
float bat_voltage=0;
float temp=0;
float I_samples=4.00;
long int latitude;
long int longitude;
long int al_titude;
long int g_speed;
long int x;
long int y;
long int z;
long int x_int;
long int y_int;
long int z_int;
long int r;
char lat='N';
char lgt='W';
uint8_t gps_display=10;
uint8_t motor_display=11;
uint16_t  RPM_value=0;
uint16_t current_ad=0;
uint16_t ref_current=510;
uint16_t delta_I=0;
uint16_t temperature_ad=0;
float temperature=0;
float I_ad=0;
float adc_bit=0.0049266;
float mAH=0;
float a_volt=0.0690; // milivolts/ampere
float I_instantaneo=0;
float avg_sample=0;
float volt_element=3.5;
int val=0;
int analogPin=3;
uint8_t motor_screen=0;
uint8_t flight_screen=0;
uint8_t GPS_screen=0;
volatile uint16_t count=0;
volatile uint16_t time=0;
#define buzzerpin 9
uint8_t bat_test=1;
uint8_t j=0;
uint8_t element_count=0;
int read_pot_pin = A0;    // select the input pin for the potentiometer
int pot_value = 0;  // variable to store the value coming from the sensor
float I_max=0;
uint16_t rpm_max=0;
float bat_temp_max=0;
float altit_baro_max=0;
uint16_t veloc_max=0;
uint16_t altit_max=0;






void setup()
{
  Serial.begin(115200); //default baudrate of the display, can be changed, consult summoningdark's README that comes with the firmware to change it
  delay(2000);

//  counter++;

pinMode (buzzerpin, OUTPUT);// define buzzer output PIN 9
pinMode(13, OUTPUT);        // define led output pin 13, local LED
time=3500;                  // load the timer1 with  
count=20;                   // load the number of cycles.
// initialize timer1 
  noInterrupts();           // disable all interrupts
  TCCR1A = 0;
  TCCR1B = 0;
  TCNT1  = 0;
  //TCCR1A = (1<<COM1A0);
  OCR1A = time;            // compare match register 16MHz/256/2Hz
  TCCR1B |= (1 << WGM12);   // CTC mode
 // TCCR1B |= (1 << CS12)|(1<<CS10);    // 1024 prescaler 
  TIMSK1 |= (1 << OCIE1A);  // enable timer compare interrupt
  interrupts();             // enable all interrupts
  digitalWrite(buzzerpin, LOW); //switch OFF speaker

serialGLCD lcd; // initialisation
delay(10);
lcd.clearLCD();
  // Allow for a short delay after clearLCD since it takes some time for the backpack to clear the entire screen
delay(10);
lcd.drawData(0,0,4,128,64,sprite6);
delay(2000);  
lcd.clearLCD();
lcd.backLight(20);
}


void loop()
{
delay(2000);

USART();

gps_position_calc();

motor_data();

// Verifies the battery voltage and calculates the number
// of elements.
if (bat_test==1)
   {
   calculate_num_elem();
   } 


flight_data();

pot_value =analogRead(read_pot_pin);

if ((pot_value>=0) && (pot_value <=255))
    {
    flight_screen=0;
    motor_screen=0;
    gps_position_print();
    }
    
 if ((pot_value>=256) && (pot_value <=512)) 
     {
    flight_screen=0;
    GPS_screen=0;
    motor_data_print();
    }
 if ((pot_value>=513) && (pot_value <=768))    
    {
    motor_screen=0;
    GPS_screen=0;
    flight_data_print(); 
    }
 if ((pot_value>=769) && (pot_value <=1023))    
    {
    motor_screen=0;
    GPS_screen=0;
    max_data_print(); 
    }



max_values();

//print_data();
 
 val=analogRead(analogPin);
 digitalWrite(13, LOW);
}


 void USART()
{
 uint8_t sig[] = { 0x7E, 0xFD};
 
        data_count=0;
	sync_frame=0;

 	while (data_count<=44)
	{
        frame_data=1;
	uint8_t read_sig = 0;
	while  (frame_data>0)
	{ 
//while (!(UCSR0A & (1<<RXC0))) {} 
//received_byte = UDR0;
	while(!Serial.available())
        ;// Do nothing until there is something to read  
        received_byte = Serial.read();
	
	if (read_sig < 2)
            read_sig = received_byte == sig[read_sig] ? read_sig + 1:received_byte == sig[0];
	      else
		{
		switch (read_sig)
		{
		case 2:
		{
		frame_data=received_byte;
		read_sig++;
		}
		break;

		case 3: if (sync_frame==1)
		{
		read_sig = 6;
		}
		else
		{
		read_sig++;
		}
		break;

		case 4:if ((received_byte == (0xB5)) && (sync_frame == 0))
		{
		read_sig=5;
		frame_data--;
		}
		else
		{
		read_sig=0;
		}
		break;
					
		case 5: if ((received_byte == (0x62)) && (sync_frame == 0))
		{
		read_sig=6;
		frame_data--;
		sync_frame=1;
		}
		else
		{
		read_sig=0;
		}
		break;
							
		case 6: if ((received_byte == (0x7D)) || (received_byte == (0x7E)))
		{
		read_sig=7;
		}
		else
		{
		GPS_data[data_count++]=received_byte;
		frame_data--;
		}
		break;

		case 7: if ((received_byte == (0x5E)) || (received_byte == (0x5D)))
		{
		received_byte ^= 0x20; 
		GPS_data[data_count++]=received_byte;
		frame_data--;
		read_sig=6;
		}
  
          default:
	        break;

		}    
	     }
	   }
	}
    }
          
// GPS Position Calculation 
//******************************************
 void gps_position_calc()
  {
  uint8_t i;
  latitude=0;
  longitude=0;
  al_titude=0;
  g_speed=0;
  x=0;
  y=0;
  z=0;
  r=0;


/* Latitude calculation
 Get 4 bytes for latitude shif it in a 32 bits signed.
 if the latitude is negative we must comvert it to positive
 (two's complmente) ans latitude is South if positive is North.
 */
 
 uint8_t index=2;
 
 latitude = get_four_bytes_from_vector(index);
   
  if (latitude<0)
      {
        latitude^=0xFFFFFFFF;
        latitude+=1;
        lat=('S');
      } 
      else
      {
      lat=('N');
      }
      y_int=latitude/1000000;
      y=latitude%1000000;
     
 /* longitude calculation 
 
 The longitude calculations is the same as the 
latitude.*/ 
   
 index=6;
 
 longitude = get_four_bytes_from_vector(index);
   if (longitude<0)
      {
        longitude^=0xFFFFFFFF;
        longitude+=1;
         lgt=('W');
      } 
      else
      {
       lgt=('E');
      }
   x_int=longitude/1000000;
   x=longitude%1000000;
// Altitude calculation 
 index=10;
 al_titude = get_four_bytes_from_vector(index);
  
  z_int=al_titude/100;
  z=al_titude%100;
 
  
 // Ground Speed
  index=14;
 
 g_speed = get_four_bytes_from_vector(index);
 g_speed=g_speed*3600/100000;
 } 
 
//Flit data calculations 
void flight_data()
{
 uint8_t i;
 barometric_pressure=0;
 
 for (i=30; i<=32; i++)
  {
   barometric_pressure |= GPS_data[i];
     if (i<32)
      {
      barometric_pressure <<=8;
      }
      else
      {
      break;
      }
  } 
  
/*Altitude Calculation*/
  temp=(double) barometric_pressure/pressure_zero;
  temp=1-pow(temp, 0.19029);
  altitude_barometric=(44330*temp); 
}
 
void motor_data()
{
//Battery voltage calculation
//****************************
  ad_voltage=0;
  bat_voltage=0;        
  uint8_t i=0;
  uint8_t index=33;
 
ad_voltage = get_two_bytes_from_vector(index);
bat_voltage=((ad_voltage*ref_voltage)/ref_ad);
 

//RPM calculation
//******************
 RPM_value=0;
 index=41;
 
 RPM_value = get_two_bytes_from_vector(index); 

  
//Battery discharge Calculation maH
//********************************** 
 current_ad=0;
 index=39;
 current_ad = get_two_bytes_from_vector(index);
 
 I_ad=current_ad; // valor recebido do ADC 4 amostragens.
 
 delta_I=(I_ad/I_samples);
I_instantaneo=((delta_I*adc_bit)/a_volt);
 
 mAH+=(I_instantaneo/3.6);
 
       

// Battery temperature calculation
//*********************************

temperature_ad=0;
temperature=0;
index=37;
temperature_ad = get_two_bytes_from_vector(index);
 
  temperature=temperature_ad;
  temperature = (temperature *adc_bit/ 0.01);
} 

/* 
void print_data()
{
  int i;
  for (i=0; i<=45; i++)
      {
        Serial.print(GPS_data[i]);
      }
}
*/
long int get_four_bytes_from_vector(uint8_t index)
        {
          uint8_t i;
          long int result;
          for(i=index; i<=(index+3); i++)
              {
               result|=GPS_data[i];
                 if (i<(index+3))
                  {
                  result <<=8;
                  }
                  else
                  {
                  break;
                  }
               }
             return result;
        }
                
int get_two_bytes_from_vector(uint8_t index)
          {
          uint8_t i;
          int result;
          for(i=index; i<=(index+1); i++)
              {
               result|=GPS_data[i];
                 if (i<(index+1))
                  {
                  result <<=8;
                  }
                  else
                  {
                  break;
                  }
               }
           return result;
        }
        
//***********************************************************
/* This routine verifies the battery voltage and checks if it is
* charged if not, sets an alarme with high cadency bip, if 
* battery voltage is within limites of a number of cell, it 
* bips the number of elements of battery.*/

void calculate_num_elem()
{
  digitalWrite(13, HIGH);
  bat_test=0; // clear the battery test
 if(bat_voltage < 7.40)
    {
      alarm_sequence();
      }
     if((bat_voltage > 7.40) && (bat_voltage < 8,43))
       {
        time=12000;
        j=2;
        cell_count(j, time);
       }
       if((bat_voltage > 8.45) && (bat_voltage < 11.1))
       {
        alarm_sequence();
       }
       if((bat_voltage > 11.1) && (bat_voltage < 12.8))
       {
        time=12000;
        j=3;
        cell_count(j, time);
       }
        if((bat_voltage > 12.9) && (bat_voltage < 14.8))
       {
        alarm_sequence();
       }
       if((bat_voltage >14.8) && (bat_voltage < 17.0))
       {
        time=12000;
        j=4;
        cell_count(j, time);
       }
}
        
//***********************************************************

//DISPLAY CONTROL
//***************************
// LCD print GPS data
//**********************
void gps_position_print()
  {
  // if (GPS_screen==0)
    //  {
    //  lcd.clearLCD();
    //  }
    //  else
    //  {
  GPS_screen=1;
      
  lcd.gotoPosition(4,0);
  Serial.print("  GPS DATA  ");

// LCD print latitude 
  lcd.gotoPosition(0, 1);
  Serial.print("Lat:");
  Serial.print(y_int);
  Serial.print(".");
  Serial.print(y);
  Serial.print(lat);
  
// LCD ptint longitude  
 lcd.gotoPosition(0, 2);
  Serial.print("Lgt:");
  Serial.print(x_int);
  Serial.print(".");
  Serial.print(x);
  Serial.print(lgt);  

// LCD print altitude
   lcd.gotoPosition(0, 3);
  Serial.print("alt:");
  Serial.print(z_int=al_titude/100);
  Serial.print(".");
  Serial.print(z=al_titude%100);
  Serial.print("m");

// LCD print ground speed
  lcd.gotoPosition(0, 4);
  Serial.print("vel:");
  Serial.print(g_speed);
  Serial.print("Km/h");
  //    }  
  } 

// LCD print flight data
//***********************
void flight_data_print() 
{
// Barometric Altitude Calculation
  if (flight_screen=0)
      {
      lcd.clearLCD();
       }
      else
      {
      flight_screen=1;

  lcd.gotoPosition(2,0);
  Serial.print("Flight Data");

  lcd.gotoPosition(0,2);
  Serial.print("Altit. = ");
  Serial.print(altitude_barometric,1);
  lcd.gotoPosition(0, 3);
  Serial.print("vel= ");
  Serial.print(g_speed);
  Serial.print("Km/h");
  lcd.gotoPosition(0, 4);
  Serial.print("ADC val=");
  Serial.print(val);
      }
  
}
//**************************************************************

// LCD motor data print
//************************
void motor_data_print()
{
  if (motor_screen=0)
      {
      lcd.clearLCD();
      }
      else
      {
      motor_screen=1;
 
// LCD batery voltage print
  lcd.gotoPosition(4, 0);
  Serial.print(" Motor Data");
  lcd.gotoPosition(0, 1);
  Serial.print("Bat.Vlt.=");
  Serial.print(bat_voltage,2);

// LCD RPM value print
  lcd.gotoPosition(0, 2);
  Serial.print("RPM = ");
  Serial.print(RPM_value);

//Battery Dischage Calculation
  lcd.gotoPosition(0, 3);
  Serial.print("mAH = ");
  Serial.print(mAH,0);
  lcd.gotoPosition(0, 4);
  Serial.print("I Amp.= ");
  Serial.print(I_instantaneo,2);
  
 //Battery Temperature Calculation
  lcd.gotoPosition(0, 5);
  Serial.print("Bat.temp.=");
  Serial.print(temperature,1);
      }
}

void max_values()
{

if (I_instantaneo > I_max)
    I_max=I_instantaneo;
    
if (RPM_value > rpm_max)
   rpm_max = RPM_value;
   
if (temperature > bat_temp_max)
    bat_temp_max = temperature;
    
if (altitude_barometric > altit_baro_max)
    altit_baro_max = altitude_barometric;
    
if (g_speed > veloc_max)
    veloc_max = g_speed;

if ((al_titude/100) > altit_max)
    altit_max = (al_titude/100);
    
}
    

void max_data_print()
 {
 // Max. Values Print
 // Current Max. print
  lcd.gotoPosition(0, 0);
  Serial.print(" Max Values ");
  lcd.gotoPosition(0, 1);
  Serial.print("I Max.=");
  Serial.print(I_max,1);

// Max. RPM value print
  lcd.gotoPosition(0, 2);
  Serial.print("RPM= ");
  Serial.print(rpm_max);

//Max. temperature Print
  lcd.gotoPosition(0, 3);
  Serial.print("Temp.= ");
  Serial.print(bat_temp_max,1);
  
//Max. Barometric Altitude  
  lcd.gotoPosition(0, 4);
  Serial.print("Bar.Alt.=");
  Serial.print(altit_baro_max,1);
  
 //Max. Speed Print
  lcd.gotoPosition(0, 5);
  Serial.print("Speed =");
  Serial.print(veloc_max);

 }





/************************************************************
This routine sets the timer (bip) frequency and the munber of
bips depending of number of battery cell*/
void cell_count(uint8_t j, uint16_t time)
{
  digitalWrite(13, HIGH);
  OCR1A=time;
  count=j;
  TCCR1B |= (1 << WGM12);   // CTC mode
  TCCR1B |= (1 << CS12)|(1<<CS10);    // 1024 prescaler
} 
  

/***********************************************************
 This routine sets the alarm sequence, faster bit and high number
  of bips*/
void alarm_sequence()
      {
      OCR1A=3000; // 0.5 seconds On and OFF
      count=60;
      TCCR1B |= (1 << WGM12);   // CTC mode
      TCCR1B |= (1 << CS12)|(1<<CS10); // CTC mode and 1024 prescaler
      }


/* This routine turns ON the speaker and counts the number of bips.
   Each interrupt it toggles the speaker and at the end make sure it is OFF*/
 
ISR(TIMER1_COMPA_vect)          // timer compare interrupt service routine
{
  digitalWrite(buzzerpin, digitalRead(buzzerpin) ^ 1);   // toggle speaker pin
  count--;
  if (count==0)
  {
   TCCR1B =0;  // Clear bits. stop the timer
   digitalWrite(buzzerpin, LOW);
  }  
}