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;