Arduino sketch isnt running after uploaded

Hi,

i have worked with arduino mega (2560) in a few projects. Everything is working fine with display touchscreen until my sketch exceed some memory space (still under the suppossed 253k limit).
(Board, Processor, Port, Programmer: AVRISP mkII, i think this is fine)

  • images used as .c
  • utft library used (with some lines uncommented in memorysaver)
  • relay8 library
  • utouch library

Everything works fine (display, touchscreen, relays, etc), some logic and buttons designed to control relays:

Sketch uses 61706 bytes (24%) of program storage space. Maximum is 253952 bytes.

then i add one conditional and some function calls, at this point when i compile (fine) and upload (console and verbose says everything is fine) but the sketch will never start, i get a white screen.

Sketch uses 89120 bytes (35%) of program storage space. Maximum is 253952 bytes.

this is the message i get from console:

avrdude: Version 6.3, compiled on Jan 17 2017 at 12:00:53
Copyright (c) 2000-2005 Brian Dean, http://www.bdmicro.com/
Copyright (c) 2007-2014 Joerg Wunsch

System wide configuration file is "C:\Program Files (x86)\Arduino\hardware\tools\avr/etc/avrdude.conf"

Using Port : COM9
Using Programmer : wiring
Overriding Baud Rate : 115200
AVR Part : ATmega2560
Chip Erase delay : 9000 us
PAGEL : PD7
BS2 : PA0
RESET disposition : dedicated
RETRY pulse : SCK
serial program mode : yes
parallel program mode : yes
Timeout : 200
StabDelay : 100
CmdexeDelay : 25
SyncLoops : 32
ByteDelay : 0
PollIndex : 3
PollValue : 0x53
Memory Detail :

Block Poll Page Polled
Memory Type Mode Delay Size Indx Paged Size Size #Pages MinW MaxW ReadBack


eeprom 65 10 8 0 no 4096 8 0 9000 9000 0x00 0x00
flash 65 10 256 0 yes 262144 256 1024 4500 4500 0x00 0x00
lfuse 0 0 0 0 no 1 0 0 9000 9000 0x00 0x00
hfuse 0 0 0 0 no 1 0 0 9000 9000 0x00 0x00
efuse 0 0 0 0 no 1 0 0 9000 9000 0x00 0x00
lock 0 0 0 0 no 1 0 0 9000 9000 0x00 0x00
calibration 0 0 0 0 no 1 0 0 0 0 0x00 0x00
signature 0 0 0 0 no 3 0 0 0 0 0x00 0x00

Programmer Type : Wiring
Description : Wiring
Programmer Model: AVRISP
Hardware Version: 15
Firmware Version Master : 2.10
Vtarget : 0.0 V
SCK period : 0.1 us

avrdude: AVR device initialized and ready to accept instructions

Reading | ################################################## | 100% 0.02s

avrdude: Device signature = 0x1e9801 (probably m2560)
avrdude: reading input file "C:\Users\ADMINI~1\AppData\Local\Temp\arduino_build_46368/newControl.ino.hex"
avrdude: writing flash (89120 bytes):

Writing | ################################################## | 100% 14.32s

avrdude: 89120 bytes of flash written
avrdude: verifying flash memory against C:\Users\ADMINI~1\AppData\Local\Temp\arduino_build_46368/newControl.ino.hex:
avrdude: load data flash data from input file C:\Users\ADMINI~1\AppData\Local\Temp\arduino_build_46368/newControl.ino.hex:
avrdude: input file C:\Users\ADMINI~1\AppData\Local\Temp\arduino_build_46368/newControl.ino.hex contains 89120 bytes
avrdude: reading on-chip flash data:

Reading | ################################################## | 100% 11.46s

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

avrdude done. Thank you.

I tried another arduino mega, and get the same behaviour... small sketch works fine, add some functions and will not work anymore.

(deleted)

Sorry,

i wasnt trying to be mean, the code is pretty simple - with some bad practices and still u nfinished (bad practices as i used landscape touch in portrait display coordinates, nothing that will mess with final functionality).

Display used is TFT_320_QVT_9341 (im prestty sure this doesnt matter).

As is unfinished the last line i added:

line 247 calls a function that checks if a button is already pressed and some screen draws to update the button state.

Until here everything works fine…

line 249 (its commented) calls another function that does the same work with another button…
at this point, the project will verify, compile, upload but nothing will appear on screen.

Clarification: (i mixed some draws in the screen in an attempt to reduce memory usage, calling drawbitmap and fillrect functions to draw the buttons).

newControl.zip (34.1 KB)

Please provide links to ALL non-standard libraries that you use. It's a bit much asked for us to hunt them down and possibly end up with the wrong ones.

PS
We're in general more interested in RAM usage than program space usage; could not find it in your opening post.

UTFT library:
http://www.rinkydinkelectronics.com/library.php?id=51

URTouch library:
http://www.rinkydinkelectronics.com/library.php?id=92

Relay8 library:
http://www.rinkydinkelectronics.com/library.php?id=57

I included Relay8 library to use it after programming the UI.

I dont Know how i can reduce ram usage.
The only problem i detected in previous projects was file size in bitmaps. Thats why i started making hybrid buttons (rectangle with .fillRect method + borders as .c bitmap)

image converter i used: Rinky-Dink Electronics

How much data are you stuffing into progmem?

You can only put 64k of data into progmem without complications - the addressing is 16-bit when using pgm_get_byte_near(), and I'm not sure how you get the farptrs for pgm_get_byte_far() Edit: With pgm_get_far_address(). Read docs for pgmspace.h

The awkward part is that you probably use libraries that already have the functionality to read from the near flash, and those would need to be modified.

ok,
as i understand i should get rid of those PROGMEM o try to optimize my flash memory usage.
All images i converted are using PROGMEM keyword (can i remove it without affecting the program?).

I can edit some libraries if needed but dont know where to start or a guide to know what should be done.

im very thankful for your help.

No, you can't remove the progmem keyword because you can't fit the data into RAM (you only have I think 8k of ram!). It becomes much harder to read from progmem once you've passed the 64k barrier...

I've never done it, so I can't give specific help here...

Everyplace where pgm_read_*_near functions are used needs to be modified though (where * is any basic datatype)

Thanks, i will try it.

This is my UI (attached) and i think is something small and simple (6 buttons ), thats why i wonder how some devs achieve complex UIs and complex functionality without having this problem.

It's the bitmap images that do it. I bet many people doing fancy ui pit the images on an sd card or something.

Or use fancier processors.

If you use character LCD, you can get lots of ui content into 16k of flash. IMO putting a tft display on an 8 bit avr is inappropriate - a mismatch in complexity/power/memory scales.

This is a great explain, i started undestanding my mistake.

thank you DrAzzy.