Last active
February 23, 2023 08:16
-
-
Save reefwing/9611e720259e7ef0ac44f5bf29c45167 to your computer and use it in GitHub Desktop.
An Arduino Sketch to detect the type of Nano 33 BLE (original, SENSE, or SENSE Rev 2)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <Wire.h> | |
#define HTS221_ADDRESS 0x5F // Nano 33 BLE Sense Rev 1 Sensor | |
#define HS3003_ADDRESS 0x44 // Nano 33 BLE Sense Rev 2 Sensor | |
enum BoardType { | |
NANO33BLE, | |
NANO33BLE_SENSE, | |
NANO33BLE_SENSE_R2, | |
XIAO_SENSE, | |
NOT_FOUND | |
}; | |
const char* typeStr[] = {"Nano 33 BLE", "Nano 33 BLE Sense", "Nano 33 BLE Sense Rev 2", "Seeed XIAO nRF52840 Sense", "Undefined Board Type"}; | |
BoardType detectBoard() { | |
BoardType boardType = NOT_FOUND; | |
if (strncmp(BOARD_NAME, typeStr[3], 25) == 0) { | |
boardType = XIAO_SENSE; | |
} | |
else if (strncmp(BOARD_NAME, typeStr[0], 11) == 0) { | |
// Nano 33 BLE found | |
byte error; | |
Wire1.beginTransmission(HTS221_ADDRESS); | |
error = Wire1.endTransmission(); | |
if (error == 0) { | |
boardType = NANO33BLE_SENSE; | |
} | |
else { | |
Wire1.beginTransmission(HS3003_ADDRESS); | |
error = Wire1.endTransmission(); | |
if (error == 0) { | |
boardType = NANO33BLE_SENSE_R2; | |
} | |
else { | |
boardType = NANO33BLE; | |
} | |
} | |
} | |
return boardType; | |
} | |
void setup() { | |
Wire1.begin(); | |
Serial.begin(115200); | |
while (!Serial); | |
Serial.println("Detecting Board Type...\n"); | |
Serial.println(typeStr[detectBoard()]); | |
} | |
void loop() { } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment