DEFINE for ZERO

Hello,

Does anyone know if there are DEFINEs that can be used to determine if a ZERO was programmed using the native port or the programming port?

Like

ifdef AVR_ATmega328P

Serial.println ("This is an ATmega328p");

endif

Only for the ZERO

Oldmicroguy

From one 'Old' to another, there are a couple of suggestions here:- Zero #define Unfortunately, he didn't return to say what, if anything, worked. :(

The only other option is to start digging through the core and try to find where it might be defined. I would start with io.h since it has tests for most of the chips.

You probably won't find one that says "ZERO", it's probably going to say something related to the name of the chip that is on the Zero.

OldMicroGuy: Hello,

Does anyone know if there are DEFINEs that can be used to determine if a ZERO was programmed using the native port or the programming port?

Like

ifdef AVR_ATmega328P

Serial.println ("This is an ATmega328p");

endif

Only for the ZERO

Oldmicroguy

????

ifdef ZERO

Serial.println ("ZERO is defined ");

endif

Hello,

My problem is not to determine if the board is a ZERO but rather if is running using native port or programming port because Serial printing is different.

I would like to write a program that would run if either is running:

if native port SerialUSB.print("Hello World"); endif

if programming port Serial.print("Hello World"); endif

Oldmicroguy

Are we mixing up compile time decision and run time decisions?

As you have to set the compiler for the correct board/chip the choice of which code to run is a compile-time decision. Setting the board/chip sets some mystical defines which you can use to deine your own. I have this once where I needed some code that run on either my "big" Arduino or the nano and trial-error I got to

#ifdef __AVR_ATmega32U4__
#define LEO
#endif

That is, my code in the few places where the Serial code neded to be sensitive to which oar it ran on I did something like (not exactly that but using your examples)

#ifdef LEO
 SerialUSB.print("Hello World");
#else
Serial.print("Hello World");
#endif

And your code will be filled with little ifdef variations. You may choose to make your own function that decides, but this adds another call/return overhead at runtime.

Now if the two boards use the same identical code, ie you have the same IDE settings when you hit "upload", then indeed the decision is at runtime. But y*ou need to sense it at runtime*. I had a similar problem, and I said that pin3 was wired to GND on the one board and to 5V on the other board. The code then was

if (digitalRead(3)==LOW)  SerialUSB.print("Hello World");
    else /* implied digialRead(3)==HIGH*/  Serial.print("Hello World");