Society of Robots - Robot Forum

Software => Software => Topic started by: fabguy on March 26, 2010, 05:21:07 PM

Title: Strange printf output
Post 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?
Title: Re: Strange printf output
Post by: waltr on March 26, 2010, 05:54:12 PM
Are the values raw binary and if so are your converting them to ASCII (text) in the printf?
Title: Re: Strange printf output
Post by: chelmi on March 26, 2010, 06:01:50 PM
we need to see your code
Title: Re: Strange printf output
Post by: fabguy on March 26, 2010, 06:21:29 PM
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);
   }
Title: Re: Strange printf output
Post by: dunk on March 26, 2010, 07:54:14 PM
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.
Title: Re: Strange printf output
Post by: chelmi on March 26, 2010, 08:44:49 PM
also, you have 3 format placeholders (%x), but only 2 parameters.
Title: Re: Strange printf output
Post by: fabguy on March 27, 2010, 05:46:50 AM
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
Title: Re: Strange printf output
Post by: chelmi on March 27, 2010, 08:42:54 AM
I just realized that you variable is a long int. You need to add a 'l' to your format placeholder. i.e.:
Code: [Select]
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.