Offline
Newbie
Karma: 0
Posts: 11
|
 |
« on: June 14, 2012, 11:44:55 am » |
Hello ! I have an Arduino nano with a Nokia 6100 LCD, and a EM-406A GPS receiver. The fonction to upload text to the LCD is : void drawString(char *s, int fg, int bg, int x, int y); I want to upload on the screen for exemple my altitude, but i need to convert a float variable to a char*. I tried drawString((char*)&altitude,WHITE,0,50,0); and with sprintf but it doesn't work.  Do you have a solution ? thinks !
|
|
|
|
|
Logged
|
|
|
|
|
Seattle, WA USA
Offline
Brattain Member
Karma: 315
Posts: 35519
Seattle, WA USA
|
 |
« Reply #1 on: June 14, 2012, 11:55:41 am » |
ftoa() or dtostrf() will do what you need to do.
|
|
|
|
|
Logged
|
|
|
|
|
Offline
Newbie
Karma: 0
Posts: 11
|
 |
« Reply #2 on: June 14, 2012, 12:47:58 pm » |
Indeed, it works ! Do you know how to convert a byte in a char* ? thinks 
|
|
|
|
|
Logged
|
|
|
|
|
Global Moderator
UK
Offline
Brattain Member
Karma: 138
Posts: 19067
I don't think you connected the grounds, Dave.
|
 |
« Reply #3 on: June 14, 2012, 12:51:21 pm » |
Cast it to an int and use itoa
|
|
|
|
|
Logged
|
Pete, it's a fool looks for logic in the chambers of the human heart.
|
|
|
|
Offline
Newbie
Karma: 0
Posts: 11
|
 |
« Reply #4 on: June 14, 2012, 01:22:53 pm » |
When i do : int_h = (int)h; itoa(int_h,char_h,2); drawString(char_h,WHITE,0,50,0);
It displays 0 ! But on my computer, (with serial.println) it's not 0 ...
|
|
|
|
« Last Edit: June 14, 2012, 01:30:33 pm by helium255 »
|
Logged
|
|
|
|
|
Global Moderator
UK
Offline
Brattain Member
Karma: 138
Posts: 19067
I don't think you connected the grounds, Dave.
|
 |
« Reply #5 on: June 14, 2012, 01:57:10 pm » |
Why do you want to print it in binary? Just curious.
|
|
|
|
|
Logged
|
Pete, it's a fool looks for logic in the chambers of the human heart.
|
|
|
|
Offline
Newbie
Karma: 0
Posts: 11
|
 |
« Reply #6 on: June 14, 2012, 02:14:35 pm » |
I don't ! The fonction gps.crack_datetime(&annee, &mois, &jour, &h, &min, &sec, &age); use byte variables, so I have to convert it in a char* to display it.
|
|
|
|
|
Logged
|
|
|
|
|
Seattle, WA USA
Offline
Brattain Member
Karma: 315
Posts: 35519
Seattle, WA USA
|
 |
« Reply #7 on: June 14, 2012, 08:38:19 pm » |
When i do : int_h = (int)h; itoa(int_h,char_h,2); drawString(char_h,WHITE,0,50,0);
It displays 0 ! But on my computer, (with serial.println) it's not 0 ... Which is why we don't want to see just snippets of your code. We want to see all of it.
|
|
|
|
|
Logged
|
|
|
|
|
Offline
Newbie
Karma: 0
Posts: 11
|
 |
« Reply #8 on: June 15, 2012, 03:23:02 am » |
sorry: #include <nokialcd_controlcodes.h> #include <nokialcd_driver.c> #include <nokialcd_driver.h> #include <nokialcd_font.c> #include <nokialcd_font.h> #include <nokialcd_io.h> #include <nokialcd_scroll.c> #include <nokialcd_scroll.h> #include <sysconfig-atmega168.c>
#include <SoftwareSerial.h> #include <TinyGPS.h>
float latitude, longitude; float alt; char char_alt[8]; int annee; byte mois, jour, heure, minute, sec, age; char *char_h, *char_min; int int_h, int_min; long vitesse_kmh; long vitesse_knot; long cap;
SoftwareSerial s_gps(6,5); TinyGPS gps; void getgps(TinyGPS &gps);
void setup() { sysInit(); LCDInitController(); LCDClearScreen(0x003); s_gps.begin(4800);
}
void loop() { /////////////////////////////// while(s_gps.available()) { byte c = s_gps.read(); if(gps.encode(c)) { getgps(gps); } } //////////////////////////////// int_h = (int)heure; itoa(int_h,char_h,2);// The problem is here drawString(char_h,WHITE,0,50,0); drawString("heure",WHITE,0,63,0);
dtostrf(alt,6,2,char_alt); if(alt<9999.0){//evite le 100000.00 qui reste sur l'écran drawString(char_alt,WHITE,0,10,30); } }
void getgps(TinyGPS &gps) { gps.f_get_position(&latitude,&longitude); gps.crack_datetime(&annee, &mois, &jour, &heure, &minute, &sec, &age); alt = gps.f_altitude(); cap = gps.f_course(); vitesse_kmh = gps.f_speed_kmph(); vitesse_knot = gps.f_speed_mph();
}
For the moment the code only displayed the hour(not the minutes), and the altitude. when i delete the line with the itoa(), the altitude is displayed on my screen, but when i put it in my code, the altitude displayed stays at 0.00. look at the pictures:the one with the altitude displayed is the code without the itoa().
|
|
|
|
|
Logged
|
|
|
|
|
Global Moderator
UK
Offline
Brattain Member
Karma: 138
Posts: 19067
I don't think you connected the grounds, Dave.
|
 |
« Reply #9 on: June 15, 2012, 03:46:43 am » |
long vitesse_knot; "vitesse_noeud", surely?
|
|
|
|
|
Logged
|
Pete, it's a fool looks for logic in the chambers of the human heart.
|
|
|
|
Offline
Newbie
Karma: 0
Posts: 11
|
 |
« Reply #10 on: June 15, 2012, 03:49:14 am » |
why not ?
|
|
|
|
|
Logged
|
|
|
|
|
Global Moderator
UK
Offline
Brattain Member
Karma: 138
Posts: 19067
I don't think you connected the grounds, Dave.
|
 |
« Reply #11 on: June 15, 2012, 03:51:08 am » |
Parce-que byte mois, jour, heure, 
|
|
|
|
|
Logged
|
Pete, it's a fool looks for logic in the chambers of the human heart.
|
|
|
|
Offline
Newbie
Karma: 0
Posts: 11
|
 |
« Reply #12 on: June 15, 2012, 04:00:42 am » |
 The GPS can give me my speed in knot or in km/h. Anyway, for the moment it's not the problem(later maybe). Why the itoa() doesn't work ?
|
|
|
|
« Last Edit: June 15, 2012, 04:58:00 am by helium255 »
|
Logged
|
|
|
|
|
Seattle, WA USA
Offline
Brattain Member
Karma: 315
Posts: 35519
Seattle, WA USA
|
 |
« Reply #13 on: June 15, 2012, 05:50:08 am » |
char *char_h, *char_min; A pointer is useless UNTIL it points to something. These do not at this time. itoa(int_h,char_h,2);// The problem is here It certainly is. You are trying to write to a place you have no business writing to. The function would throw an exception, if it could. But, it can't. So, it silently does nothing. char char_h[3], char_min[3]; would be a much better declaration statement for your purposes. And, now you know why snippets are useless.
|
|
|
|
|
Logged
|
|
|
|
|
Offline
Newbie
Karma: 0
Posts: 11
|
 |
« Reply #14 on: June 15, 2012, 07:21:29 am » |
sprintf(char_time,"%02d:%02d",heure,minute); drawString(char_time,WHITE,0,50,0);
It works !
|
|
|
|
|
Logged
|
|
|
|
|
|