Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
String to float
15-12-2011, 12:19 PM,
#1
String to float
I'm doing a G-Code interpreter in Pinguino, and I have to pass float values from the PC. The problem is that I can't find a function to translate strings to float.
I've found that pinguino supports atoi (string to integer i believe), but I don't know if atof or similar is implemented...

¿Some ideas?

Thanks!
Reply
15-12-2011, 08:38 PM,
#2
RE: String to float
Try it?
Reply
15-12-2011, 09:28 PM,
#3
RE: String to float
Ok, silly question. Yes, I tried, but I tried with stdio.h and string.h, not with stdlib.h Blush
Silly me, I've been facing this problem for some time and I didn't see it. Really sorry!
Reply
15-12-2011, 10:19 PM, (This post was last modified: 15-12-2011, 10:20 PM by pingotg.)
#4
RE: String to float
If it's working, that's good! Don't worry about the postings Smile

John
Reply
18-12-2011, 06:06 PM,
#5
RE: String to float
A little off-topic, are you writing your own interpreter for G-Codes, or is it a port of some Arduino code? I was thinking on porting the RepRap libraries to Pinguino... Those are C++, but as RepRap has PIC firmware, maybe it's already done in C?
Reply
19-12-2011, 01:58 AM,
#6
RE: String to float
(18-12-2011, 06:06 PM)Alfred Wrote: A little off-topic, are you writing your own interpreter for G-Codes, or is it a port of some Arduino code? I was thinking on porting the RepRap libraries to Pinguino... Those are C++, but as RepRap has PIC firmware, maybe it's already done in C?

Thanks Alfred! Porting the arduino c++ code is a bit messy (in this particular case), so I prefer writing it again and copy some functions from there. I've been looking for the PIC firmware, but it only appears as .hex format! If you find C code, that would be great!
Reply
16-02-2012, 06:09 PM,
#7
RE: String to float
Hello,

it seems that electronlibre uses the atof() function.

I try to uses this function but the result is wrong.
Simple code for testing

Quote:void test() {
char s[]="123.45";
char out[50];
float f;
f = atof(s)*1.5f;
sprintf(out,"%.2f",f);

CDC.print(out);
CDC.print("\r\n");
}


void setup() {
}

void loop() {
test();
}

The result is -1288490240.00 !!!
if I use atoi () instead of atof () the result is correct : 184.50 (123.5 -> integer = 123 * 1.5 =184.50)

the problem is in my code or is it a bug in atof () ?

I use Ide X2 rev 266 (svn) linux with pinguino32-otg

Thanks


Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)