├── .gitignore ├── LICENSE ├── README.md ├── TeensyID.cpp ├── TeensyID.h ├── examples ├── ReadAll │ └── ReadAll.ino └── T4_ReadAll │ └── T4_ReadAll.ino ├── library.json └── library.properties /.gitignore: -------------------------------------------------------------------------------- 1 | *.DS_Store 2 | .DS_Store 3 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2016 Frank Bösing 4 | Copyright (c) 2020 Stefan Staub 5 | 6 | Permission is hereby granted, free of charge, to any person obtaining a copy 7 | of this software and associated documentation files (the "Software"), to deal 8 | in the Software without restriction, including without limitation the rights 9 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | copies of the Software, and to permit persons to whom the Software is 11 | furnished to do so, subject to the following conditions: 12 | 13 | The above copyright notice and this permission notice shall be included in all 14 | copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | SOFTWARE. 23 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # TeensyID 2 | - Teensy (USB-)Serialnumber, MAC-Address, 3 | - Kinetis ChipUID and UUID (RFC4122) for Teensy 3.x and LC 4 | - 64-bit UID for Teensy 4.x 5 | 6 | Tested: 7 | - Teensy 3.5 by sstaub 8 | - Teensy 3.2, WIZ850io, PRJC sd/Ethernet adapter, Arduino 1.8.11, TD 1.35, by bboyes 9 | - Teensy 3.6 amd LC by manitou 10 | - Teensy 4.x by sstaub 11 | 12 | ## Examples 13 | ### **ReadAll** for Teensy 3.x and LC 14 | ``` 15 | #include "Arduino.h" 16 | #include 17 | 18 | uint8_t serial[4]; 19 | uint8_t mac[6]; 20 | uint32_t uid[4]; 21 | uint8_t uuid[16]; 22 | 23 | void setup() { 24 | teensySN(serial); 25 | teensyMAC(mac); 26 | kinetisUID(uid); 27 | teensyUUID(uuid); 28 | delay(2000); 29 | Serial.printf("USB Serialnumber: %u \n", teensyUsbSN()); 30 | Serial.printf("Array Serialnumber: %02X-%02X-%02X-%02X \n", serial[0], serial[1], serial[2], serial[3]); 31 | Serial.printf("String Serialnumber: %s\n", teensySN()); 32 | Serial.printf("Array MAC Address: %02X:%02X:%02X:%02X:%02X:%02X \n", mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]); 33 | Serial.printf("String MAC Address: %s\n", teensyMAC()); 34 | Serial.printf("Array 128-bit UniqueID from chip: %08X-%08X-%08X-%08X\n", uid[0], uid[1], uid[2], uid[3]); 35 | Serial.printf("String 128-bit UniqueID from chip: %s\n", kinetisUID()); 36 | Serial.printf("Array 128-bit UUID RFC4122: %02X%02X%02X%02X-%02X%02X-%02X%02X-%02X%02X-%02X%02X%02X%02X%02X%02X\n", uuid[0], uuid[1], uuid[2], uuid[3], uuid[4], uuid[5], uuid[6], uuid[7], uuid[8], uuid[9], uuid[10], uuid[11], uuid[12], uuid[13], uuid[14], uuid[15]); 37 | Serial.printf("String 128-bit UUID RFC4122: %s\n", teensyUUID()); 38 | } 39 | 40 | void loop() {} 41 | ``` 42 | 43 | - Just as it sounds, read and print out serial, mac, uid, uuid 44 | - Typical output: 45 | ``` 46 | USB Serialnumber: 1244570 47 | Array Serialnumber: 00-01-E6-29 48 | String Serialnumber: 00-01-e6-29 49 | Array MAC Address: 04:E9:E5:01:E6:29 50 | String MAC Address: 04:e9:e5:01:e6:29 51 | Array 128-bit UniqueID from chip: C7210000-714D001E-00496017-31384E45 52 | String 128-bit UniqueID from chip: c7210000-714d001e-00496017-31384e45 53 | Array 128-bit UUID RFC4122: 00496017-3138-404E-8045-04E9E501E629 54 | String 128-bit UUID RFC4122: 00496017-3138-404e-8045-04e9e501e629 55 | ``` 56 | 57 | ### **T4_ReadAll** for Teensy 4.x 58 | ``` 59 | #include "Arduino.h" 60 | #include 61 | 62 | uint8_t serial[4]; 63 | uint8_t mac[6]; 64 | uint8_t uid64[8]; 65 | 66 | void setup() { 67 | Serial.begin(9600); 68 | delay(2000); 69 | teensySN(serial); 70 | teensyMAC(mac); 71 | teensyUID64(uid64); 72 | Serial.printf("USB Serialnumber: %u \n", teensyUsbSN()); 73 | Serial.printf("Array Serialnumber: %02X-%02X-%02X-%02X \n", serial[0], serial[1], serial[2], serial[3]); 74 | Serial.printf("String Serialnumber: %s\n", teensySN()); 75 | Serial.printf("Array MAC Address: %02X:%02X:%02X:%02X:%02X:%02X \n", mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]); 76 | Serial.printf("String MAC Address: %s\n", teensyMAC()); 77 | Serial.printf("UID 64-bit: %02X-%02X-%02X-%02X-%02X-%02X-%02X-%02X\n", uid64[0], uid64[1], uid64[2], uid64[3], uid64[4], uid64[5], uid64[6], uid64[7]); 78 | Serial.printf("UID 64-bit: %s\n", teensyUID64()); 79 | } 80 | 81 | void loop() {} 82 | ``` -------------------------------------------------------------------------------- /TeensyID.cpp: -------------------------------------------------------------------------------- 1 | /* TeensyMAC library code is placed under the MIT license 2 | * Copyright (c) 2017 Stefan Staub 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining 5 | * a copy of this software and associated documentation files (the 6 | * "Software"), to deal in the Software without restriction, including 7 | * without limitation the rights to use, copy, modify, merge, publish, 8 | * distribute, sublicense, and/or sell copies of the Software, and to 9 | * permit persons to whom the Software is furnished to do so, subject to 10 | * the following conditions: 11 | * 12 | * The above copyright notice and this permission notice shall be 13 | * included in all copies or substantial portions of the Software. 14 | * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 16 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 17 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 18 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS 19 | * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN 20 | * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 21 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | 25 | #include "TeensyID.h" 26 | 27 | // UNIQUE_ID 28 | #if defined ARDUINO_TEENSY40 || defined ARDUINO_TEENSY41 29 | static uint32_t getTeensySerial(void) { 30 | uint32_t num; 31 | num = HW_OCOTP_MAC0 & 0xFFFFFF; 32 | return num; 33 | } 34 | 35 | #else 36 | static uint32_t getTeensySerial(void) { 37 | uint32_t num = 0; 38 | __disable_irq(); 39 | #if defined(HAS_KINETIS_FLASH_FTFA) || defined(HAS_KINETIS_FLASH_FTFL) 40 | FTFL_FSTAT = FTFL_FSTAT_RDCOLERR | FTFL_FSTAT_ACCERR | FTFL_FSTAT_FPVIOL; 41 | FTFL_FCCOB0 = 0x41; 42 | FTFL_FCCOB1 = 15; 43 | FTFL_FSTAT = FTFL_FSTAT_CCIF; 44 | while (!(FTFL_FSTAT & FTFL_FSTAT_CCIF)) ; // wait 45 | num = *(uint32_t *)&FTFL_FCCOB7; 46 | #elif defined(HAS_KINETIS_FLASH_FTFE) 47 | kinetis_hsrun_disable(); 48 | FTFL_FSTAT = FTFL_FSTAT_RDCOLERR | FTFL_FSTAT_ACCERR | FTFL_FSTAT_FPVIOL; 49 | *(uint32_t *)&FTFL_FCCOB3 = 0x41070000; 50 | FTFL_FSTAT = FTFL_FSTAT_CCIF; 51 | while (!(FTFL_FSTAT & FTFL_FSTAT_CCIF)) ; // wait 52 | num = *(uint32_t *)&FTFL_FCCOBB; 53 | kinetis_hsrun_enable(); 54 | #endif 55 | __enable_irq(); 56 | return num; 57 | } 58 | #endif 59 | 60 | uint32_t teensyUsbSN() { 61 | uint32_t num = getTeensySerial(); 62 | if (num < 10000000) num = num * 10; 63 | return num; 64 | } 65 | 66 | void teensySN(uint8_t *sn) { 67 | uint32_t num = getTeensySerial(); 68 | sn[0] = num >> 24; 69 | sn[1] = num >> 16; 70 | sn[2] = num >> 8; 71 | sn[3] = num; 72 | } 73 | 74 | const char* teensySN(void) { 75 | uint8_t serial[4]; 76 | static char teensySerial[12]; 77 | teensySN(serial); 78 | sprintf(teensySerial, "%02x-%02x-%02x-%02x", serial[0], serial[1], serial[2], serial[3]); 79 | return teensySerial; 80 | } 81 | 82 | #if defined ARDUINO_TEENSY40 || defined ARDUINO_TEENSY41 83 | 84 | void teensyMAC(uint8_t *mac) { // there are 2 MAC addresses each 48bit 85 | uint32_t m1 = HW_OCOTP_MAC1; 86 | uint32_t m2 = HW_OCOTP_MAC0; 87 | mac[0] = m1 >> 8; 88 | mac[1] = m1 >> 0; 89 | mac[2] = m2 >> 24; 90 | mac[3] = m2 >> 16; 91 | mac[4] = m2 >> 8; 92 | mac[5] = m2 >> 0; 93 | } 94 | 95 | #else 96 | 97 | void teensyMAC(uint8_t *mac) { 98 | uint8_t serial[4]; 99 | teensySN(serial); 100 | mac[0] = 0x04; 101 | mac[1] = 0xE9; 102 | mac[2] = 0xE5; 103 | mac[3] = serial[1]; 104 | mac[4] = serial[2]; 105 | mac[5] = serial[3]; 106 | } 107 | 108 | #endif 109 | 110 | const char* teensyMAC(void) { 111 | uint8_t mac[6]; 112 | static char teensyMac[18]; 113 | teensyMAC(mac); 114 | sprintf(teensyMac, "%02x:%02x:%02x:%02x:%02x:%02x", mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]); 115 | return teensyMac; 116 | } 117 | 118 | #if defined ARDUINO_TEENSY40 || defined ARDUINO_TEENSY41 119 | void kinetisUID(uint32_t *uid) { 120 | (void)uid; // suppress warn unused parameter 'uid' 121 | } 122 | 123 | const char* kinetisUID(void) { 124 | return "no UID"; 125 | } 126 | 127 | #elif ARDUINO_TEENSYLC // 80bit UID Teensy LC 128 | 129 | void kinetisUID(uint32_t *uid) { 130 | uid[0] = SIM_UIDMH; 131 | uid[1] = SIM_UIDML; 132 | uid[2] = SIM_UIDL; 133 | } 134 | 135 | const char* kinetisUID(void) { 136 | uint32_t uid[3]; 137 | static char uidString[27]; 138 | kinetisUID(uid); 139 | sprintf(uidString, "%08lx-%08lx-%08lx", uid[0], uid[1], uid[2]); 140 | return uidString; 141 | } 142 | 143 | #else // 128bit UIDTeensy 3.x 144 | 145 | void kinetisUID(uint32_t *uid) { 146 | uid[0] = SIM_UIDH; 147 | uid[1] = SIM_UIDMH; 148 | uid[2] = SIM_UIDML; 149 | uid[3] = SIM_UIDL; 150 | } 151 | 152 | const char* kinetisUID(void) { 153 | uint32_t uid[4]; 154 | static char uidString[36]; 155 | kinetisUID(uid); 156 | sprintf(uidString, "%08lx-%08lx-%08lx-%08lx", uid[0], uid[1], uid[2], uid[3]); 157 | return uidString; 158 | } 159 | 160 | #endif 161 | 162 | #if defined ARDUINO_TEENSY40 || defined ARDUINO_TEENSY41 163 | 164 | void teensyUUID(uint8_t *uuid) { 165 | (void)uuid; // suppress warn unused parameter 'uuid' 166 | } 167 | 168 | const char* teensyUUID(void) { 169 | return "no UID"; 170 | } 171 | 172 | void teensyUID64(uint8_t *uid64) { 173 | uint32_t uid0 = HW_OCOTP_CFG0; 174 | uint32_t uid1 = HW_OCOTP_CFG1; 175 | uid64[0] = uid0 >> 24; 176 | uid64[1] = uid0 >> 16; 177 | uid64[2] = uid0 >> 8; 178 | uid64[3] = uid0; 179 | uid64[4] = uid1 >> 24; 180 | uid64[5] = uid1 >> 16; 181 | uid64[6] = uid1 >> 8; 182 | uid64[7] = uid1; 183 | } 184 | 185 | const char* teensyUID64(void) { 186 | uint8_t uid64[8]; 187 | static char uid64String[24]; 188 | teensyUID64(uid64); 189 | sprintf(uid64String, "%02x-%02x-%02x-%02x-%02x-%02x-%02x-%02x", uid64[0], uid64[1], uid64[2], uid64[3], uid64[4], uid64[5], uid64[6], uid64[7]); 190 | return uid64String; 191 | } 192 | 193 | #else 194 | 195 | void teensyUUID(uint8_t *uuid) { 196 | uint8_t mac[6]; 197 | teensyMAC(mac); 198 | uuid[0] = SIM_UIDML >> 24; 199 | uuid[1] = SIM_UIDML >> 16; 200 | uuid[2] = SIM_UIDML >> 8; 201 | uuid[3] = SIM_UIDML; 202 | uuid[4] = SIM_UIDL >> 24; 203 | uuid[5] = SIM_UIDL >> 16; 204 | uuid[6] = 0x40; // marked as version v4, but this uuid is not random based !!! 205 | uuid[7] = SIM_UIDL >> 8; 206 | uuid[8] = 0x80; //variant 207 | uuid[9] = SIM_UIDL; 208 | uuid[10] = mac[0]; 209 | uuid[11] = mac[1]; 210 | uuid[12] = mac[2]; 211 | uuid[13] = mac[3]; 212 | uuid[14] = mac[4]; 213 | uuid[15] = mac[5]; 214 | } 215 | 216 | 217 | const char* teensyUUID(void) { 218 | uint8_t uuid[16]; 219 | static char uuidString[37]; 220 | teensyUUID(uuid); 221 | sprintf(uuidString, "%02x%02x%02x%02x-%02x%02x-%02x%02x-%02x%02x-%02x%02x%02x%02x%02x%02x", uuid[0], uuid[1], uuid[2], uuid[3], uuid[4], uuid[5], uuid[6], uuid[7], uuid[8], uuid[9], uuid[10], uuid[11], uuid[12], uuid[13], uuid[14], uuid[15]); 222 | return uuidString; 223 | } 224 | 225 | #endif 226 | 227 | #if defined ARDUINO_TEENSY41 228 | const char* teensyBoardVersion(void) { 229 | static char boardVersion[16] = "Teensy 4.1"; 230 | return boardVersion; 231 | } 232 | 233 | #elif defined ARDUINO_TEENSY40 234 | const char* teensyBoardVersion(void) { 235 | static char boardVersion[16] = "Teensy 4.0"; 236 | return boardVersion; 237 | } 238 | 239 | #elif defined ARDUINO_TEENSYLC 240 | const char* teensyBoardVersion(void) { 241 | static char boardVersion[16] = "Teensy LC"; 242 | return boardVersion; 243 | } 244 | 245 | #elif defined ARDUINO_TEENSY36 246 | const char* teensyBoardVersion(void) { 247 | static char boardVersion[16] = "Teensy 3.6"; 248 | return boardVersion; 249 | } 250 | 251 | #elif defined ARDUINO_TEENSY35 252 | const char* teensyBoardVersion(void) { 253 | static char boardVersion[16] = "Teensy 3.5"; 254 | return boardVersion; 255 | } 256 | 257 | #elif defined ARDUINO_TEENSY32 258 | const char* teensyBoardVersion(void) { 259 | static char boardVersion[16] = "Teensy 3.2"; 260 | return boardVersion; 261 | } 262 | 263 | #elif defined ARDUINO_TEENSY31 264 | const char* teensyBoardVersion(void) { 265 | static char boardVersion[16] = "Teensy 3.1"; 266 | return boardVersion; 267 | } 268 | 269 | #elif defined ARDUINO_TEENSY30 270 | const char* teensyBoardVersion(void) { 271 | static char boardVersion[16] = "Teensy 3.0"; 272 | return boardVersion; 273 | } 274 | 275 | #else 276 | const char* teensyBoardVersion(void) { 277 | static char boardVersion[16] = "Unknown Teensy"; 278 | return boardVersion; 279 | } 280 | #endif 281 | 282 | -------------------------------------------------------------------------------- /TeensyID.h: -------------------------------------------------------------------------------- 1 | /* TeensyMAC library code is placed under the MIT license 2 | * Copyright (c) 2017 Stefan Staub 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining 5 | * a copy of this software and associated documentation files (the 6 | * "Software"), to deal in the Software without restriction, including 7 | * without limitation the rights to use, copy, modify, merge, publish, 8 | * distribute, sublicense, and/or sell copies of the Software, and to 9 | * permit persons to whom the Software is furnished to do so, subject to 10 | * the following conditions: 11 | * 12 | * The above copyright notice and this permission notice shall be 13 | * included in all copies or substantial portions of the Software. 14 | * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 16 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 17 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 18 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS 19 | * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN 20 | * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 21 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | 25 | #ifndef TEENSYID_H 26 | #define TEENSYID_H 27 | 28 | #include "Arduino.h" 29 | 30 | /** Teens USB Serial Number 31 | * 32 | * @ returns 33 | * The USB Serial Number 34 | */ 35 | uint32_t teensyUsbSN(); 36 | 37 | /** Teensy Serial Number 38 | * 39 | * @param sn Pointer to an array with size of 4 uint8_t which contents the serial number 40 | */ 41 | void teensySN(uint8_t *sn); 42 | 43 | /** Teensy Serial Number 44 | * 45 | * @returns 46 | * A formated string in hex xx-xx-xx-xx 47 | */ 48 | const char* teensySN(void); 49 | 50 | /** Teensy MAC Address 51 | * 52 | * @param mac Pointer to an array with size of 6 uint8_t which contents the mac address 53 | */ 54 | void teensyMAC(uint8_t *mac); 55 | 56 | /** Teensy MAC Address 57 | * 58 | * @returns 59 | * A formated string in hex xx:xx:xx:xx:xx:xx 60 | */ 61 | const char* teensyMAC(void); 62 | 63 | /** Kinetis Chip UID 64 | * 65 | * @param uid Pointer to an array with size of 4 uint32_t which contents the kinetis uid 66 | */ 67 | void kinetisUID(uint32_t *uid); 68 | 69 | /** Kinetis Chip UID 70 | * 71 | * @returns 72 | * A formated string in hex xxxx:xxxx:xxxx:xxxx 73 | */ 74 | const char* kinetisUID(void); 75 | 76 | /** Teensy UUID (RFC4122) 77 | * 78 | * @param uid Pointer to an array with size of 16 uint8_t which contents the uuid 79 | * 80 | * @note 81 | * It is an UUID extracted from the Kinetis UID and the MAC Address. 82 | * It is marked as version 4, (pseudo)random based 83 | */ 84 | void teensyUUID(uint8_t *uid); 85 | 86 | /** Teensy UUID (RFC4122) 87 | * 88 | * @returns 89 | * A formated string in hex xxxx-xx-xx-xx-xxxxxx 90 | */ 91 | const char* teensyUUID(void); 92 | 93 | /** Teensy UID 64-bit for Teensy 4.x 94 | * 95 | * @param uid Pointer to an array with size of 16 uint8_t which contents the uuid 96 | * 97 | * @note 98 | * It is an UUID extracted from the Kinetis UID and the MAC Address. 99 | * It is marked as version 4, (pseudo)random based 100 | */ 101 | void teensyUID64(uint8_t *uid64); 102 | 103 | /** Teensy UID 64-bit for Teensy 4.x 104 | * 105 | * @returns 106 | * A formated string in hex xxxx-xx-xx-xx-xxxxxx 107 | */ 108 | const char* teensyUID64(void); 109 | 110 | /** Teensy Board Version 111 | * 112 | * @returns 113 | * A string containing the board name as specified on https://www.pjrc.com/teensy/ 114 | */ 115 | const char* teensyBoardVersion(void); 116 | 117 | #endif 118 | -------------------------------------------------------------------------------- /examples/ReadAll/ReadAll.ino: -------------------------------------------------------------------------------- 1 | /* TeensyMAC library code is placed under the MIT license 2 | * Copyright (c) 2017 Stefan Staub 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining 5 | * a copy of this software and associated documentation files (the 6 | * "Software"), to deal in the Software without restriction, including 7 | * without limitation the rights to use, copy, modify, merge, publish, 8 | * distribute, sublicense, and/or sell copies of the Software, and to 9 | * permit persons to whom the Software is furnished to do so, subject to 10 | * the following conditions: 11 | * 12 | * The above copyright notice and this permission notice shall be 13 | * included in all copies or substantial portions of the Software. 14 | * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 16 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 17 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 18 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS 19 | * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN 20 | * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 21 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | 25 | /** Teensy Library for different IDs of Teensy LC and Teensy 3.x and 4.x 26 | * 27 | * - USB Serial Number for Teensy 3.x and LC 28 | * - Teensy Serial Number for Teensy 3.x and LC 29 | * - MAC Address for Teensy 3.x, LC and 4.x 30 | * - Kinetis Chip UID for Teensy 3.x, LC 31 | * - UUID (RFC4122) pseudo v4 for Teensy 3.x, LC 32 | * - UID64 for Teensy 4.x 33 | */ 34 | 35 | 36 | #include "Arduino.h" 37 | #include 38 | 39 | uint8_t serial[4]; 40 | uint8_t mac[6]; 41 | uint32_t uid[4]; 42 | uint8_t uuid[16]; 43 | 44 | void setup() { 45 | Serial.begin(9600); 46 | delay(2000); 47 | teensySN(serial); 48 | teensyMAC(mac); 49 | kinetisUID(uid); 50 | teensyUUID(uuid); 51 | Serial.printf("USB Serialnumber: %u \n", teensyUsbSN()); 52 | Serial.printf("Array Serialnumber: %02X-%02X-%02X-%02X \n", serial[0], serial[1], serial[2], serial[3]); 53 | Serial.printf("String Serialnumber: %s\n", teensySN()); 54 | Serial.printf("Array MAC Address: %02X:%02X:%02X:%02X:%02X:%02X \n", mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]); 55 | Serial.printf("String MAC Address: %s\n", teensyMAC()); 56 | Serial.printf("Array 128-bit UniqueID from chip: %08X-%08X-%08X-%08X\n", uid[0], uid[1], uid[2], uid[3]); 57 | Serial.printf("String 128-bit UniqueID from chip: %s\n", kinetisUID()); 58 | Serial.printf("Array 128-bit UUID RFC4122: %02X%02X%02X%02X-%02X%02X-%02X%02X-%02X%02X-%02X%02X%02X%02X%02X%02X\n", uuid[0], uuid[1], uuid[2], uuid[3], uuid[4], uuid[5], uuid[6], uuid[7], uuid[8], uuid[9], uuid[10], uuid[11], uuid[12], uuid[13], uuid[14], uuid[15]); 59 | Serial.printf("String 128-bit UUID RFC4122: %s\n", teensyUUID()); 60 | Serial.printf("Board Model: %s\n", teensyBoardVersion()); 61 | } 62 | 63 | void loop() {} 64 | -------------------------------------------------------------------------------- /examples/T4_ReadAll/T4_ReadAll.ino: -------------------------------------------------------------------------------- 1 | /* TeensyMAC library code is placed under the MIT license 2 | * Copyright (c) 2017 Stefan Staub 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining 5 | * a copy of this software and associated documentation files (the 6 | * "Software"), to deal in the Software without restriction, including 7 | * without limitation the rights to use, copy, modify, merge, publish, 8 | * distribute, sublicense, and/or sell copies of the Software, and to 9 | * permit persons to whom the Software is furnished to do so, subject to 10 | * the following conditions: 11 | * 12 | * The above copyright notice and this permission notice shall be 13 | * included in all copies or substantial portions of the Software. 14 | * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 16 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 17 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 18 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS 19 | * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN 20 | * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 21 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | 25 | /** Teensy Library for different IDs of Teensy LC and Teensy 3.x and 4.x 26 | * 27 | * - USB Serial Number for Teensy 3.x, LC and 4.x 28 | * - Teensy Serial Number for Teensy 3.x, LC and 4.x 29 | * - MAC Address for Teensy 3.x, LC and 4.x 30 | * - Kinetis Chip UID only for Teensy 3.x, LC 31 | * - UUID (RFC4122) pseudo v4 only for Teensy 3.x, LC 32 | * - UID64 for Teensy 4.x 33 | */ 34 | 35 | 36 | #include "Arduino.h" 37 | #include 38 | 39 | uint8_t serial[4]; 40 | uint8_t mac[6]; 41 | uint8_t uid64[8]; 42 | 43 | void setup() { 44 | Serial.begin(9600); 45 | delay(2000); 46 | teensySN(serial); 47 | teensyMAC(mac); 48 | teensyUID64(uid64); 49 | Serial.printf("USB Serialnumber: %u \n", teensyUsbSN()); 50 | Serial.printf("Array Serialnumber: %02X-%02X-%02X-%02X \n", serial[0], serial[1], serial[2], serial[3]); 51 | Serial.printf("String Serialnumber: %s\n", teensySN()); 52 | Serial.printf("Array MAC Address: %02X:%02X:%02X:%02X:%02X:%02X \n", mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]); 53 | Serial.printf("String MAC Address: %s\n", teensyMAC()); 54 | Serial.printf("UID 64-bit: %02X-%02X-%02X-%02X-%02X-%02X-%02X-%02X\n", uid64[0], uid64[1], uid64[2], uid64[3], uid64[4], uid64[5], uid64[6], uid64[7]); 55 | Serial.printf("UID 64-bit: %s\n", teensyUID64()); 56 | Serial.printf("Board Model: %s\n", teensyBoardVersion()); 57 | } 58 | 59 | void loop() {} 60 | -------------------------------------------------------------------------------- /library.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "TeensyID", 3 | "keywords": "MAC, Serialnumber, ChipID", 4 | "description": "Set of functions for different IDs of the Teensy: USB Serialnumber, Serialnumber, MAC-Address, ChipID and BoardID", 5 | "repository": 6 | { 7 | "type": "git", 8 | "url": "https://github.com/sstaub/TeensyID" 9 | }, 10 | "version": "1.4.0", 11 | "frameworks": "arduino", 12 | "platforms": "Teensy" 13 | } 14 | 15 | -------------------------------------------------------------------------------- /library.properties: -------------------------------------------------------------------------------- 1 | name=TeensyID 2 | version=1.4.0 3 | author=Stefan Staub 4 | maintainer=Stefan Staub 5 | sentence=A library for getting Teensy IDs 6 | paragraph=Small Set of functions for different IDs of the Teensy: USB Serialnumber, Serialnumber, MAC-Address, ChipID and BoardID 7 | category=Communication 8 | url=https://github.com/sstaub/TeensyID 9 | architectures=Teensy 10 | --------------------------------------------------------------------------------