So at work I am building a Poster with lots of Neopixels to draw attention to our work. The code has gotten so big, that I ran out of RAM on the Micro I was using. Apperently Neopixels need a lot of free RAM to send the data out to the LEDs. Arduino IDE showed 70 % RAM used, no errors, but the LEDs just didnt light up. Took me a long time to figure this one out.
So I switched to the Arduino with the most RAM and a 5 V architecture, which is the Nano Every. The program works fine and now I can have a lot bigger arrays for complex blinking action. But if I want to use Serial.print() for debugging the Arduino resets and sometimes prints � in the serial monitor, sometimes nothing.
I read in another thread that Serial.print() resetting the Arduino indicates memory problems, like writing outside of an array. But it doesnt happen on the Micro and it happens even before the first call of any array. Serial.print() works normal until I call the first function in Loop().
Is there a difference between the Micro and Nano Every that I am missing? Can the problem be the declaration of my arrays, because it already happens before the arrays are called? I have the <avrdude: jtagmkII_initialize(): Cannot locate "flash" and "boot" memories in description> error message, but people say this can be ignored.
Please post your sketch, using code tags when you do
In my experience the easiest way to tidy up the code and add the code tags is as follows
Start by tidying up your code by using Tools/Auto Format in the IDE to make it easier to read. Then use Edit/Copy for Forum and paste what was copied in a new reply. Code tags will have been added to the code to make it easy to read in the forum thus making it easier to provide help.
Ok, I will try to delete as much stuff as possible, so you dont have to read through all 11 kB. The Auto Format shifted my arrays around, thats not great. I had the numbers aligned in rows.
Don't worry much about that, we can 'see' past that as long as the code still compiles. IF you reduce your code, you'll likely change, or eradicate the problem, so it would be better if you present the problematic code with no changes, just formatted. We can talk about what we see then.
Before I post all of it, here is the function I think causes the problem. I had issues with going outside the array, but then i put in the contrain().
//int spectrometer[4][5][21]
void sap(int speed, int sapmode) {
if (random(0, 3) == 0) {
int x = random(0, 5);
int y = random(0, 21);
if (spectrometer[2][x][y] == 0) spectrometer[2][x][y] = 100;
}
for (int i = 0; i < 5; i++) {
for (int j = 0; j < 21; j++) {
switch (spectrometer[2][i][j]) {
case 100:
if (j == 20) bcount++;
if (sapmode == 1) spectrometer[2][i][constrain(j + spectrometer[3][i][j], 0, 20)] = 100;
else spectrometer[2][i][constrain(j + spectrometer[1][i][j], 0, 20)] = 100;
spectrometer[2][i][j] = 50;
if (spectrometer[3][i][j] == 1 && sapmode == 1) j++;
else if (spectrometer[1][i][j] == 1 && sapmode == 0) j++;
break;
case 50:
spectrometer[2][i][j] = 20;
break;
case 20:
spectrometer[2][i][j] = 0;
break;
default:
break;
}
}
}
if (sapmode == 1)
for (int i = 0; i < 5; i++)
for (int j = 0; j < 21; j++) pixels.setPixelColor(spectrometer[0][i][j], pixels.Color(spectrometer[2][i][j], max(0, 10 * spectrometer[3][i][j]), max(0, -10 * spectrometer[3][i][j])));
else
for (int i = 0; i < 5; i++)
for (int j = 0; j < 21; j++) pixels.setPixelColor(spectrometer[0][i][j], pixels.Color(spectrometer[2][i][j], max(0, 10 * spectrometer[1][i][j]), max(0, -10 * spectrometer[1][i][j])));
pixels.show();
delay(speed);
bdetector();
}
What I find strange is, if I remove any calls to this function, the problem with Serial.print() goes away. So the IDE doesnt compile functions that are never called? But then if I leave the calls in the program, why does it fail before the problematic function is even called? It must be that compiling this function already causes the problem, not actually runing it.
Please post your full sketch. It is important to be able to see how all of your variables are declared
When I compile your code for the Every, I see that the dynamic RAM allocated seems to be fewer bytes than I expected, given the number of global ints declared at the top of the code. Makes me think some of that is unreferenced, and therefore discarded by the compiler automatically. That would explain even compiling on the Nano, if you didn't reference one of the large arrays(i.e. only sap() referenced a large array, but sap() was commented out).
So it would seem that even now, on the Every, some of that data is not referenced and therefore discarded.
Have you looked at the compiler's output to see if there are hints there? Go to Preferences, and turn up compiler output, then recompile and dig through the output. If you want, post the complete compilation output here for inspection.
As I thought, the large array (spectrometer[][][]) is only referenced within sap(), and therefore if sap() is never called, both the function and the array are eliminated by the compiler.
Once the array is referenced(inferred by a reference to sap()), the array is compiled. Changes the amount of memory used quite significantly, but I'm not yet seeing the root problem. TBD.
As an aside, I presume you have a pulldown resistor on pin 3, and that your button pulls the pin to 5V when pressed. If the pulldown isn't present, your sensing of pin 3's state will be erratic.
The sketch uses 13028 kB of flash memory and 2457 kB of sRAM on a micro, but 11754 kB of flash memory and 1405 kB of RAM on a nano every. No idea how this works. Since the sketch runs fine I dont think the nano every is loosing data.
Yes, the button has a pulldown resistor.
Here is the compiler output. Sorry for the German in there, my IDE is set to English.
FQBN: arduino:megaavr:nona4809:mode=off
Using board 'nona4809' from platform in folder: C:\Users\x\AppData\Local\Arduino15\packages\arduino\hardware\megaavr\1.8.8
Using core 'arduino' from platform in folder: C:\Users\x\AppData\Local\Arduino15\packages\arduino\hardware\megaavr\1.8.8
Verwendete Bibliotheken erkennen ...
C:\Users\x\AppData\Local\Arduino15\packages\arduino\tools\avr-gcc\7.3.0-atmel3.6.1-arduino5/bin/avr-g++ -c -g -Os -w -std=gnu++11 -fpermissive -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics -Wno-error=narrowing -flto -w -x c++ -E -CC -mmcu=atmega4809 -DF_CPU=16000000L -DARDUINO=10607 -DARDUINO_AVR_NANO_EVERY -DARDUINO_ARCH_MEGAAVR -DMILLIS_USE_TIMERB3 -DNO_EXTERNAL_I2C_PULLUP -IC:\Users\x\AppData\Local\Arduino15\packages\arduino\hardware\megaavr\1.8.8\cores\arduino/api/deprecated -IC:\Users\x\AppData\Local\Arduino15\packages\arduino\hardware\megaavr\1.8.8\cores\arduino -IC:\Users\x\AppData\Local\Arduino15\packages\arduino\hardware\megaavr\1.8.8\variants\nona4809 C:\Users\x\AppData\Local\Temp\arduino\sketches\34152714B6AC21BB4C92691033658340\sketch\KATRIN_LED_Modell_4_game.ino.cpp -o nul
Alternativen für Adafruit_NeoPixel.h: [Adafruit NeoPixel@1.12.3]
ResolveLibrary(Adafruit_NeoPixel.h)
-> Kandidaten: [Adafruit NeoPixel@1.12.3]
C:\Users\x\AppData\Local\Arduino15\packages\arduino\tools\avr-gcc\7.3.0-atmel3.6.1-arduino5/bin/avr-g++ -c -g -Os -w -std=gnu++11 -fpermissive -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics -Wno-error=narrowing -flto -w -x c++ -E -CC -mmcu=atmega4809 -DF_CPU=16000000L -DARDUINO=10607 -DARDUINO_AVR_NANO_EVERY -DARDUINO_ARCH_MEGAAVR -DMILLIS_USE_TIMERB3 -DNO_EXTERNAL_I2C_PULLUP -IC:\Users\x\AppData\Local\Arduino15\packages\arduino\hardware\megaavr\1.8.8\cores\arduino/api/deprecated -IC:\Users\x\AppData\Local\Arduino15\packages\arduino\hardware\megaavr\1.8.8\cores\arduino -IC:\Users\x\AppData\Local\Arduino15\packages\arduino\hardware\megaavr\1.8.8\variants\nona4809 -IC:\Users\x\Documents\Arduino\libraries\Adafruit_NeoPixel C:\Users\x\AppData\Local\Temp\arduino\sketches\34152714B6AC21BB4C92691033658340\sketch\KATRIN_LED_Modell_4_game.ino.cpp -o nul
Using cached library dependencies for file: C:\Users\x\Documents\Arduino\libraries\Adafruit_NeoPixel\Adafruit_NeoPixel.cpp
Using cached library dependencies for file: C:\Users\x\Documents\Arduino\libraries\Adafruit_NeoPixel\esp.c
Using cached library dependencies for file: C:\Users\x\Documents\Arduino\libraries\Adafruit_NeoPixel\esp8266.c
Using cached library dependencies for file: C:\Users\x\Documents\Arduino\libraries\Adafruit_NeoPixel\kendyte_k210.c
Funktionsprototypen werden generiert ...
C:\Users\x\AppData\Local\Arduino15\packages\arduino\tools\avr-gcc\7.3.0-atmel3.6.1-arduino5/bin/avr-g++ -c -g -Os -w -std=gnu++11 -fpermissive -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics -Wno-error=narrowing -flto -w -x c++ -E -CC -mmcu=atmega4809 -DF_CPU=16000000L -DARDUINO=10607 -DARDUINO_AVR_NANO_EVERY -DARDUINO_ARCH_MEGAAVR -DMILLIS_USE_TIMERB3 -DNO_EXTERNAL_I2C_PULLUP -IC:\Users\x\AppData\Local\Arduino15\packages\arduino\hardware\megaavr\1.8.8\cores\arduino/api/deprecated -IC:\Users\x\AppData\Local\Arduino15\packages\arduino\hardware\megaavr\1.8.8\cores\arduino -IC:\Users\x\AppData\Local\Arduino15\packages\arduino\hardware\megaavr\1.8.8\variants\nona4809 -IC:\Users\x\Documents\Arduino\libraries\Adafruit_NeoPixel C:\Users\x\AppData\Local\Temp\arduino\sketches\34152714B6AC21BB4C92691033658340\sketch\KATRIN_LED_Modell_4_game.ino.cpp -o C:\Users\x\AppData\Local\Temp\3183751610\sketch_merged.cpp
C:\Users\x\AppData\Local\Arduino15\packages\builtin\tools\ctags\5.8-arduino11/ctags -u --language-force=c++ -f - --c++-kinds=svpf --fields=KSTtzns --line-directives C:\Users\x\AppData\Local\Temp\3183751610\sketch_merged.cpp
Sketch wird kompiliert ...
"C:\\Users\\x\\AppData\\Local\\Arduino15\\packages\\arduino\\tools\\avr-gcc\\7.3.0-atmel3.6.1-arduino5/bin/avr-g++" -c -g -Os -Wall -Wextra -std=gnu++11 -fpermissive -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics -Wno-error=narrowing -MMD -flto -mmcu=atmega4809 -DF_CPU=16000000L -DARDUINO=10607 -DARDUINO_AVR_NANO_EVERY -DARDUINO_ARCH_MEGAAVR -DMILLIS_USE_TIMERB3 -DNO_EXTERNAL_I2C_PULLUP "-IC:\\Users\\x\\AppData\\Local\\Arduino15\\packages\\arduino\\hardware\\megaavr\\1.8.8\\cores\\arduino/api/deprecated" "-IC:\\Users\\x\\AppData\\Local\\Arduino15\\packages\\arduino\\hardware\\megaavr\\1.8.8\\cores\\arduino" "-IC:\\Users\\x\\AppData\\Local\\Arduino15\\packages\\arduino\\hardware\\megaavr\\1.8.8\\variants\\nona4809" "-IC:\\Users\\x\\Documents\\Arduino\\libraries\\Adafruit_NeoPixel" "C:\\Users\\x\\AppData\\Local\\Temp\\arduino\\sketches\\34152714B6AC21BB4C92691033658340\\sketch\\KATRIN_LED_Modell_4_game.ino.cpp" -o "C:\\Users\\x\\AppData\\Local\\Temp\\arduino\\sketches\\34152714B6AC21BB4C92691033658340\\sketch\\KATRIN_LED_Modell_4_game.ino.cpp.o"
Bibliotheken werden kompiliert ...
Bibliothek "Adafruit NeoPixel" wird kompiliert
Zuvor kompilierte Datei wird verwendet: C:\Users\x\AppData\Local\Temp\arduino\sketches\34152714B6AC21BB4C92691033658340\libraries\Adafruit_NeoPixel\esp8266.c.o
Zuvor kompilierte Datei wird verwendet: C:\Users\x\AppData\Local\Temp\arduino\sketches\34152714B6AC21BB4C92691033658340\libraries\Adafruit_NeoPixel\kendyte_k210.c.o
Zuvor kompilierte Datei wird verwendet: C:\Users\x\AppData\Local\Temp\arduino\sketches\34152714B6AC21BB4C92691033658340\libraries\Adafruit_NeoPixel\esp.c.o
Zuvor kompilierte Datei wird verwendet: C:\Users\x\AppData\Local\Temp\arduino\sketches\34152714B6AC21BB4C92691033658340\libraries\Adafruit_NeoPixel\Adafruit_NeoPixel.cpp.o
Kern wird kompiliert ...
Zuvor kompilierte Datei wird verwendet: C:\Users\x\AppData\Local\Temp\arduino\sketches\34152714B6AC21BB4C92691033658340\core\variant.c.o
Using precompiled core: C:\Users\x\AppData\Local\Temp\arduino\cores\arduino_megaavr_nona4809_mode_off_511d907636b8ca1cb6392dab3b59f92a\core.a
Linking everything together...
"C:\\Users\\x\\AppData\\Local\\Arduino15\\packages\\arduino\\tools\\avr-gcc\\7.3.0-atmel3.6.1-arduino5/bin/avr-gcc" -Wall -Wextra -Os -g -flto -fuse-linker-plugin -Wl,--gc-sections -Wl,--section-start=.text=0x0 -mmcu=atmega4809 -o "C:\\Users\\x\\AppData\\Local\\Temp\\arduino\\sketches\\34152714B6AC21BB4C92691033658340/KATRIN_LED_Modell_4_game.ino.elf" "C:\\Users\\x\\AppData\\Local\\Temp\\arduino\\sketches\\34152714B6AC21BB4C92691033658340\\sketch\\KATRIN_LED_Modell_4_game.ino.cpp.o" "C:\\Users\\x\\AppData\\Local\\Temp\\arduino\\sketches\\34152714B6AC21BB4C92691033658340\\libraries\\Adafruit_NeoPixel\\Adafruit_NeoPixel.cpp.o" "C:\\Users\\x\\AppData\\Local\\Temp\\arduino\\sketches\\34152714B6AC21BB4C92691033658340\\libraries\\Adafruit_NeoPixel\\esp.c.o" "C:\\Users\\x\\AppData\\Local\\Temp\\arduino\\sketches\\34152714B6AC21BB4C92691033658340\\libraries\\Adafruit_NeoPixel\\esp8266.c.o" "C:\\Users\\x\\AppData\\Local\\Temp\\arduino\\sketches\\34152714B6AC21BB4C92691033658340\\libraries\\Adafruit_NeoPixel\\kendyte_k210.c.o" "C:\\Users\\x\\AppData\\Local\\Temp\\arduino\\sketches\\34152714B6AC21BB4C92691033658340\\core\\variant.c.o" "C:\\Users\\x\\AppData\\Local\\Temp\\arduino\\sketches\\34152714B6AC21BB4C92691033658340/..\\..\\cores\\arduino_megaavr_nona4809_mode_off_511d907636b8ca1cb6392dab3b59f92a\\core.a" "-LC:\\Users\\x\\AppData\\Local\\Temp\\arduino\\sketches\\34152714B6AC21BB4C92691033658340" -lm "-Wl,-Map,C:\\Users\\x\\AppData\\Local\\Temp\\arduino\\sketches\\34152714B6AC21BB4C92691033658340/KATRIN_LED_Modell_4_game.ino.map"
"C:\\Users\\x\\AppData\\Local\\Arduino15\\packages\\arduino\\tools\\avr-gcc\\7.3.0-atmel3.6.1-arduino5/bin/avr-objcopy" -O binary -R .eeprom "C:\\Users\\x\\AppData\\Local\\Temp\\arduino\\sketches\\34152714B6AC21BB4C92691033658340/KATRIN_LED_Modell_4_game.ino.elf" "C:\\Users\\x\\AppData\\Local\\Temp\\arduino\\sketches\\34152714B6AC21BB4C92691033658340/KATRIN_LED_Modell_4_game.ino.bin"
"C:\\Users\\x\\AppData\\Local\\Arduino15\\packages\\arduino\\tools\\avr-gcc\\7.3.0-atmel3.6.1-arduino5/bin/avr-objcopy" -O ihex -j .eeprom --set-section-flags=.eeprom=alloc,load --no-change-warnings --change-section-lma .eeprom=0 "C:\\Users\\x\\AppData\\Local\\Temp\\arduino\\sketches\\34152714B6AC21BB4C92691033658340/KATRIN_LED_Modell_4_game.ino.elf" "C:\\Users\\x\\AppData\\Local\\Temp\\arduino\\sketches\\34152714B6AC21BB4C92691033658340/KATRIN_LED_Modell_4_game.ino.eep"
"C:\\Users\\x\\AppData\\Local\\Arduino15\\packages\\arduino\\tools\\avr-gcc\\7.3.0-atmel3.6.1-arduino5/bin/avr-objcopy" -O ihex -R .eeprom "C:\\Users\\x\\AppData\\Local\\Temp\\arduino\\sketches\\34152714B6AC21BB4C92691033658340/KATRIN_LED_Modell_4_game.ino.elf" "C:\\Users\\x\\AppData\\Local\\Temp\\arduino\\sketches\\34152714B6AC21BB4C92691033658340/KATRIN_LED_Modell_4_game.ino.hex"
Bibliothek Adafruit NeoPixel in Version 1.12.3 im Ordner: C:\Users\x\Documents\Arduino\libraries\Adafruit_NeoPixel wird verwendet
"C:\\Users\\x\\AppData\\Local\\Arduino15\\packages\\arduino\\tools\\avr-gcc\\7.3.0-atmel3.6.1-arduino5/bin/avr-size" -A "C:\\Users\\x\\AppData\\Local\\Temp\\arduino\\sketches\\34152714B6AC21BB4C92691033658340/KATRIN_LED_Modell_4_game.ino.elf"
Der Sketch verwendet 11754 Bytes (23%) des Programmspeicherplatzes. Das Maximum sind 49152 Bytes.
Globale Variablen verwenden 1405 Bytes (22%) des dynamischen Speichers, 4739 Bytes für lokale Variablen verbleiben. Das Maximum sind 6144 Bytes.
Performing 1200-bps touch reset on serial port COM11
"C:\Users\x\AppData\Local\Arduino15\packages\arduino\tools\avrdude\6.3.0-arduino17/bin/avrdude" "-CC:\Users\x\AppData\Local\Arduino15\packages\arduino\tools\avrdude\6.3.0-arduino17/etc/avrdude.conf" -v -V -patmega4809 -cjtag2updi -PCOM11 -b115200 -e -D "-Uflash:w:C:\Users\x\AppData\Local\Temp\arduino\sketches\34152714B6AC21BB4C92691033658340/KATRIN_LED_Modell_4_game.ino.hex:i" "-Ufuse2:w:0x01:m" "-Ufuse5:w:0xC9:m" "-Ufuse8:w:0x00:m" {upload.extra_files}
avrdude: Version 6.3-20190619
Copyright (c) 2000-2005 Brian Dean, http://www.bdmicro.com/
Copyright (c) 2007-2014 Joerg Wunsch
System wide configuration file is "C:\Users\x\AppData\Local\Arduino15\packages\arduino\tools\avrdude\6.3.0-arduino17/etc/avrdude.conf"
Using Port : COM11
Using Programmer : jtag2updi
Overriding Baud Rate : 115200
JTAG ICE mkII sign-on message:
Communications protocol version: 1
M_MCU:
boot-loader FW version: 1
firmware version: 1.07
hardware version: 1
S_MCU:
boot-loader FW version: 1
firmware version: 6.07
hardware version: 1
Serial number: 00:00:00:00:00:00
Device ID: JTAGICE mkII
AVR Part : ATmega4809
Chip Erase delay : 0 us
PAGEL : P00
BS2 : P00
RESET disposition : dedicated
RETRY pulse : SCK
serial program mode : yes
parallel program mode : yes
Timeout : 0
StabDelay : 0
CmdexeDelay : 0
SyncLoops : 0
ByteDelay : 0
PollIndex : 0
PollValue : 0x00
Memory Detail :
Block Poll Page Polled
Memory Type Mode Delay Size Indx Paged Size Size #Pages MinW MaxW ReadBack
----------- ---- ----- ----- ---- ------ ------ ---- ------ ----- ----- ---------
signature 0 0 0 0 no 3 0 0 0 0 0x00 0x00
prodsig 0 0 0 0 no 61 61 0 0 0 0x00 0x00
fuses 0 0 0 0 no 9 0 0 0 0 0x00 0x00
fuse0 0 0 0 0 no 1 0 0 0 0 0x00 0x00
fuse1 0 0 0 0 no 1 0 0 0 0 0x00 0x00
fuse2 0 0 0 0 no 1 0 0 0 0 0x00 0x00
fuse4 0 0 0 0 no 1 0 0 0 0 0x00 0x00
fuse5 0 0 0 0 no 1 0 0 0 0 0x00 0x00
fuse6 0 0 0 0 no 1 0 0 0 0 0x00 0x00
fuse7 0 0 0 0 no 1 0 0 0 0 0x00 0x00
fuse8 0 0 0 0 no 1 0 0 0 0 0x00 0x00
lock 0 0 0 0 no 1 0 0 0 0 0x00 0x00
data 0 0 0 0 no 0 0 0 0 0 0x00 0x00
usersig 0 0 0 0 no 64 64 0 0 0 0x00 0x00
flash 0 0 0 0 no 49152 128 0 0 0 0x00 0x00
eeprom 0 0 0 0 no 256 64 0 0 0 0x00 0x00
Programmer Type : JTAGMKII_PDI
Description : JTAGv2 to UPDI bridge
M_MCU hardware version: 1
M_MCU firmware version: 1.07
S_MCU hardware version: 1
S_MCU firmware version: 6.07
Serial number: 00:00:00:00:00:00
Vtarget : 5.0 V
avrdude: jtagmkII_initialize(): Cannot locate "flash" and "boot" memories in description
avrdude: AVR device initialized and ready to accept instructions
Reading | ################################################## | 100% 0.27s
avrdude: Device signature = 0x1e9651 (probably m4809)
avrdude: erasing chip
avrdude: reading input file "C:\Users\x\AppData\Local\Temp\arduino\sketches\34152714B6AC21BB4C92691033658340/KATRIN_LED_Modell_4_game.ino.hex"
avrdude: writing flash (11754 bytes):
Writing | ################################################## | 100% 8.60s
avrdude: 11754 bytes of flash written
avrdude: reading input file "0x01"
avrdude: writing fuse2 (1 bytes):
Writing | ################################################## | 100% 0.00s
avrdude: 1 bytes of fuse2 written
avrdude: reading input file "0xC9"
avrdude: writing fuse5 (1 bytes):
Writing | ################################################## | 100% 0.00s
avrdude: 1 bytes of fuse5 written
avrdude: reading input file "0x00"
avrdude: writing fuse8 (1 bytes):
Writing | ################################################## | 100% 0.00s
avrdude: 1 bytes of fuse8 written
avrdude done. Thank you.
Can the nano every use compression? Because I have a lot of zeros and repeating stuff in my arrays?
compression? No.
Your code, my Every:
Sketch uses 11754 bytes (23%) of program storage space. Maximum is 49152 bytes.
Global variables use 1405 bytes (22%) of dynamic memory, leaving 4739 bytes for local variables. Maximum is 6144 bytes.
I have no idea where you got this:
Oh, I meant bytes, not kB. I just compiled it for each board. Strange that there is such a big difference.