NerdKits - electronics education for a digital generation

You are not logged in. [log in]

NEW: Learning electronics? Ask your questions on the new Electronics Questions & Answers site hosted by CircuitLab.

Support Forum » tempsensor fail: printf_P and fprintf_P don't output anything

October 23, 2010
by dthomas
dthomas's Avatar

I have completed the tempsensor tutorial project. Everything seems to be working: I get temperature reads and all. Except for those parts of the program that use the streams, both fprintf_P and printf_P don't output anything.

Sample output:

ADC:  144 of  1024
˚F

This tells me, that the wiring is alright. It also tells me, that the libnerdkits/lcd.h can talk to the lcd. I have made sure that the tempsensor/tempsensor.c and tempsensor_edu/tempsensor.c files are identical.

I'm pretty new to hardware, but from my experience as a software developer I guess the problem might be in linking the <avr/io.h> library. If it is, then this information might be useful:

macbook:~/workspace/nerdkit/sample/tempsensor_edu dthomas$ make
avrdude -c avr109 -p m168 -b 115200 -P /dev/cu.PL2303-0000103D -U flash:w:tempsensor.hex:a

Connecting to programmer: .
Found programmer: Id = "FDL v02"; type = S
    Software Version = 0.2; No Hardware Version given.
Programmer supports auto addr increment.
Programmer supports buffered memory access with buffersize=128 bytes.

Programmer supports the following devices:
    Device code: 0x35

avrdude: AVR device initialized and ready to accept instructions

Reading | ################################################## | 100% 0.00s

avrdude: Device signature = 0x1e9406
avrdude: NOTE: FLASH memory has been specified, an erase cycle will be performed
         To disable this feature, specify the -D option.
avrdude: erasing chip
avrdude: reading input file "tempsensor.hex"
avrdude: input file tempsensor.hex auto detected as Intel Hex
avrdude: writing flash (10404 bytes):

Writing | ################################################## | 100% 11.05s

avrdude: 10404 bytes of flash written
avrdude: verifying flash memory against tempsensor.hex:
avrdude: load data flash data from input file tempsensor.hex:
avrdude: input file tempsensor.hex auto detected as Intel Hex
avrdude: input file tempsensor.hex contains 10404 bytes
avrdude: reading on-chip flash data:

Reading | ################################################## | 100% 1.31s

avrdude: verifying ...
avrdude: 10404 bytes of flash verified

avrdude done.  Thank you.

macbook:~/workspace/nerdkit/sample/tempsensor_edu dthomas$

I'm running Mac OS X 10.4.11. Also, this might hint at the compiler I'm using (I'm pretty sure I just followed your guide)

macbook:~/workspace/nerdkit/sample/tempsensor_edu dthomas$ avr-gcc -v
Reading specs from /usr/local/AVRMacPack-20080721/lib/gcc/avr/3.4.6/specs
Configured with: ../configure --prefix=/usr/local/AVRMacPack-20080721 --disable-dependency-tracking --disable-nls --target=avr --enable-languages=c,c++ --disable-nls --disable-libssp --with-dwarf2
Thread model: single
gcc version 3.4.6

Where should I start looking for the error?

October 23, 2010
by hevans
(NerdKits Staff)

hevans's Avatar

Hi dthomas,

Did you remember to run

avr-gcc-select 4

on the command line after installing AVR mac pack? Not running that command will definitely cause strange things to happen to printf and scanf.

Humberto

October 23, 2010
by Ralphxyz
Ralphxyz's Avatar

re: "Except for those parts of the program that use the streams, both fprintf_P and printf_P don't output anything."

You need to use Terminal screen in order to see anything on your mac!

Open another Terminal window and Type in screen /dev/cu.PL2303-0000101D 115200 (adjust for your USB port).

You should see the stream output.

Ralph

October 24, 2010
by bretm
bretm's Avatar

The tempsensor.c program writes to the LCD with one of the fprintf_P's, so they don't necessarily need a terminal. It looks like the only part missing is the part generated by

fprintf_P(&lcd_stream, PSTR("Temperature: %.2f"), temp_avg);

instead of the lcd_writes.

October 25, 2010
by dthomas
dthomas's Avatar

Thanks for all the feedback!

@hevans: just to be sure, I reexecuted the avr-gcc-select command:

macbook:~/workspace/nerdkit/sample/tempsensor dthomas$ avr-gcc-select 4 
Current default compiler: gcc 4

I then reprogrammed the chip, but the buggy behavior remains.

@Raplhxyz: wow, somehow I had totally missed this. So thats what the UART library is for. Great. Except, nothing is being written to stdout as far as I can tell.

These two findings make me even more sure, that somehow the wrong libraries are being used. (@bretm: yeah, it seems like any writes to streams are not working).

I also tried another chip (I ordered a bunch and now have some spares) but the same issue remains.

Does anybody have an idea for further tests I could do?

October 25, 2010
by Ralphxyz
Ralphxyz's Avatar

In light of the above and unless you get a better answer "Start Over From Scratch"!!

Down load the source code again and do a default unzip.

You changed things with your original unzip as illustrated by:

"macbook:~/workspace/nerdkit/sample/tempsensor_edu dthomas$ make"

A default unzip would have macbook:~/workspace/nerdkit/code/tempsensor_edu dthomas$ make.

The code folder has the Nerdkit libraries (Code/libnerdkits) which might have gotten munged.

Are your new mcu's from Nerdkits or from a distributer? If not from Nerdkits you'll need a bootloader installed.

It's a pain I know but try it.

Ralph

October 25, 2010
by hevans
(NerdKits Staff)

hevans's Avatar

Hi dthomas,

Just to make sure the code is actually getting recompiled make sure you delete all the .hex and .o files in both the libnerdkits directory and the whichever directory you are working in (probably intitialload), then try make again. The make program tries to be smart about when it needs to recompile code, and if nothing has changed in the source files it does not attempt to compile the code again. Perhaps you just got a strange initial compile for some reason.

Humberto

October 26, 2010
by dthomas
dthomas's Avatar

@Humberto, this did the trick! I deleted all *.hex and *.o files in the tempsensor project and the libnerdkits folder. After remaking, it works!

I guess I must have missed avr-gcc-select 4 on the first build and have been using a bad libnerdkits since then...

@Ralphxyz, yup, restarting from scratch should also have done the trick...

Thanks to @all who helped me out here :) yay! now to convert to ˚C...

Post a Reply

Please log in to post a reply.

Did you know that the printf format string "%.3f" will show three digits after the decimal point? Learn more...