go_away

Author Topic: Strange printf output  (Read 2081 times)

0 Members and 1 Guest are viewing this topic.

Offline fabguyTopic starter

  • Jr. Member
  • **
  • Posts: 19
  • Helpful? 1
Strange printf output
« 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?

Offline waltr

  • Supreme Robot
  • *****
  • Posts: 1,944
  • Helpful? 99
Re: Strange printf output
« Reply #1 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?

Offline chelmi

  • Supreme Robot
  • *****
  • Posts: 496
  • Helpful? 15
    • Current projects
Re: Strange printf output
« Reply #2 on: March 26, 2010, 06:01:50 PM »
we need to see your code

Offline fabguyTopic starter

  • Jr. Member
  • **
  • Posts: 19
  • Helpful? 1
Re: Strange printf output
« Reply #3 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);
   }

Offline dunk

  • Expert Roboticist
  • Supreme Robot
  • *****
  • Posts: 1,086
  • Helpful? 21
    • dunk's robot
Re: Strange printf output
« Reply #4 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 )
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.

Offline chelmi

  • Supreme Robot
  • *****
  • Posts: 496
  • Helpful? 15
    • Current projects
Re: Strange printf output
« Reply #5 on: March 26, 2010, 08:44:49 PM »
also, you have 3 format placeholders (%x), but only 2 parameters.

Offline fabguyTopic starter

  • Jr. Member
  • **
  • Posts: 19
  • Helpful? 1
Re: Strange printf output
« Reply #6 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 )
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

Offline chelmi

  • Supreme Robot
  • *****
  • Posts: 496
  • Helpful? 15
    • Current projects
Re: Strange printf output
« Reply #7 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 for more details.

Chelmi.

 


Get Your Ad Here