Show Posts
Pages: [1] 2 3
1  Forum 2005-2010 (read only) / Troubleshooting / Re: Printing floats to the Serial port on: March 03, 2010, 08:05:48 pm
Ok.  All is right with the world, for now.  This worked:

declared flt_arguments as a one dimensional array:
float flt_arguments[13];

and the code:

Code:
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
             }
            
           }          
                
          [glow]for(int i=1; i<10; i++){
            flt_arguments[i] = atof (arguments[i]);
          }[/glow]
          
          Serial.print("LAT: ");
          Serial.println(flt_arguments[3],4);
          Serial.print("LONG: ");
          Serial.println(flt_arguments[5],4);
}
          
2  Forum 2005-2010 (read only) / Troubleshooting / Re: Printing floats to the Serial port on: March 03, 2010, 07:02:40 pm
I tried this code with the error invalid conversion from 'char' to 'const char*'.

Code:
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
        
           while (theSize > sIndex + 1){
             if (*str != seperator){
               arguments[index][count] = *str;  //store array sections into argument arrays
               flt_arguments[index][count] = atof (*str);
             }
             else {
               arguments[index][count] = '\0';
               flt_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
               flt_arguments[index][count] = '\0';
             }
             //flt_arguments[index][count] = (float) arguments[index][count];
           }
    }
3  Forum 2005-2010 (read only) / Troubleshooting / Re: Printing floats to the Serial port on: March 03, 2010, 03:45:52 pm
OK.  I will attempt that but is this conversion from an array of characters to a float array legal:

float_arguments[index][count] = (float) arguments[index][count];

with them declared as:

 char arguments[13][11];
 float float_arguments[13][11];
4  Forum 2005-2010 (read only) / Troubleshooting / Printing floats to the Serial port on: March 03, 2010, 03:25:52 pm
I have a problem with printing a float array.  It says the call of the overloaded 'print(float[11], int)' is ambiguous.

here is the code:

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];
 [glow]double float_arguments[13][11];[/glow]
 char comandoGPR[7] = "$GPRMC";
 int cont=0;
 int bien=0;
 int conta=0;
 int indices[13];

OLED320 LED;

void setup() {
pinMode(rx1Pin, INPUT);
pinMode(tx1Pin, OUTPUT);
Serial1.begin(4800);
Serial2.begin(9600);
Serial.begin(19200);

for (int i=0;i<300;i++){       // Initialize a buffer for received data
  linea[i]=' ';
}

Serial2.print(0x55,BYTE);          //initialize led
delay(1000);

LED.LED_Clear();                    //clear led
delay(100);

}

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++;                      
     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 data
         for (int i=0;i<300;i++){
           if (linea[i]==','){    // check for position of "," separator
             indices[cont]=i;
             cont++;
           }
           if (linea[i]=='*'){    // ... and the "*"
             indices[12]=i;
             cont++;
           }
         }
                  
           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
        
           while (theSize > sIndex + 1){
             if (*str != seperator){
               arguments[index][count] = *str;  //store array sections into argument arrays
               [glow]float_arguments[index][count] = (float) arguments[index][count];[/glow]
             }
             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
               float_arguments[index][count] = '\0';
             }
           }          
          
          Serial.print("LAT: ");
          [glow]Serial.print(float_arguments[3],2);[/glow]
       }
       conta=0;                    // Reset the buffer
       for (int i=0;i<300;i++){    //  
         linea[i]=' ';            
       }                
     }
   }
}


I thought print could now handle floating point.  Possibly I was wrong in assuming it could handle an array of floating points.
5  Forum 2005-2010 (read only) / Syntax & Programs / Re: Passing Arrays into a function on: February 16, 2010, 08:44:29 pm
I figured it out!  Thanks for the help.  The issue was that I was not allowing a long enough delay after a command to change the background so the LCD was never receiving the bytes telling it to print the array!
6  Forum 2005-2010 (read only) / Syntax & Programs / Re: Passing Arrays into a function on: February 16, 2010, 08:04:23 pm
I removed the delay to no avail.  How do I go about checking the RX line with a scope?
7  Forum 2005-2010 (read only) / Syntax & Programs / Re: Passing Arrays into a function on: February 16, 2010, 06:29:06 pm
I am leaving the usb cable plugged in and each serial.print(hex value here, BYTE) sends a command to the graphics controller on the LCD.

  Serial.print(0x53,BYTE);          //print string cmd
  Serial.print(0x05,BYTE);          //x coord
  Serial.print(0x00,BYTE);          //y1 coord
  Serial.print(0x05,BYTE);         //y2 coord
  Serial.print(0x00,BYTE);         //font
  Serial.print(0x0f,BYTE);          //color
  Serial.print(0xff,BYTE);          //color
  Serial.print(0x02,BYTE);         //width
  Serial.print(0x02,BYTE);         //height
  Serial.print('G',BYTE);            //print G
  Serial.print(0x00,BYTE);         //Terminator


This set of commands prints The letter 'G' on the LCD.
8  Forum 2005-2010 (read only) / Syntax & Programs / Re: Passing Arrays into a function on: February 16, 2010, 05:50:42 pm
Well it looks like it prints the correct data to the serial console but this text is not showing up on the LCD as it does for the code without the function.
9  Forum 2005-2010 (read only) / Syntax & Programs / Re: Passing Arrays into a function on: February 16, 2010, 04:21:59 pm
Still no luck.  I feel like it isn't keeping the actual character elements in the new array.  Code:

Code:
char str1[]="abctest";
printstring(str1);

}
void loop() {
}

void printstring(char* str) {
  
  delay(100);
  int i = 0;
 
  Serial.print(0x53,BYTE);        //print string cmd
  Serial.print(0x05,BYTE);           //x coord
  Serial.print(0x00,BYTE);          //y1 coord
  Serial.print(0x05,BYTE);          //y2 coord
  Serial.print(0x00,BYTE);        //font
  Serial.print(0x0f,BYTE);      //color
  Serial.print(0xff,BYTE);      //color
  Serial.print(0x02,BYTE);      //width
  Serial.print(0x02,BYTE);     //height

  while(str[i]!='\0')
  {  
    Serial.print(str[i],BYTE);
    i++;
  }

  Serial.print(0x00,BYTE);         //Terminator

}

Here is the serial output for this code:





Here is the Serial Output for the original code without a printstring function:



This output matches that of the code with the function but this code actually prints "abctest" to the LCD screen.
10  Forum 2005-2010 (read only) / Syntax & Programs / Passing Arrays into a function on: February 16, 2010, 03:48:51 pm
I'm new to the Arduino and I am having problems passing an array to a function to print to a 4D uLCD-320PMD2 screen using a Picaso graphics controller.


This code prints an array of characters successfully:


Code:
void setup() {
Serial.begin(9600);            //open serial port at 9600 bps

Serial.print(0x55,BYTE);      //initialize LCD

char str[]="abctest";
int i = 0;

Serial.print(0x53,BYTE);     //print string cmd
Serial.print(0x05,BYTE);     //x coord
Serial.print(0x00,BYTE);     //y1 coord
Serial.print(0x05,BYTE);     //y2 coord
Serial.print(0x00,BYTE);     //font
Serial.print(0x0f,BYTE);      //color
Serial.print(0xff,BYTE);      //color
Serial.print(0x02,BYTE);     //width
Serial.print(0x02,BYTE);     //height
  
  while(str[i]!='\0')
  {  
    Serial.print(str[i],BYTE);   //print each array element until '\0'
    i++;
  }

  Serial.print(0x00,BYTE);         //Terminator

}


while this code prints nothing:

Code:
void setup() {
Serial.begin(9600);            //open serial port at 9600 bps

Serial.print(0x55,BYTE);      //initialize LCD

char str1[]="abctest";
printstring(str1);

}
void loop() {
}

void printstring(char str[]) {
  
  delay(100);
  int i = 0;
 
  Serial.print(0x53,BYTE);        //print string cmd
  Serial.print(0x05,BYTE);        //x coord
  Serial.print(0x00,BYTE);        //y1 coord
  Serial.print(0x05,BYTE);        //y2 coord
  Serial.print(0x00,BYTE);        //font
  Serial.print(0x0f,BYTE);         //color
  Serial.print(0xff,BYTE);         //color
  Serial.print(0x02,BYTE);        //width
  Serial.print(0x02,BYTE);       //height

  while(str[i]!='\0')
  {  
    Serial.print(str[i],BYTE);
    i++;
  }
  Serial.print(0x00,BYTE);         //Terminator
}


I've also tried:
void printstring(char *str[]) {


Thanks for the help, and sorry if I looked over the obvious solution when searching the forums!
11  Forum 2005-2010 (read only) / Syntax & Programs / Re: editing certain digits in a number on: March 27, 2010, 11:22:36 am
No, there is no decimal point missing.  I am using strtok to parse the whole nmea string as you helped me with before.  Since the latitude and longitude are strings before I convert them, I can just pull out the second two digits by using their index I believe.

tempminutes[0] = latitude[2];
tempminutes[1] = latitude[3];
latitude[2] = 0;
latitude[3] = 0;

tempminutes = tempminutes/60;
latitude = latitude + tempminutes;
12  Forum 2005-2010 (read only) / Syntax & Programs / editing certain digits in a number on: March 26, 2010, 05:06:24 pm
My GPS module is providing latitude and longitude in a form that needs to be changed.  It is giving Degrees, Minutes, and fractions of Minutes.  It is giving something similar to this:

3045.7834

I would like to change the Minutes into fractions of Degrees:

30.757834


Is there a simple way to alter the 3rd and 4th digits to put it into this form?
13  Forum 2005-2010 (read only) / Syntax & Programs / Re: Storing very first input on: March 10, 2010, 02:05:23 pm
Thanks Paul!  It works great now.  I used this code:

Code:
if(bien==6){               // If yes, continue and process the data        
          char *token;
          int tokNum;
          char delims[] = ",";
          char *time_char = NULL;
          char *fix_char = NULL;
          char *lat_char = NULL;
          char *latdir_char = NULL;
          char *long_char = NULL;
          char *longdir_char = NULL;
          char *date_char = NULL;

          token = strtok(linea, delims);
            tokNum = 0;
            while(token){
            // Decide whether to save or convert the token, or not
            switch(tokNum){
                case 1:                     // token = time
               time_char = token;
               break;
              case 2:                     // token = fix
               fix_char = token;
               break;
                case 3:                     // token = latitude
               lat_char = token;
               break;
                case 4:                     // token = latitude direction
               latdir_char = token;
               break;
                case 5:                     // token = longitude
               long_char = token;
               break;
                case 6:                     // token = longitude direction
               longdir_char = token;
               break;                
                case 9:                     // token = fix
               date_char = token;
               break;    
            }
            token = strtok(NULL, delims);
              tokNum++;
            }  
          time = atof(time_char);
          latitude = atof(lat_char);
          latitude = latitude/100;
          longitude = atof(long_char);
          longitude = longitude/100;
          date = atof(date_char);
}

I was also wondering the best way to truncate the latitude and longitude floats.  The values have 8 numbers such as 4807.0385 and I want to multiply by 1000 to give 4807038.5 and round the number to 4807039.

Using:
Code:
latitude = atof(lat_char);
longitude = atof(long_char);
latitude = latitude*1000;
longitude = longitude*1000;  
int_lat = (int)latitude;
int_long = (int)longitude;
          
          Serial.print("latitude: ");
          Serial.println(latitude);
          Serial.print("longitude: ");
          Serial.println(longitude);
          Serial.print("INT LAT: ");
          Serial.println(int_lat);
          Serial.print("INT LONG: ");
          Serial.println(int_long);

I see:

latitude: 3037100.25
longitude: 9620388.00
INT LAT: 22444
INT LONG: -13404

Thanks!
14  Forum 2005-2010 (read only) / Syntax & Programs / Re: Storing very first input on: March 08, 2010, 10:15:13 pm
Ok so how about something along these lines...

Code:
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[i]==comandoGPR[i-1]){
           bien++;
         }
       }
       if(bien==6){               // If yes, continue and process the data          
               char delims[] = ",";
               char* result1 = NULL;
               char* result2 = NULL;
               char* result3 = NULL;
              
               result1 = strtok(linea, delims);
               result2 = strtok(NULL, delims);
               result3 = strtok(NULL, delims);
}


giving:
result1 = "$GPRMC"
result2 = "123519"
result3 = "A"

for example.

$GPRMC,123519,A,4807.038,N,01131.000,E,022.4,084.4,230394,003.1,W*6A
15  Forum 2005-2010 (read only) / Syntax & Programs / Re: Storing very first input on: March 07, 2010, 09:03:55 pm
Well, I am just working off of the example code I found and it has been working so I didn't try to change up the code and implement the strtok function.

I printed the value of m in the previous post.

I am not sure when to terminate the character array entries.
Pages: [1] 2 3