Detecting board from sketch

Is it possible to detect board type by code from induistruino / protoduino.
So that it becomes possible to write code that works on all versions
(assigning pin layout in setup phase depending on board type.)
 

Peter
Peter
7
| 2 1 1
Asked on 10/23/17, 6:22 AM
0
vote
1769 Views

Hi Peter,

Below code runs on all 3 platforms (D21G, 32u4, 1286) and detects the architecture: AVR or SAMD.

Still, during upload you need to select the correct type of platform.

 

#if defined(ARDUINO_ARCH_AVR) || defined(__AVR__)
boolean D21G = false;
#define SER_USB Serial
#elif defined(ARDUINO_ARCH_SAMD)
boolean D21G = true;
#define SER_USB SerialUSB
#endif

void setup() {
  // put your setup code here, to run once:

  SER_USB.begin(9600);
  while (!SER_USB);

  if (!D21G) {
    SER_USB.println("AVR board");
  }
  if (D21G) {
    SER_USB.println("SAMD board");
  }
}

void loop() {
  // put your main code here, to run repeatedly:

}

Tom
Tom
5675
| 1 1 3
Answered on 10/25/17, 12:49 AM
0
vote

Your answer

Please try to give a substantial answer. If you wanted to comment on the question or answer, just use the commenting tool. Please remember that you can always revise your answers - no need to answer the same question twice. Also, please don't forget to vote - it really helps to select the best questions and answers!

Ask a Question

Keep Informed

About This Forum

This community is for professionals and enthusiasts of our products and services.

Read Guidelines

Question tools

41 follower(s)

Stats

Asked: 10/23/17, 6:22 AM
Seen: 1769 times
Last updated: 10/25/17, 12:49 AM