Show Posts
|
|
Pages: 1 [2] 3
|
|
18
|
Forum 2005-2010 (read only) / Syntax & Programs / Re: Storing very first input
|
on: March 05, 2010, 07:48:12 pm
|
|
I changed the stupid double equals error, but i still have the same results.
[code] #include <OLED320.h> #include <string.h> #include <ctype.h> #include <print.h>
int rx1Pin = 19; // RX1 PIN int tx1Pin = 18; // TX1 TX int byteGPS=-1; char linea[300] = ""; char arguments[13][11]; float flt_arguments[13]; char comandoGPR[7] = "$GPRMC"; int cont=0; int bien=0; int conta=0; int indices[13]; float latitude, longitude, lat_rad, long_rad; float origin_lat, origin_long, int_lat, int_long; int m = 0;
OLED320 LED;
void setup() { pinMode(rx1Pin, INPUT); pinMode(tx1Pin, OUTPUT); Serial1.begin(4800); Serial2.begin(9600); Serial.begin(19200); //delay(100); for (int i=0;i<300;i++){ // Initialize a buffer for received data linea=' '; }
Serial2.print(0x55,BYTE); delay(1000);
LED.LED_Clear(); delay(100);
}
void loop() { gps(); }
void gps(){ byteGPS=Serial1.read(); // Read a byte of the serial port if (byteGPS == -1) { // See if the port is empty yet delay(100); } else { linea[conta]=byteGPS; // If there is serial port data, it is put in the buffer conta++; //Serial.print(byteGPS, BYTE); if (byteGPS==13){ // If the received byte is = to 13, end of transmission cont=0; bien=0; for (int i=1;i<7;i++){ // Verifies if the received command starts with $GPR if (linea==comandoGPR[i-1]){ bien++; } } if(bien==6){ // If yes, continue and process the data char* str = linea; //direct linea char array to str pointer array char seperator = ','; int count = 0, index = 0, sIndex = 0; int theSize = 299; arguments[index][count] = '\0'; // clear first argument before starting flt_arguments[index] = '\0'; while (theSize > sIndex + 1){ if (*str != seperator){ arguments[index][count] = *str; //store array sections into argument arrays } else { arguments[index][count] = '\0'; } *str++; count++; sIndex++;
if (*str == seperator){ *str++; // jump over the separator count = 0; index++; arguments[index][count] = '\0'; // clear argument before starting } } for(int i=1; i<10; i++){ flt_arguments = atof (arguments); //convert character in argument array into floating point } latitude = flt_arguments[3]; //assign latitude floating point array to a single floating point variable longitude = flt_arguments[5]; //assign longitude floating point array to a single floating point variable int_lat = latitude*10000; int_long = longitude*10000; Serial.print("INT LAT: "); Serial.println(int_lat); Serial.print("INT LONG: "); Serial.println(int_long); Serial.println("________"); if(m==0){ origin_lat = int_lat; origin_long = int_long; m++; }
getpoint(origin_lat, origin_long, int_lat, int_long); } conta=0; // Reset the buffer for (int i=0;i<300;i++){ // linea=' '; } } } }
void getpoint(float origin_lati, float origin_longi, float current_lat, float current_long){ int ya, yb; float tempx, tempy; tempx = (current_lat - origin_lati); //set original coordiates at (0,0) tempy = (current_long - origin_longi); int x = (int)(tempx*10); int y = (int)tempy; if(y<256){ ya = 0; yb = y; } else{ ya = 1; yb = y-256; } Serial.print("origin_lat: "); Serial.println(origin_lati); Serial.print("origin_long: "); Serial.println(origin_longi); Serial.print("current_lat: "); Serial.println(current_lat); Serial.print("current_long: "); Serial.println(current_long); Serial.print("tempx: "); Serial.println(tempx); Serial.print("tempy: "); Serial.println(tempy); Serial.print("x: "); Serial.println(x); Serial.print("y: "); Serial.println(y); Serial.println("_________"); }
|
|
|
|
|
19
|
Forum 2005-2010 (read only) / Syntax & Programs / Storing very first input
|
on: March 05, 2010, 06:56:09 pm
|
I was looking to take in latitude and longitude data and set the very first reading as the origin point on an led. All other location readings would be displayed on the screen in respect to the first stored location. This is what I tried first: int m = 0;
void loop(){ if(m=0){ origin_lat = int_lat; origin_long = int_long; m++; } }
But the values of origin_lat and origin_long equal 0 and don't match int_lat or int_long. Is there an easier way to go about this?
|
|
|
|
|
20
|
Forum 2005-2010 (read only) / Syntax & Programs / Re: invalid conversion from char to char*
|
on: February 21, 2010, 05:10:56 pm
|
and it prints the correct amount of characters when printing to the serial monitor. for(int j=8; j<14; j++){ Serial.print(linea[j]); } Serial.println(" "); for(int j=17; j<26; j++){ Serial.print(linea[j]); } Serial.print(" "); for(int j=27; j<28; j++){ Serial.print(linea[j]); } Serial.println(" "); for(int j=29; j<39; j++){ Serial.print(linea[j]); } Serial.print(" "); for(int j=40; j<41; j++){ Serial.print(linea[j]); }
|
|
|
|
|
22
|
Forum 2005-2010 (read only) / Syntax & Programs / invalid conversion from char to char*
|
on: February 21, 2010, 04:22:51 pm
|
I am having a problem passing a character to a function. It gives the invalid conversion from char to char* error. I am using the code from the parallax gps arduino tutorial at: http://www.arduino.cc/playground/Tutorials/GPSThis is the code: void loop() { byteGPS=Serial1.read(); // Read a byte of the serial port if (byteGPS == -1) { // See if the port is empty yet delay(100); } else { linea[conta]=byteGPS; // If there is serial port data, it is put in the buffer conta++; Serial.print(byteGPS, BYTE); if (byteGPS==13){ // If the received byte is = to 13, end of transmission cont=0; bien=0; for (int i=1;i<7;i++){ // Verifies if the received command starts with $GPR if (linea[i]==comandoGPR[i-1]){ bien++; } } if(bien==6){ // If yes, continue and process the data for (int i=0;i<300;i++){ if (linea[i]==','){ // check for the position of the "," separator indices[cont]=i; cont++; } if (linea[i]=='*'){ // ... and the "*" indices[12]=i; cont++; } } for(int j=8; j<14; j++){ LED.LED_PrintString(linea[j], 0x00, 0x1d, 0x00, 0x02, 0, 0x00, 0x00, 0x01, 0x02); //print time value } } conta=0; // Reset the buffer for (int i=0;i<300;i++){ // linea[i]=' '; } } } delay(1000); } this is the function i am passing it to: void OLED320::LED_PrintString(char* str, char xa, char xb, char ya, char yb, char font, char color1, char color2, char width_, char height_) { delay(10); int i = 0; Serial.print(0x53,BYTE); //print string cmd Serial.print(xa,BYTE); //xa coord Serial.print(xb,BYTE); //xb coord Serial.print(ya,BYTE); //y1 coord Serial.print(yb,BYTE); //y2 coord Serial.print(font,BYTE); //font Serial.print(color1,BYTE); //color Serial.print(color2,BYTE); //color Serial.print(width_,BYTE); //width Serial.print(height_,BYTE); //height
while(str[i]!='\0') { Serial.print(str[i],BYTE); i++; } Serial.print(0x00,BYTE); //Terminator } I am confused because I was able to pass the character arrays to this function using the LB_GPS library functions for example: void loop() { GPS.getRaw(100);
GPS.GPSStringExplode(GPS.inBuffer,','); LED.LED_PrintString(GPS.arguments[1], 0x00, 0x1d, 0x00, 0x02, 0, 0x00, 0x00, 0x01, 0x02); //print time value }
I tried using: LED.LED_PrintString((char*)linea[j], 0x00, 0x1d, 0x00, 0x02, 0, 0x00, 0x00, 0x01, 0x02); and it would compile but it would not display the data. Thanks!
|
|
|
|
|
30
|
Forum 2005-2010 (read only) / Syntax & Programs / Software Serial & Parallax GPS
|
on: February 20, 2010, 01:15:23 pm
|
I am having problems outputting the raw NMEA strings coming from the Parallax GPS while using a software serial pin. This code works great when using pin 0 and 1: #include <string.h> #include <ctype.h>
int rxPin = 0; // RX PIN int txPin = 1; // TX TX int byteGPS=-1; char linea[300] = ""; char comandoGPR[7] = "$GPRMC"; int cont=0; int bien=0; int conta=0; int indices[13];
void setup() { pinMode(rxPin, INPUT); pinMode(txPin, OUTPUT); Serial.begin(4800); for (int i=0;i<300;i++){ // Initialize a buffer for received data linea[i]=' '; } }
void loop() { byteGPS=Serial.read(); // Read a byte of the serial port if (byteGPS == -1) { // See if the port is empty yet delay(100); } else { linea[conta]=byteGPS; // If there is serial port data, it is put in the buffer conta++; Serial.print(byteGPS, BYTE); if (byteGPS==13){ // If the received byte is = to 13, end of transmission cont=0; bien=0; for (int i=1;i<7;i++){ // Verifies if the received command starts with $GPR if (linea[i]==comandoGPR[i-1]){ bien++; } } conta=0; // Reset the buffer for (int i=0;i<300;i++){ // linea[i]=' '; } } } }
and the serial monitor displays this:  And using softwareserial and pins 8 and 9: #include <string.h> #include <ctype.h> #include <SoftwareSerial.h>
#define rxPin 8 #define txPin 9
SoftwareSerial mySerial = SoftwareSerial(rxPin, txPin); int byteGPS=-1; char linea[300] = ""; char comandoGPR[7] = "$GPRMC"; int cont=0; int bien=0; int conta=0; int indices[13];
void setup() { Serial.begin(19200); pinMode(rxPin, INPUT); pinMode(txPin, OUTPUT); mySerial.begin(4800); for (int i=0;i<300;i++){ // Initialize a buffer for received data linea[i]=' '; } }
void loop() { byteGPS=mySerial.read(); // Read a byte of the serial port if (byteGPS == -1) { // See if the port is empty yet delay(100); } else { linea[conta]=byteGPS; // If there is serial port data, it is put in the buffer conta++; Serial.print(byteGPS, BYTE); if (byteGPS==13){ // If the received byte is = to 13, end of transmission digitalWrite(ledPin, LOW); cont=0; bien=0; for (int i=1;i<7;i++){ // Verifies if the received command starts with $GPR if (linea[i]==comandoGPR[i-1]){ bien++; } } conta=0; // Reset the buffer for (int i=0;i<300;i++){ // linea[i]=' '; } } } }
And the serial monitor prints this:  which seems to print the right data but it does not print the headers for each string and it is continuously printing horizontally. Any suggestions will help! Thanks.
|
|
|
|
|