Go Down

Topic: A way to identify Leonardo or Teensy in a program? (Read 2 times) previous topic - next topic


There needs to be a way to identify a board in a program.  For example the Leonardo and Teensy use the ATmega32U4 but having different pin mappings.

I am writing bit-bang libraries for SPI and I2C that require fast digital I/O so I can't use the standard digitalRead/digitalWrite.  I need to know the pin map at compile time to implement fast I/O but the processor type macro no longer is adequate.

Boards like the Teensy and Leonardo will have other special features that need to be distinguished so it would be helpful for a macro to identify the board, not just the processor.


There are already some #defines for board type but IIRC only for Mega/non-Mega, maybe they should be extended.

Rob Gray aka the GRAYnomad www.robgray.com

Paul Stoffregen

Ideally the IDE should define a symbol that tells you the target/core/variant which is selected from the Tools > Boards menu.  That's not a new idea... but it's never gone anywhere.  I'm pretty sure it's in the issue tracker, but I'm not going to go look up the issue number right now.

For an immediate solution, after you include Arduino.h or WProgram.h, you can check for CORE_TEENSY to determine if a Teensy board is in use.  For example:

Code: [Select]

#ifdef __AVR_ATmega32U4__
  // it's Teensy 2.0
  // it's probably Leonardo

Hopefully the IDE will someday provide more descriptive info about which board, or target/core/variant, or platform/target/core/variant, or whatever future schema combination, is in use.


How are the signature bytes read? AVRdude does it, comes out with that "Yikes! Wrong signature" error message:

"All Atmel microcontrollers have a three-byte signature code which identifies the device. This
code can be read in both serial and parallel mode, also when the device is locked. The three
bytes reside in a separate address space."
Designing & building electrical circuits for over 25 years. Check out the ATMega1284P based Bobuino and other '328P & '1284P creations & offerings at  www.crossroadsfencing.com/BobuinoRev17.
Arduino for Teens available at Amazon.com.


Thats doesn't tell you the board though, just the chip.

Rob Gray aka the GRAYnomad www.robgray.com

Go Up