[SOLVED] Problem with uploading larger programs (caused by old version)

Hello, I bought Andruino Starter Kit last week and tried some examples there, all working.
Then I merged code from couple of them together, to create simple LCD thermometer. It also worked, till I start to create better display messages.

When I upload script to Arduino, it says "Binary sketch size 4 448 bytes (of a 32 256 byte maximum)", (led 13 is blinking as on every upload), but then nothing happens. Not even led start to blink/shine - nothing.
When I comment out nearly anyone line of code, then everything works as expected.

I tried different things and elaborated code, which is just 4 bytes large to work - commenting anything out makes the code to be smaller and work flawlessly. I also tried to play with string constants, but making strings inside longer/shorter does not affect this behavior. I tried to compile from command line and got the same results - looks, like it depends on size of code, not size of data.

What I should do now? Is something I could try? Or should I return it as defect HW?

I attached the program, the end of good and end of bad session (with commented out just one call to Temp() function).

Thanks for any suggestions.

Temp.ino (1.42 KB)

OK.txt (833 Bytes)

BAD.txt (832 Bytes)

The symptoms are similar to excessive use of RAM.
You could research using the F() macro.

Please post your code.

The code is attachment Temp.ino in my first post. There are also reports from compilers (for good and bad case)

I also tried another ATmega328 chip, the problem still resist. Also tried it with only Andruino UNO board alone, without bredboard or any other HW attached, the problem resist. (Without HW it just wait 4.5 sec, then flash LED 13 for 4.5 sec, leave it shining, then repeat - it can be tested without any wiring at all).

My OS is Linux Gento, I can also send any other data of interest.

Using only the Uno board is the best way to make it work.

You don't have a lot of arrays, so you use only little ram.
The influence of the code size seems to me just an coincidence.

What about power, versions, libraries ?

How is is powered ? Only via the USB bus ? Can you try with a power supply ?
Do you use the newest version of the Arduino ? Version 1.0.4 or 1.5.2.
Do you have a mix of old versions via the repositories with new downloaded versions ?
Is it a clone Arduino Uno, with a bad bootloader ?
Is the microcontroller on the Arduino Uno the ATmega328P-.. or the ATmega328-PU (without the 'P').
If nothing seem to help, could you try it with Windows ?
I can upload your sketch without problem, using Arduino 1.0.4 / 1.5.2.

Can you change the sketch.
First of all, use the serial monitor.
In setup() do this:

void setup() {
  Serial.begin(9600);
  Serial.println("Hello");
  .....

In Temp() do this:

  .....
  cels=(voltage -0.5)*100.0;
  
  Serial.print("cels = ");
  Serial.println(cels);
  .....

Open the serial monitor of the Arduino IDE after uploading.
Do the values look okay ?

It is powered only by the USB from my PC.

When I upload the bad (too long) version, then disconect it from USB then connect to 7.5V powersupply, it still do not work. Short version works on the 7.5V supply.

I have version 1.0.3 and not more recent version is in my repository.

I bought the starter Kit at GME.cz, it looks like original. I bought the other chip there too.
On the kit chip is written: ATMEL 1228 ATMEGA328P-PU, on the other ATMEL 1223 ATMEGA328P-PU

I have no Windows.

I will try to change the sketch and report back, but there will probabelly be no change - I tried Serial communication from the Starter Kit examples and it worked ok, I think, it will not send anything, if it is not able even to blik LED 13.

Also I will try to install Arduino 1.0.4 from sources, will report back about that too.

I have no clue in what direction to look. Everything seems to be okay.
But at least add a lot Serial.println() messages, perhaps the programs stops after a wrong function call.

I tried the Serial thing, but no success - if I comment out enought code to be "small" it just works. if I comment out less, so it is large, then it say nothing. Which is consistent with previous tests - I think, that satting LED HIGH would be visible, if the programs just try it, but it did not run thru the setup(), so no chance to go to loop() and fail there on some function.

Also what bad calling function it would be, if it works after commenting out any of lines, that generate code? That meant, if I comment out say lcd.print("C "); it works (so I would suspect this function of being source of problem). But if I return the line back and comment out any one of the 3 calls to Temp(), it works too - and the remaining 2 calls to Temp() show the temperature with "C " without problems.

(Adding Serial made the cede larger -so it stopeed working again until I commented out enough code to climb under the critical value.)

It's too weird to be true.
Everything indicates a size problem (either flash or ram), but I think that is not possible. Perhaps with a wrong bootloader.

Do you have a programmer ? To update the bootloader ?

Could you try another computer ?
Download Arduino 1.0.4 on an other computer, install the device driver for windows, use the same Arduino Uno and the same sketch.

That should work.
If it works, you have to investigate the difference between both computer setups.
If it doesn't, perhaps the bootloader is wrong.

Can you upload a photo of the Arduino Uno with wires and usb and so ?

I have no other HW than the Starter Kit and one spare ATMEGA328P-PU (so no programmer I think).
I will try other comp and GIT version of Arduino, but it will take some time to arrange.
I have problems with obtaining good photo, but if you look at official pictures of Arduino Uno R3, then it is nearly the same. Differences are:

  • crystal is marked T16.000 not SPK16.000G
  • the yellow thing left of him reads 5010, not 501K
  • on back side is written TE (circled) S# 011 UR (italic reverse) 94V-O in upper right corner
  • the date in lower right corner reads 2011-11-03, not 2011-3-02
    I could not found any more differences, so I suppose that it is little newer version of R3, but original.

No wires are attached now, just provided USB cable to laptop. (so I cannot read the lcs, but can see blinking LED13).


I also dumped what is stored on the board ( /usr/bin/avrdude -DV -p atmega328p -P /dev/ttyACM0 -c arduino -b 115200 -U flash:r:Ard_ok.raw:r ) and compared it by hands (via hexdump and vimdiff):

  • there is a lot of differences in single values, all differs by 6, which is the difference in the size of images (so it should be ok)
  • from around 2F7 there is some 12 bytes (i think 6 16-bit words) more in the bad image.
  • from that it is 12 bytes shifted to the end, with a lot places different 6 in value
    My resume is, that the program is probably correctly written to the device, but is not started properly.

Small correction - I did comment out function with parameters, so the size changed from 4376 to 4364 - so it is probably 12 bytes, not 6 16-bites words.

A programmer is always useful. You could buy a USBasp programmer on Ebay for a few euros/dollars. You can also use an Arduino as programmer (Arduino as ISP).
If you rewrite the bootloader, also the fuses are set properly. This can done from within the Arduino IDE.

With avrdude, you can check the fuses.
The file 'boards.txt' contains the settings for the fuses for the Arduino Uno.
uno.bootloader.low_fuses=0xff
uno.bootloader.high_fuses=0xde
uno.bootloader.extended_fuses=0x05
http://www.engbedded.com/fusecalc

At this point, rewriting the bootloader would be my first goal.
Perhaps you can collect more information, I still don't know how to interpret the size problem.

You could add a lot of code, and test what happens you pass the 8k or 16k boundery.
This function can be usefull, Arduino Playground - AvailableMemory
A sketch for information, Arduino Playground - ShowInfo

FINALLY SOLVED :smiley:

I uploaded the GIT version of Arduino on other computer, installed everything from scratch and it works. Now I will try find, where the versions differs and what makes the difference (as Arduino is a bunch of programs and libraries and I want to know, how such problems could arise under hoods)

I'm glad it is solved !
Allthough I have no idea what might have caused it.

You now know that your Arduino board is okay.

Did you mix different versions of Arduino ? Perhaps a linker that didn't match the compiler ?
To test it, use the latest stable version, version 1.0.4