I tried replacing those files in the variants folder but no go. My 2.9.1 has the moded #1/30 pins.h as b4.
The only one that still works and is about .03 vdc difference which is ok for my app at present but I stand on SEEED making this work like an Adafruit or Nordic reference design to be sure it’s there brew.
code below. running on dev board.
//TESTED AOK.12/15/22
// Displays Xiao Unit ID
// Xiao MAC:
// Battery Monitor.
#include <Arduino.h>
#include <Wire.h>
#include <U8x8lib.h>
//Create a instance of class
U8X8_SSD1306_128X64_NONAME_HW_I2C u8x8(/* clock=*/ PIN_WIRE_SCL, /* data=*/ PIN_WIRE_SDA, /* reset=*/ U8X8_PIN_NONE);
// OLEDs without Reset of the Display
const int ledPin = LED_BUILTIN;
int BuzzerPin = A3; //A3 , P0.29 PIN 4
int buzzer = BuzzerPin;
volatile int Vadc = analogRead(P0_31); // Xiao ADC for BATT mon.
uint8_t mac_address[6]; // MAC_address ARRAY
void setup(){
Serial.begin(9600);
delay(2000); //relax...Get Ready for serial port
Serial.println("Processor came out of reset.\n");
startsound();
setBatt();
initdisplay();
setupblink();
}
void loop(){
char buff[6];
get_id_address(mac_address);
sprintf(buff, "\nXiao Unit: %02lX%02lX\n",
mac_address[0],mac_address[1]);
Serial.print(buff);
u8x8.clearDisplay();
u8x8.setCursor(0,-1);
u8x8.print(buff);
u8x8.setCursor(6,6);
delay(2000);
char buffer[80];
char bufferu8[80];
get_mac_address(mac_address);
sprintf(buffer, "Xiao MAC: %02lX:%02lX:%02lX:%02lX:%02lX:%02lX\n",
mac_address[0],mac_address[1],mac_address[2],mac_address[3],mac_address[4],mac_address[5] ,mac_address[6]);
Serial.print(buffer);
sprintf(bufferu8, "Xiao MAC: \n%02lX%02lX%02lX%02lX%02lX%02lX\n",
mac_address[0],mac_address[1],mac_address[2],mac_address[3],mac_address[4],mac_address[5] ,mac_address[6]);
u8x8.setCursor(0,3);
u8x8.print(bufferu8);
delay (2000);
getBattery();
delay (2000);
}
//
//************************functions **********************
//
void get_unit_id(){
char buff[2];
get_id_address(mac_address);
sprintf(buff, "\nXiao Unit: %02lX%02lX\n", mac_address[0],mac_address[1]);
Serial.print(buff);
u8x8.clearDisplay();
u8x8.setCursor(0,-1);
u8x8.print(buff);
u8x8.setCursor(6,6);
delay(100);
}
void do_mac(){
char buffer[80];
char bufferu8[80];
Serial.println("");
get_mac_address(mac_address);
sprintf(buffer, "Xiao MAC: %02lX:%02lX:%02lX:%02lX:%02lX:%02lX\n",
mac_address[0],mac_address[1],mac_address[2],mac_address[3],mac_address[4],mac_address[5] ,mac_address[6]);
Serial.print(buffer);
sprintf(bufferu8, "Xiao MAC: \n%02lX%02lX%02lX%02lX%02lX%02lX\n",
mac_address[0],mac_address[1],mac_address[2],mac_address[3],mac_address[4],mac_address[5] ,mac_address[6]);
u8x8.setCursor(0,3);
u8x8.print(bufferu8);
}
void get_id_address(uint8_t mac_address[6]) {
unsigned int device_addr_0 = NRF_FICR->DEVICEADDR[0];
unsigned int device_addr_1 = NRF_FICR->DEVICEADDR[1];
const uint8_t* part_0 = reinterpret_cast<const uint8_t*>(&device_addr_0);
const uint8_t* part_1 = reinterpret_cast<const uint8_t*>(&device_addr_1);
mac_address[0] = part_1[3]; //changed from get_mac_address elements 0,1
mac_address[1] = part_1[2]; //
}
void setBatt(){
pinMode(P0_31, INPUT); //Battery Voltage monitoring pin
pinMode(P0_13, OUTPUT); //Charge Current setting pin
pinMode(P0_14, OUTPUT); //Enable Battery Voltage monitoring pin
digitalWrite(P0_13, LOW); //Charge Current 100mA
digitalWrite(P0_14, LOW); //Enable
analogReference(AR_INTERNAL2V4); //Vref=2.4V
analogReadResolution(12);
}
void getBattery(){
int Vadc = analogRead(P0_31);
float Vbatt = ((510e3 + 1000e3) / 510e3) * 2.466 * Vadc / 4096;
Serial.print("Battery Level ");
Serial.println( Vbatt, 2);
digitalWrite(LED_GREEN, HIGH);
u8x8.clearDisplay();
u8x8.setCursor(0,2);
u8x8.print("Battery Monitor");
u8x8.setCursor(6,6);
u8x8.print(Vbatt, 2);
}
void get_mac_address(uint8_t mac_address[6]) {
unsigned int device_addr_0 = NRF_FICR->DEVICEADDR[0];
unsigned int device_addr_1 = NRF_FICR->DEVICEADDR[1];
const uint8_t* part_0 = reinterpret_cast<const uint8_t*>(&device_addr_0);
const uint8_t* part_1 = reinterpret_cast<const uint8_t*>(&device_addr_1);
mac_address[0] = part_1[1];
mac_address[1] = part_1[0];
mac_address[2] = part_0[3];
mac_address[3] = part_0[2];
mac_address[4] = part_0[1];
mac_address[5] = part_0[0];
}
void setupblink(){
setLedRGB(false, false, true); // set Blue LED
delay(1000);
setLedRGB(false, true, false); // Red
delay(1000);
setLedRGB(true, false, false); // Green
delay(1000);
setLedRGB(false, false, false); // OFF
}
void initdisplay() {
pinMode(LEDR, OUTPUT); // initialize the LED pin as an output:
pinMode(LEDG, OUTPUT); // initialize the LED pin as an output:
pinMode(LEDB, OUTPUT);
pinMode(LED_BUILTIN, OUTPUT); // initialize the LED pin as an output:
u8x8.begin();
u8x8.setFlipMode(1); // set number from 1 to 3, the screen word will rotary 180
u8x8.setFont(u8x8_font_8x13B_1x2_r);
u8x8.clearDisplay();
u8x8.setCursor(0, 0);
u8x8.print("Power ON ");
}
void startsound() {
tone (buzzer, 890);
delay (220);
noTone(buzzer);
delay (20);
tone (buzzer, 800);
delay (220);
noTone(buzzer);
delay (20);
tone (buzzer, 800);
delay (220);
noTone(buzzer);
delay (20);
tone (buzzer, 990);
delay (420);
noTone(buzzer);
delay (20);
}
void setLedRGB(bool red, bool green, bool blue) {
if (!red) { digitalWrite(LEDR, HIGH); } else { digitalWrite(LEDR, LOW); }
if (!green) { digitalWrite(LEDG, HIGH); } else { digitalWrite(LEDG, LOW); }
if (!blue) { digitalWrite(LEDB, HIGH); } else { digitalWrite(LEDB, LOW); }
}
print output,
Processor came out of reset.
Xiao Unit: 53BB
Xiao MAC: 21:0E:63:78:CF:67
Battery Level 3.50
Xiao Unit: 53BB
Xiao MAC: 21:0E:63:78:CF:67
Battery Level 3.51
Xiao Unit: 53BB
Xiao MAC: 21:0E:63:78:CF:67
Battery Level 3.50
HTH
GL