├── ArduinoBoardManager.cpp
├── ArduinoBoardManager.h
├── README.md
└── examples
└── featuresniffer
└── featuresniffer.ino
/ArduinoBoardManager.cpp:
--------------------------------------------------------------------------------
1 | /*-------------------------------------------------------------------------
2 | Arduino library to determine the Arduino models and features,
3 | as well as the SDK version.
4 |
5 | Most features can be accessed via static variables.
6 | You must instantiate if you want to know if the name of the board
7 | or if specific features such exist, for example multiple serial
8 | connections on the Arduino Mega.
9 |
10 | This list may be neither comprehensive nor up to date
11 |
12 | A full list of boards and processor names are available on Wikipedia:
13 | https://en.wikipedia.org/wiki/List_of_Arduino_boards_and_compatible_systems
14 |
15 | @author Tony Gaitatzis backupbrain@gmail.com
16 | @date 2015-12-10
17 |
18 | -------------------------------------------------------------------------
19 | This file is part of the Arduino Board Manager library
20 |
21 | NeoPixel is free software: you can redistribute it and/or modify
22 | it under the terms of the GNU Lesser General Public License as
23 | published by the Free Software Foundation, either version 3 of
24 | the License, or (at your option) any later version.
25 |
26 | NeoPixel is distributed in the hope that it will be useful,
27 | but WITHOUT ANY WARRANTY; without even the implied warranty of
28 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
29 | GNU Lesser General Public License for more details.
30 |
31 | You should have received a copy of the GNU Lesser General Public
32 | License along with NeoPixel. If not, see
33 | .
34 | -------------------------------------------------------------------------*/
35 |
36 | #include "ArduinoBoardManager.h"
37 |
38 | ArduinoBoardManager::ArduinoBoardManager() {
39 | // clear the features
40 | memset(FEATURES, false, NUM_FEATURES);
41 |
42 |
43 |
44 | static const unsigned long BOARD_UNKNOWN = 0x0;
45 | static const unsigned long BOARD_UNO = 0x01;
46 | static const unsigned long BOARD_ZERO = 0x02;
47 | static const unsigned long BOARD_DUE = 0x03;
48 | static const unsigned long BOARD_MICRO= 0x04;
49 | static const unsigned long BOARD_YUN_400 = 0x05;
50 | static const unsigned long BOARD_LEONARDO = 0x06;
51 | static const unsigned long BOARD_MEGA = 0x07;
52 | static const unsigned long BOARD_NANO = 0x08;
53 | static const unsigned long BOARD_NANO_3 = 0x09;
54 | static const unsigned long BOARD_LILYPAD = 0x08;
55 | static const unsigned long BOARD_TRINKET = 0x09;
56 |
57 |
58 | switch (ArduinoBoardManager::BOARD) {
59 | case ArduinoBoardManager::BOARD_UNO:
60 | strcpy(BOARD_NAME, "UNO");
61 | strcpy(CPU_NAME, "ATmega328P");
62 | break;
63 | case ArduinoBoardManager::BOARD_ZERO:
64 | strcpy(BOARD_NAME, "Zero");
65 | strcpy(CPU_NAME, "ATSAMD21G18A");
66 | FEATURES[ArduinoBoardManager::FEATURE_ANALOG_OUT] = true;
67 | break;
68 | case ArduinoBoardManager::BOARD_DUE:
69 | strcpy(BOARD_NAME, "Due");
70 | strcpy(CPU_NAME, "ATSAM3X8E");
71 | FEATURES[ArduinoBoardManager::FEATURE_ANALOG_OUT] = true;
72 | break;
73 | case ArduinoBoardManager::BOARD_MICRO:
74 | strcpy(BOARD_NAME, "Micro");
75 | strcpy(CPU_NAME, "Atmega32U4");
76 | break;
77 | case ArduinoBoardManager::BOARD_YUN_400:
78 | strcpy(BOARD_NAME, "Yun");
79 | strcpy(CPU_NAME, "AR9331");
80 | break;
81 | case ArduinoBoardManager::BOARD_LEONARDO:
82 | strcpy(BOARD_NAME, "Leonardo");
83 | strcpy(CPU_NAME, "ATmega16U4");
84 | break;
85 | case ArduinoBoardManager::BOARD_MEGA:
86 | strcpy(BOARD_NAME, "Mega");
87 | strcpy(CPU_NAME, "ATmega1280");
88 | FEATURES[ArduinoBoardManager::FEATURE_MULTIPLE_SERIAL] = true;
89 | break;
90 | case ArduinoBoardManager::BOARD_NANO:
91 | strcpy(BOARD_NAME, "Nano");
92 | strcpy(CPU_NAME, "ATmega168");
93 | break;
94 | case ArduinoBoardManager::BOARD_NANO_3:
95 | strcpy(BOARD_NAME, "Nano");
96 | strcpy(CPU_NAME, "ATmega328");
97 | break;
98 | case ArduinoBoardManager::BOARD_LILYPAD:
99 | strcpy(BOARD_NAME, "Lilypad");
100 | strcpy(CPU_NAME, "ATmega168V");
101 | break;
102 | case ArduinoBoardManager::BOARD_LILYPAD_2:
103 | strcpy(BOARD_NAME, "Lilypad");
104 | strcpy(CPU_NAME, "ATmega328V");
105 | break;
106 | case ArduinoBoardManager::BOARD_TRINKET:
107 | strcpy(BOARD_NAME, "Trinket");
108 | strcpy(CPU_NAME, "ATTiny85");
109 | break;
110 | case ArduinoBoardManager::BOARD_101:
111 | strcpy(BOARD_NAME, "101");
112 | strcpy(CPU_NAME, "ARCv2EM");
113 | FEATURES[ArduinoBoardManager::FEATURE_BLUETOOTH_4] = true;
114 | FEATURES[ArduinoBoardManager::FEATURE_ACCELEROMETER] = true;
115 | FEATURES[ArduinoBoardManager::FEATURE_GYROSCOPE] = true;
116 | break;
117 | default:
118 | strcpy(BOARD_NAME, "Unknown");
119 | strcpy(CPU_NAME, "Unknown");
120 |
121 | }
122 |
123 | }
124 |
125 |
126 | bool ArduinoBoardManager::featureExists(uint8_t feature) {
127 | if ((feature < ArduinoBoardManager::NUM_FEATURES) &&
128 | (ArduinoBoardManager::FEATURES[feature]))
129 | return true;
130 | return false;
131 | }
132 |
133 |
--------------------------------------------------------------------------------
/ArduinoBoardManager.h:
--------------------------------------------------------------------------------
1 | /*-------------------------------------------------------------------------
2 | Arduino library to determine the Arduino models and features,
3 | as well as the SDK version.
4 |
5 | Most features can be accessed via static variables.
6 | You must instantiate if you want to know if the name of the board
7 | or if specific features such exist, for example multiple serial
8 | connections on the Arduino Mega.
9 |
10 | This list may be neither comprehensive nor up to date
11 |
12 | A full list of boards and processor names are available on Wikipedia:
13 | https://en.wikipedia.org/wiki/List_of_Arduino_boards_and_compatible_systems
14 |
15 | @author Tony Gaitatzis backupbrain@gmail.com
16 | @date 2015-12-10
17 |
18 | -------------------------------------------------------------------------
19 | This file is part of the Arduino Board Manager library
20 |
21 | NeoPixel is free software: you can redistribute it and/or modify
22 | it under the terms of the GNU Lesser General Public License as
23 | published by the Free Software Foundation, either version 3 of
24 | the License, or (at your option) any later version.
25 |
26 | NeoPixel is distributed in the hope that it will be useful,
27 | but WITHOUT ANY WARRANTY; without even the implied warranty of
28 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
29 | GNU Lesser General Public License for more details.
30 |
31 | You should have received a copy of the GNU Lesser General Public
32 | License along with NeoPixel. If not, see
33 | .
34 | -------------------------------------------------------------------------*/
35 |
36 | #if ARDUINO >= 100
37 | #include
38 | #else
39 | #include
40 | #endif
41 |
42 | class ArduinoBoardManager {
43 | public:
44 | /**
45 | * Arduino IDE/SDK Version
46 | */
47 | static const uint16_t SDK_VERSION = ARDUINO; /**< Arduino SDK Version */
48 |
49 | /**
50 | * Board Name
51 | */
52 | static const uint8_t MAX_BOARD_NAME_LENGTH = 16;
53 | static const uint8_t MAX_CPU_NAME_LENGTH = 16;
54 | char BOARD_NAME[MAX_BOARD_NAME_LENGTH]; /**< When instantiated, this is the board name, eg "UNO" */
55 | char CPU_NAME[MAX_CPU_NAME_LENGTH]; /**< When instantiated, this is the cpu name, eg "__AVR_ATmega328P__" */
56 |
57 | /**
58 | * Known Board Models
59 | */
60 | static const uint8_t BOARD_UNKNOWN = 0x0;
61 | static const uint8_t BOARD_UNO = 0x01;
62 | static const uint8_t BOARD_ZERO = 0x02;
63 | static const uint8_t BOARD_DUE = 0x03;
64 | static const uint8_t BOARD_MICRO= 0x04;
65 | static const uint8_t BOARD_YUN_400 = 0x05;
66 | static const uint8_t BOARD_LEONARDO = 0x06;
67 | static const uint8_t BOARD_MEGA = 0x07;
68 | static const uint8_t BOARD_NANO = 0x08;
69 | static const uint8_t BOARD_NANO_3 = 0x09;
70 | static const uint8_t BOARD_LILYPAD = 0x0a;
71 | static const uint8_t BOARD_LILYPAD_2 = 0x0b;
72 | static const uint8_t BOARD_TRINKET = 0x0c;
73 | static const uint8_t BOARD_101 = 0x0d;
74 |
75 | /**
76 | * Known Arduino Features
77 | */
78 | static const uint8_t NUM_FEATURES = 1;
79 | static const uint8_t FEATURE_MULTIPLE_SERIAL = 0x00;
80 | static const uint8_t FEATURE_BLUETOOTH_4 = 0x01;
81 | static const uint8_t FEATURE_ACCELEROMETER = 0x02;
82 | static const uint8_t FEATURE_GYROSCOPE = 0x03;
83 | static const uint8_t FEATURE_ANALOG_OUT = 0x04;
84 |
85 | /**
86 | * CPU speed
87 | */
88 | static const unsigned long MAX_MHZ = F_CPU;
89 |
90 | boolean FEATURES[NUM_FEATURES];
91 |
92 | /**
93 | * CPU Specifications
94 | */
95 | #if defined(__AVR_ATmega328P__) // uno, fio
96 | static const uint8_t BOARD = 0x01; /**< UNO board */
97 | static const uint8_t NUM_BITS = 8; /**< 8-bit processor */
98 | static const uint16_t CPU = __AVR_ATmega328P__; /**< 16Mhz */
99 | static const unsigned long SRAM_SIZE = 2000; /**< 2kb of sram */
100 | static const unsigned long EEPROM_SIZE = 1000; /**< 1kb eeprom */
101 | static const unsigned long FLASH_SIZE = 32000; /**< 32k flash storage */
102 | #elif defined(__AVR_ATSAMD21G18A__) // zero
103 | static const uint8_t BOARD = 0x02
104 | static const uint8_t NUM_BITS = 8;
105 | static const uint16_t CPU = __AVR_ATSAMD21G18A__;
106 | static const unsigned long SRAM_SIZE = 32000;
107 | static const unsigned long EEPROM_SIZE = 16000;
108 | static const unsigned long FLASH_SIZE = 256000;
109 | #elif defined(__AVR_ATSAM3X8E__) // Due
110 | static const uint8_t BOARD = 0x03;
111 | static const uint8_t NUM_BITS = 8;
112 | static const uint16_t CPU = __AVR_ATSAMD21G18A__;
113 | static const unsigned long SRAM_SIZE = 96000;
114 | static const unsigned long EEPROM_SIZE = 0;
115 | static const unsigned long FLASH_SIZE = 512000;
116 | #elif defined(__AVR_Atmega32U4__) // Yun 16Mhz, Micro, Leonardo, Esplora
117 | static const uint8_t BOARD = 0x04;
118 | static const uint8_t NUM_BITS = 8;
119 | static const uint16_t CPU = __AVR_Atmega32U4__;
120 | static const unsigned long SRAM_SIZE = 2500;
121 | static const unsigned long EEPROM_SIZE = 1000;
122 | static const unsigned long FLASH_SIZE = 32000;
123 | #elif defined(_AVR_AR9331__) // Yun 400Mhz
124 | static const uint8_t BOARD = 0x05;
125 | static const uint8_t NUM_BITS = 8;
126 | static const uint16_t CPU = _AVR_AR9331__;
127 | static const unsigned long SRAM_SIZE = 64000000;
128 | static const unsigned long EEPROM_SIZE = 0;
129 | static const unsigned long FLASH_SIZE = 16000000;
130 | #elif defined(__AVR_ATmega16U4__) // leonardo
131 | static const uint8_t BOARD = 0x06;
132 | static const uint8_t NUM_BITS = 8;
133 | static const uint16_t CPU = __AVR_ATmega16U4__;
134 | static const unsigned long SRAM_SIZE = 2560;
135 | static const unsigned long EEPROM_SIZE = 1000;
136 | static const unsigned long FLASH_SIZE = 32000;
137 | #elif defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__) // mega, Mega ADK
138 | static const uint8_t BOARD = 0x07;
139 | static const uint8_t NUM_BITS = 8;
140 | static const uint16_t CPU = __AVR_ATmega1280__;
141 | static const unsigned long SRAM_SIZE = 8000;
142 | static const unsigned long EEPROM_SIZE = 4000;
143 | static const unsigned long FLASH_SIZE = 256000;
144 | #elif defined(_AVR_ATmega328__) // Nano >= v3.0 or Arduino Pro, pro328, ethernet
145 | static const uint8_t BOARD = 0x08;
146 | static const uint8_t NUM_BITS = 8;
147 | static const uint16_t CPU = _AVR_ATmega328__;
148 | static const unsigned long SRAM_SIZE = 2000;
149 | static const unsigned long EEPROM_SIZE = 1000;
150 | static const unsigned long FLASH_SIZE = 32000;
151 | #elif defined(_AVR_ATmega168__) // Nano < v3.0 or uno, pro
152 | static const uint8_t BOARD = 0x09;
153 | static const uint8_t NUM_BITS = 8;
154 | static const uint16_t CPU = _AVR_ATmega168;
155 | static const unsigned long SRAM_SIZE = 1000;
156 | static const unsigned long EEPROM_SIZE = 500;
157 | static const unsigned long FLASH_SIZE = 16000;
158 | #elif defined(_AVR_ATmega168V__) // LilyPad
159 | static const uint8_t BOARD = 0x0a;
160 | static const uint8_t CPU = _AVR_ATmega168V__;
161 | static const unsigned int NUM_BITS = 8;
162 | static const unsigned long SRAM_SIZE = 1000;
163 | static const unsigned long EEPROM_SIZE = 500;
164 | static const unsigned long FLASH_SIZE = 14000
165 | #elif defined(_AVR_ATmega328V__) // LilyPad 2
166 | static const uint8_t BOARD = 0x0b;
167 | static const uint8_t CPU = _AVR_ATmega328V__;
168 | static const unsigned int NUM_BITS = 8;
169 | static const unsigned long SRAM_SIZE = 1000;
170 | static const unsigned long EEPROM_SIZE = 500;
171 | static const unsigned long FLASH_SIZE = 14000
172 | #elif defined(_AVR_ATTiny85__) // trinket
173 | static const uint8_t BOARD = 0x0c;
174 | static const uint8_t NUM_BITS = 8;
175 | static const uint16_t CPU = _AVR_ATTiny85__;
176 | static const unsigned long SRAM_SIZE = 500;
177 | static const unsigned long EEPROM_SIZE = 500;
178 | static const unsigned long FLASH_SIZE = 2500;
179 | #elif defined(__AVR_ARCv2EM__) || (__CURIE_FACTORY_DATA_H_) // Intel Curie/101
180 | static const uint8_t BOARD = 0x0d;
181 | static const uint8_t NUM_BITS = 32;
182 | static const uint16_t CPU = __AVR_ARCv2EM__;
183 | static const unsigned long SRAM_SIZE = 24000; // might be 80k?
184 | static const unsigned long EEPROM_SIZE = 0;
185 | static const unsigned long FLASH_SIZE = 384000;
186 | #else
187 | static const uint8_t BOARD = 0x00;
188 | static const uint8_t NUM_BITS = 0;
189 | static const uint16_t CPU = 0;
190 | static const unsigned long SRAM_SIZE = 0;
191 | static const unsigned long EEPROM_SIZE = 0;
192 | static const unsigned long FLASH_SIZE = 0;
193 | #endif
194 |
195 | /**
196 | * Instantiate board Manager
197 | */
198 | ArduinoBoardManager();
199 |
200 | /**
201 | * Ask if a specific feature exists, e.g. Arduino::FEATURE_MULTIPLE_SERIAL
202 | *
203 | * @param feature an unsigned int, e.g. FEATURE_MULTIPLE_SERIAL
204 | * @return true if feature exists, false if feature does not exist
205 | */
206 | bool featureExists(uint8_t feature);
207 |
208 | };
209 |
210 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # ArduinoBoardManager
2 |
3 |
4 | Arduino library to determine the Arduino models and features, as well as the SDK version.
5 |
6 | Most features can be accessed via static variables.
7 |
8 | You must instantiate if you want to know if the name of the board or if specific features such exist, for example multiple serial connections on the Arduino Mega.
9 |
10 | **This list may be neither comprehensive nor up to date**
11 |
12 | A full [List of boards and processor names][arduino_wiki] are available on Wikipedia:
13 |
14 | For more information, please see my blog article titled [Determine Arduino Board Model and Version Programmatically][blog_article]
15 |
16 | ## Installation
17 |
18 | After downloading, rename folder to 'ArduinoManager' and install in Arduino Libraries folder. Restart Arduino IDE, then open File->Sketchbook->Library->ArduinoManager->featuresniffer sketch.
19 |
20 | ## Usage
21 | ```c
22 | #include
23 |
24 |
25 | ArduinoBoardManager arduino = ArduinoBoardManager();
26 |
27 | void setup() {
28 | unsigned long M = 1000000;
29 | unsigned int k = 1000;
30 | Serial.begin(9600);
31 |
32 | while(!Serial); // on Leonardo/Micro, wait for serial
33 |
34 | // The Arduino board name
35 | Serial.print("Board is compatible with Arduino ");
36 | Serial.println(arduino.BOARD_NAME);
37 | Serial.println();
38 |
39 | // the Arduino SDK version
40 | Serial.print("SDK Version is: ");
41 | Serial.println(ArduinoBoardManager::SDK_VERSION);
42 | Serial.println();
43 |
44 | // The processor features (RAM, speed, etc)
45 | Serial.print("This "); Serial.print(arduino.BOARD_NAME);
46 | Serial.print(" is an "); Serial.print(ArduinoBoardManager::NUM_BITS);
47 | Serial.print("-bit, "); Serial.print(ArduinoBoardManager::MAX_MHZ/M);
48 | Serial.print("Mhz processor with "); Serial.print(ArduinoBoardManager::SRAM_SIZE/k);
49 | Serial.print("k of SRAM and "); Serial.print(ArduinoBoardManager::FLASH_SIZE/k);
50 | Serial.println("k of flash.");
51 | Serial.println();
52 |
53 | // Board features (multiple serial ports on Mega, for example)
54 | if (arduino.featureExists(ArduinoBoardManager::FEATURE_MULTIPLE_SERIAL)) {
55 | Serial.println("Your board supports multiple serial connections");
56 | } else {
57 | Serial.println("Your board only supports one serial connection");
58 | }
59 |
60 | if (arduino.featureExists(ArduinoBoardManager::FEATURE_ANALOG_OUT)) {
61 | Serial.println("Your board supports analog out");
62 | }
63 | if (arduino.featureExists(ArduinoBoardManager::FEATURE_BLUETOOTH_4)) {
64 | Serial.println("Your board supports bluetooth 4");
65 | }
66 | }
67 |
68 |
69 | void loop() {
70 | }
71 | ```
72 |
73 | Serial output will resemble this (tested of Arduino UNO)
74 |
75 | ```
76 | Board is compatible with Arduino UNO
77 |
78 | SDK Version is: 10604
79 |
80 | This UNO is an 8-bit, 16Mhz processor with 2k of SRAM and 32k of flash.
81 |
82 | Your board only supports one serial connection.
83 | ```
84 |
85 | [arduino_wiki]: https://en.wikipedia.org/wiki/List_of_Arduino_boards_and_compatible_systems
86 | [blog_article]: http://tonygaitatzis.tumblr.com/post/134967126657/determine-arduino-board-model-and-version
87 |
88 |
89 |
--------------------------------------------------------------------------------
/examples/featuresniffer/featuresniffer.ino:
--------------------------------------------------------------------------------
1 | #include
2 |
3 |
4 | ArduinoBoardManager arduino = ArduinoBoardManager();
5 |
6 | void setup() {
7 | unsigned long M = 1000000;
8 | unsigned int k = 1000;
9 | Serial.begin(9600);
10 |
11 | while(!Serial); // on Leonardo/Micro, wait for serial
12 |
13 | // The Arduino board name
14 | Serial.print("Board is compatible with Arduino ");
15 | Serial.println(arduino.BOARD_NAME);
16 | Serial.println();
17 |
18 | // the Arduino SDK version
19 | Serial.print("SDK Version is: ");
20 | Serial.println(ArduinoBoardManager::SDK_VERSION);
21 | Serial.println();
22 |
23 | // The processor features (RAM, speed, etc)
24 | Serial.print("This "); Serial.print(arduino.BOARD_NAME);
25 | Serial.print(" is an "); Serial.print(ArduinoBoardManager::NUM_BITS);
26 | Serial.print("-bit, "); Serial.print(ArduinoBoardManager::MAX_MHZ/M);
27 | Serial.print("Mhz processor with "); Serial.print(ArduinoBoardManager::SRAM_SIZE/k);
28 | Serial.print("k of SRAM and "); Serial.print(ArduinoBoardManager::FLASH_SIZE/k);
29 | Serial.println("k of flash.");
30 | Serial.println();
31 |
32 | // Board features (multiple serial ports on Mega, for example)
33 | if (arduino.featureExists(ArduinoBoardManager::FEATURE_MULTIPLE_SERIAL)) {
34 | Serial.println("Your board supports multiple serial connections");
35 | } else {
36 | Serial.println("Your board only supports one serial connection");
37 | }
38 |
39 | if (arduino.featureExists(ArduinoBoardManager::FEATURE_ANALOG_OUT)) {
40 | Serial.println("Your board supports analog out");
41 | }
42 | if (arduino.featureExists(ArduinoBoardManager::FEATURE_BLUETOOTH_4)) {
43 | Serial.println("Your board supports bluetooth 4");
44 | }
45 | }
46 |
47 |
48 | void loop() {
49 | }
50 |
--------------------------------------------------------------------------------