I've got some code that was developed for nano, but, having overrun RAM I want to modify one of my own libraries to work with standard nano & nano every. So, at compile time I want to know my target board &/or target processor. I assume it's some sort of #define, but haven't yet found it. I'm hoping someone out there has the answer to this at his/her fingertips. Would someone point me in the right direction, please?
if this compiles
#ifdef ARDUINO_AVR_NANO_EVERY
volatile int t[100];
#endif
void setup() {
Serial.begin(115200); Serial.println();
for (int x = 0; x < 100; x++) t[x] = random(x);
}
void loop() {
for (int x = 0; x < 100; x++) Serial.println(t[x]);
}
then you can use ARDUINO_AVR_NANO_EVERY in an #ifdef
(one way to look at what's defined for a platform is to compile an empty sketch and look at the detailed compilation log for the -D options for example compiling for the Nano Every I saw
-DF_CPU=16000000L -DARDUINO=10819 -DARDUINO_AVR_NANO_EVERY -DARDUINO_ARCH_MEGAAVR -DAVR_NANO_4809_328MODE -DMILLIS_USE_TIMERB3 -DNO_EXTERNAL_I2C_PULLUP
that's how I guessed ARDUINO_AVR_NANO_EVERY could be a good option)
By including the crucial "ARDUINO_AVR_NANO_EVERY" you have actually provided the answer I was after. Much appreciated.
However, you have exposed another gap in my my understanding. I can happily build an empty sketch ...
setup(){} void loop(){}
and that compiles just fine. You then advise " ... and look at the detailed compilation log for the -D options".
That's where I have come a cropper!
I'm sure that's a clear instruction, but I'm afraid I haven't yet figured out how to achieve that.
I tried File | Preferences & clicked the "show verbose output during compile" box, but that didn't crack it. I'm using Arduino IDE 2.1.1. I have tried looking through all the main menu items & can't really spot another contender.
That's how I do it in IDE 1.8.19. If that is a problem in IDE 2.x, you could install the portable IDE 1.8.9 to see the defines. The portable installation does not interfere with your 2.1.1
I did it in 1.8.19 indeed
This is the beginning of the verbose output in IDE 2.1.1
FQBN: arduino:megaavr:nona4809:mode=off
Using board 'nona4809' from platform in folder: C:\Users\Wim\AppData\Local\Arduino15\packages\arduino\hardware\megaavr\1.8.8
Using core 'arduino' from platform in folder: C:\Users\Wim\AppData\Local\Arduino15\packages\arduino\hardware\megaavr\1.8.8
Detecting libraries used...
"C:\\Users\\Wim\\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\\Wim\\AppData\\Local\\Arduino15\\packages\\arduino\\hardware\\megaavr\\1.8.8\\cores\\arduino/api/deprecated" "-IC:\\Users\\Wim\\AppData\\Local\\Arduino15\\packages\\arduino\\hardware\\megaavr\\1.8.8\\cores\\arduino" "-IC:\\Users\\Wim\\AppData\\Local\\Arduino15\\packages\\arduino\\hardware\\megaavr\\1.8.8\\variants\\nona4809" "C:\\Users\\Wim\\AppData\\Local\\Temp\\arduino\\sketches\\6FAED814952AC00D1F0C851D7BEE2699\\sketch\\sketch_aug19a.ino.cpp" -o nul
Start looking from character at position 295 on the last line above.
A lesson learned in early Arduino development is that using specific symbols like ARDUINO_AVR_NANO_EVERY or even AVR_ATmega4809 (which would at least get Uno Wifi 2), you should look for symbols specifically associated with what you are trying to do, like:
#if INTERNAL_SRAM_SIZE > 4096 /* Lots of RAM? */
...
#if defined(VPORTA) /* Virtual Ports? */
...
#if defined(TCB0) /* Type B timer ? */
This is more likely to give you compatibility with other boards, or other processors with similar peripherals (though you'll still have to be careful.)
(First noticed in some code that used to check for ATmega168, ATmega88, ATmega328, ATmega328p, etc..., when they were all the same...)
Good point @westfw, and I agree with you totally. My predicament was getting off first base. I arrived at my situation when the 2k of RAM just wouldn’t hack the problem. At that stage I hadn’t even realised the 4809 didn’t provide pin change interrupt and it was a bridge too far to turn my library into something much more general purpose. Hitherto, I had only been bumbling around the vanilla nano, the every delivered the headroom I needed, and an area that had appeared solid fell over at compile time. Recognising the every was my first venture “under the hood”, so the first steer from @J-M-L (I think) took me to a quick fix, and I was away. Opening up the bag of worms that is the whole raft of possible flavours of Arduino is not a zone I’m that keen to venture into. If there’s a document out there that captures the list of possible pre-processor definitions I think I might embrace that. But I was at the stage I had only just learned how to enable verbose compilation diagnostics, let alone trying to understand what the often cryptic keywords meant, or where to find them in the forest of now feedback.
Incidentally, a new problem I didn’t see coming was that I have been using the 1.1 volt internal reference of the basic (328) nano. Giving the same source code for the (4809) nano every to eat appears to set the ADC reference voltage to about 700mV. Another area of my code that I’m not working on right now, but needs a bit of attention as a consequence of me moving from the Atmega328P processor to the Atmega4809 … I think!
This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.