Hey,
I just recently ordered a teensy 2, after weeks of troubles with a fake one (w/o knowing! Bummer).
Now, it's just plain fun!
Yet, it's been over 10 years since I tried programming C in a decent way.
Being new in chips & microcontrollers, so to understand hardware-programming, I decided to try Arduino-teensyduino-interface first.
After blinking leds, I managed to get my teensy talking over Serial & Uart, having conversations with an old windows-based gps.
But, while using sprintf to build some strings, I wonder about performance & datatypes.
<snip>
char *SSTRING;
int Data1=0, Data2=0, Data3=0;
loop {
Data1=999999; // Need to be able to send at least 6 "9"s.
Data2=99999;
Data3=9999;
sprintf(SSTRING,"$SOFT,%u,%i,%u",Data1,Data2,Data3);
Uart.println(SSTRING);
delay(200);
}
</snip>
Not entirely okay, but something like that, you get the point.
Now, it's sending all kind of stuff, but the problem is that "999999" gets turned in some number that doesn't reflect at all what I'm trying to send, turned in something like 19382, or -32000 and a bit... Probably just overflowed?
So, I've got a couple of questions:
1. What am I doing wrong? Which datatype is supported in teensy and what am I supposed to use to print integers like 999999 (6 9s)? int? double? long?
I don't need floatingpoint-possibilities, just positive numbers. And some negatives but those are quite smaller (temperature-like).
2. Am I actually using the correct flags for sprintf (%u, %i) to build my string?
3. Performance-wise, is there a better option than sprintf to build my string? And get it over the Uart?
4. Is it okay to use char* for my send-string or would it be better to just use a fixed char[xxxx]-size-thing? Ending it with "\0"?
Pretty newbie-questions, I know... but after trying some different things with doubles, longs & floats, I seem to be doing something wrong.
Thanks in advance.
Fré
I just recently ordered a teensy 2, after weeks of troubles with a fake one (w/o knowing! Bummer).
Now, it's just plain fun!
Yet, it's been over 10 years since I tried programming C in a decent way.
Being new in chips & microcontrollers, so to understand hardware-programming, I decided to try Arduino-teensyduino-interface first.
After blinking leds, I managed to get my teensy talking over Serial & Uart, having conversations with an old windows-based gps.
But, while using sprintf to build some strings, I wonder about performance & datatypes.
<snip>
char *SSTRING;
int Data1=0, Data2=0, Data3=0;
loop {
Data1=999999; // Need to be able to send at least 6 "9"s.
Data2=99999;
Data3=9999;
sprintf(SSTRING,"$SOFT,%u,%i,%u",Data1,Data2,Data3);
Uart.println(SSTRING);
delay(200);
}
</snip>
Not entirely okay, but something like that, you get the point.
Now, it's sending all kind of stuff, but the problem is that "999999" gets turned in some number that doesn't reflect at all what I'm trying to send, turned in something like 19382, or -32000 and a bit... Probably just overflowed?
So, I've got a couple of questions:
1. What am I doing wrong? Which datatype is supported in teensy and what am I supposed to use to print integers like 999999 (6 9s)? int? double? long?
I don't need floatingpoint-possibilities, just positive numbers. And some negatives but those are quite smaller (temperature-like).
2. Am I actually using the correct flags for sprintf (%u, %i) to build my string?
3. Performance-wise, is there a better option than sprintf to build my string? And get it over the Uart?
4. Is it okay to use char* for my send-string or would it be better to just use a fixed char[xxxx]-size-thing? Ending it with "\0"?
Pretty newbie-questions, I know... but after trying some different things with doubles, longs & floats, I seem to be doing something wrong.
Thanks in advance.
Fré
Last edited: