Society of Robots - Robot Forum
Software => Software => Topic started by: fabguy on March 26, 2010, 05:21:07 PM
-
Hey guys.
Ive got a ZX-sound sound detector module and a Phigits precision light sensor. There connected the my Axon controller and seem to work fine. But I cant seem to use them properly. When I use printf to see what I'm working with I get a strange output. As the numbers increase they turn into letters. The first digit is usually a number but the last 2 or 3 depending on light and sound input are letters.
Has anybody seen this before and how do I get rid of it?
-
Are the values raw binary and if so are your converting them to ASCII (text) in the printf?
-
we need to see your code
-
Thankyou for the quick responce
long int light;
long int sound;
void update_sensors(void)
{
sound = a2dConvert10bit(4);
light = a2dConvert10bit(6);
rprintf("\r\n%x %x %x", sound, light);
delay_ms(20);
}
-
hey Fabguy,
printf usually uses the %x specifier for hexadecimal numbers.
(ie, base 16. http://en.wikipedia.org/wiki/Hexadecimal (http://en.wikipedia.org/wiki/Hexadecimal) )
so the letters and numbers are the expected behavior.
look at the documentation for your printf function and see if there is a decimal specifier.
(usually %i or %d)
good luck!
dunk.
-
also, you have 3 format placeholders (%x), but only 2 parameters.
-
also, you have 3 format placeholders (%x), but only 2 parameters.
Sorry about that I had another variable there but I took it out when I posted the code, just to be more specific on what I needed help with.
hey Fabguy,
printf usually uses the %x specifier for hexadecimal numbers.
(ie, base 16. http://en.wikipedia.org/wiki/Hexadecimal (http://en.wikipedia.org/wiki/Hexadecimal) )
so the letters and numbers are the expected behavior.
look at the documentation for your printf function and see if there is a decimal specifier.
(usually %i or %d)
good luck!
dunk.
%d worked fine but. It still had a strange output if I tryied to print out more than one at a time. It works fine with one but not with 2 or more. Ohwell thankyou! I have the information I need now.
Fabguy
-
I just realized that you variable is a long int. You need to add a 'l' to your format placeholder. i.e.:
rprintf("\r\n%lx %lx", sound, light);
See http://www.nongnu.org/avr-libc/user-manual/group__avr__stdio.html#ga3b98c0d17b35642c0f3e4649092b9f1 (http://www.nongnu.org/avr-libc/user-manual/group__avr__stdio.html#ga3b98c0d17b35642c0f3e4649092b9f1) for more details.
Chelmi.