I bought a Xiao BLE Sense and tried to use the RGB LEDs. As explained in the wiki page for getting started, I tried Blink with the LEDB, LEDR and LEDG replacing LED_BUILTIN, but the Arduino IDE gave me errors that those were not declared in the scope. So I tried P0.26, P0.30, P0.06 and simply 26,30, 6 in the pinMode, but none of them worked. I have searched this forum and Google, but couldn’t find any answers. LED_BUILTIN works fine with the red LED. I found some other posts for the battery level indicator with these RGB LEDs but none of them added any particular header file to define these LED pins. Am I missing something?
Thanks.
I couldn’t edit my previous reply to my own post, so deleted it and am posting a new one here.
After some trial, I found I had installed wrong (not sure why exactly, though) board in the Arduino IDE. It should be ‘Seeed nRF52 mbed-enabled Boards,’ not ‘Seeed nRF52 Boards.’
Once you install this board correctly, the variant.cpp (in the folder /.arduino15/packages/Seeeduino/hardware/mbed/2.7.2/variants/SEEED_XIAO_NRF52840_SENSE/) lists all the pin definition. Here is a part of the file for the LED pins.
// LEDs
{ P0_26, NULL, NULL, NULL }, // D11/LED RED
{ P0_30, NULL, NULL, NULL }, // D12/LED GREEN
{ P0_6, NULL, NULL, NULL }, // D13/LED BLUE
In the same folder, pins_arduino.h also shows pin definitions.
Wow, You do Good Work… just saying… TY
I wish there was a definitive “seeed” guide on when to use the "Mbed-enabled " and When NOT to. Lurking on here I have been getting an uneasy feeling about going “ALL-IN” on my product dev with these Seeed Xiao boards. I too LOVE the Form-factor and all the allure of low power & BLE. I’m also relying on the accelerometer as well. (my Priority)
1)BLE (advertise,pair,etc)
2)Battery power (with deep sleep)
3)Battery level (to display on App)
4) IMU data, accelerometer (Notify App its moved)
5) Solenoid control , 3Vdc On/Off (this is working BLE controlled)
6) NFC Tag Id INFO (want to programatically change the Text it advertises)
SEEED ?
–Soapbox_OFF–
TIA.
GL :-p
BTW: I was able to get the correct colors after looking at your info,
Thank you for the pointer.
The example provided at Getting Started with Seeed Studio XIAO nRF52840 (Sense) | Seeed Studio Wiki does not work. The names of the LEDs seem to have changed for LED_RED
, LED_GREEN
and LED_BLUE
instead of LEDR
, LEDG
and LEDB
.
However, on the following sketch, the red LED never lights up.
// Blink RGB
// // Failure - Nothing
// const uint8_t ledRed = D11; // LED_RED; // LEDR; // 11; // p26;
// const uint8_t ledGreen = D12; // LED_GREEN; //LEDG; // 12; // p30;
// const uint8_t ledBlue = D13; // LED_BLUE; //LEDB; // 13; // p6;
// Failure - Blue and Green only
const uint8_t ledRed = LED_RED; // LEDR; // 11; // p26;
const uint8_t ledGreen = LED_GREEN; //LEDG; // 12; // p30;
const uint8_t ledBlue = LED_BLUE; //LEDB; // 13; // p6;
// // Failure - Blue only
// const uint8_t ledRed = LEDR; // 11; // p26;
// const uint8_t ledGreen = LEDG; // 12; // p30;
// const uint8_t ledBlue = LEDB; // 13; // p6;
// // Failure - Nothing
// const uint8_t ledRed = 11; // p26;
// const uint8_t ledGreen = 12; // p30;
// const uint8_t ledBlue = 13; // p6;
// // Failure
// const uint8_t ledRed = p26;
// const uint8_t ledGreen = p30;
// const uint8_t ledBlue = p6;
void setup() {
pinMode(ledRed, OUTPUT);
pinMode(ledGreen, OUTPUT);
pinMode(ledBlue, OUTPUT);
digitalWrite(ledRed, HIGH);
digitalWrite(ledGreen, HIGH);
digitalWrite(ledBlue, HIGH);
}
void blink(uint8_t pin) {
digitalWrite(pin, LOW); // turn the LED on (HIGH is the voltage level)
delay(1000); // wait for a second
digitalWrite(pin, HIGH); // turn the LED off by making the voltage LOW
}
void loop() {
blink(ledRed);
blink(ledGreen);
blink(ledBlue);
delay(1000); // wait for a second
}
Any hint on how to fix this? Thank you!
Hello,
The red light, green light, and blue light still correspond to LEDR, LEDG, and LEDB respectively. You can try using these three to replace your original variables ledRed, ledGreen, and ledBlue.
(with the mbed 2.9.2)
With this configuration, only the blue LED lights up.
I tried every possible variants mentioned above, to no avail.
Hi there, Such a simple thing like LED’s Why wouldn’t they be the same for both makes no-Sense to me
but I digress,
So what’s in a Name?
pinMode(LED_RED, OUTPUT); //1.1.1
pinMode(LED_GREEN, OUTPUT);
pinMode(LED_BLUE, OUTPUT);
/*****************************************************************************/
// IMU Interrupt Example for XIAO BLE Sense
// This example shows how to configure LMSD6S3TR-C on XIAO BLE SENSE to interrupt
// on INT1 after a "Double Tap" was recognized.
// Additionally, the device goes into System OFF state, after 3 interrupts were
// received. Another "Double Tap" will wake up the device again.
//
// Original by chuck
//poatched and toasted by pjg
// LEDs 2.9.2
// ----
//#define PIN_LED (12u)
//#define LED_BUILTIN PIN_LED
//#define LEDR (12u)
//#define LEDG (13u)
//#define LEDB (14u)
//#define LED_PWR (12u)
// LEDs 1.1.1
// 26, // D11 is P0.26 (LED RED)
// 6, // D12 is P0.06 (LED BLUE)
// 30, // D13 is P0.30 (LED GREEN)
// 14, // D14 is P0.14 (READ_BAT)
// this is what works.. pinMode(LED_RED, OUTPUT); //1.1.1
// pinMode(LED_GREEN, OUTPUT);
// pinMode(LED_BLUE, OUTPUT);
/*******************************************************************************/
#include "LSM6DS3.h"
#include "Wire.h"
#include <U8x8lib.h>
LSM6DS3 myIMU(I2C_MODE, 0x6A); // IMU
#define int1Pin PIN_LSM6DS3TR_C_INT1
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 buttonPin = 1; // the number of the pushbutton pin
int buttonState = 0; // variable for reading the pushbutton status
int BuzzerPin = A3;
int buzzer = BuzzerPin;
uint8_t interruptCount = 0; // Amount of received interrupts
uint8_t prevInterruptCount = 0; // Interrupt Counter from last loop
void setup() {
Serial.begin(9600);
delay(1000); //relax...
Serial.println("Processor came out of reset.\n");
u8x8.begin();
u8x8.setFlipMode(1); // set number from 1 to 3, the screen word will rotary 180
pinMode(LED_BUILTIN, OUTPUT);// initialize the LED pin as an output:
//pinMode(buttonPin, INPUT_PULLUP);// initialize the pushbutton pin as an input:
pinMode(BuzzerPin, OUTPUT);
pinMode(LED_RED, OUTPUT); //1.1.1
pinMode(LED_GREEN, OUTPUT);
pinMode(LED_BLUE, OUTPUT);
// pinMode(LEDR, OUTPUT); //2.9.2
// pinMode(LEDG, OUTPUT);
// pinMode(LEDB, OUTPUT);
setLedRGB(false, false, true); // set blue led
delay (2000);
startsound(); //Beep Buzzer speaker on A3
//initLeds(); // set pins
setupblink(); //Test RGB LED
myIMU.settings.gyroEnabled = 0; // Gyro currently not used, disabled to save power
if (myIMU.begin() != 0) {
Serial.println("IMU error");
} else {
Serial.println("IMU OK!");
}
Serial.println("\nLSM6D3 'High Level Example' compiled on "__DATE__ " at " __TIME__);
setupDoubleTapInterrupt();
pinMode(int1Pin, INPUT);
attachInterrupt(digitalPinToInterrupt(int1Pin), int1ISR, RISING);
u8x8.setFont(u8x8_font_8x13B_1x2_r);
u8x8.clearDisplay();
u8x8.setCursor(0, 0);
u8x8.print("Tap Demo");
}
void loop() {
setLedRGB(false, false, true); // reset led to blue only
u8x8.setCursor(0, 3);
u8x8.print(interruptCount);
//Serial.print("\Iterrupt Counter: ");
//Serial.println(interruptCount);
// if interrupt was received in this cycle
if (interruptCount > prevInterruptCount) {
Serial.println("\Interrupt received!");
setLedRGB(false, true, false); // set green only
}
prevInterruptCount = interruptCount;
if (interruptCount >= 3) {
// Trigger System OFF after 3 interrupts
goToPowerOff();
}
delay(500);
}
// -------------------- System ------------------------- //
void goToPowerOff() {
setLedRGB(false, false, false);
Serial.println("Going to System OFF");
u8x8.clearDisplay();
u8x8.setCursor(0, 3);
u8x8.print("SLEEP");
setupDoubleTapInterrupt(); // not needed here, if already applied..
delay(1000); // delay seems important to apply settings, before going to System OFF
//Ensure interrupt pin from IMU is set to wake up device
nrf_gpio_cfg_sense_input(digitalPinToInterrupt(int1Pin), NRF_GPIO_PIN_PULLDOWN, NRF_GPIO_PIN_SENSE_HIGH);
delay(2000); // Required delay
// Trigger System OFF
NRF_POWER->SYSTEMOFF = 1;
}
// -------------------- Interrupts ------------------------- //
void setupDoubleTapInterrupt() {
uint8_t error = 0;
uint8_t dataToWrite = 0;
// Double Tap Config
myIMU.writeRegister(LSM6DS3_ACC_GYRO_CTRL1_XL, 0x60); //* Acc = 416Hz (High-Performance mode)// Turn on the accelerometer
// ODR_XL = 416 Hz, FS_XL = 2g
myIMU.writeRegister(LSM6DS3_ACC_GYRO_TAP_CFG1, 0x8E);// INTERRUPTS_ENABLE, SLOPE_FDS// Enable interrupts and tap detection on X, Y, Z-axis
myIMU.writeRegister(LSM6DS3_ACC_GYRO_TAP_THS_6D, 0x85);// Set tap threshold 8C
myIMU.writeRegister(LSM6DS3_ACC_GYRO_INT_DUR2, 0x7F);// Set Duration, Quiet and Shock time windows 7F
myIMU.writeRegister(LSM6DS3_ACC_GYRO_WAKE_UP_THS, 0x80);// Single & double-tap enabled (SINGLE_DOUBLE_TAP = 1)
myIMU.writeRegister(LSM6DS3_ACC_GYRO_MD1_CFG, 0x08);// Double-tap interrupt driven to INT1 pin
}
void int1ISR()
{
interruptCount++;
;
}
// -------------------- Utilities ------------------------- //
void initLeds() {
pinMode(LED_RED, OUTPUT); // initialize the LED pin as an output:
pinMode(LED_GREEN, OUTPUT); // initialize the LED pin as an output:
pinMode(LED_BLUE, OUTPUT); // initialize the LED pin as an output:
pinMode(LED_BUILTIN, OUTPUT); // initialize the LED pin as an output:
}
void setupblink() {
setLedRGB(false, true, false); // Red
delay(1000);
setLedRGB(true, false, false); // Green
delay(1000);
setLedRGB(false, false, true); // Blue
delay(1000);
setLedRGB(false, false, false); // OFF
}
void startsound() {
tone(buzzer, 890);
delay(220);
noTone(buzzer);
delay(20);
tone(buzzer, 800);
delay(220);
noTone(buzzer);
delay(20);
tone(buzzer, 990);
delay(420);
noTone(buzzer);
}
void setLedRGB(bool red, bool green, bool blue) {
if (!blue) { digitalWrite(LED_BLUE, HIGH); } else { digitalWrite(LED_BLUE, LOW); }
if (!green) { digitalWrite(LED_GREEN, HIGH); } else { digitalWrite(LED_GREEN, LOW); }
if (!red) { digitalWrite(LED_RED, HIGH); } else { digitalWrite(LED_RED, LOW); }
}
Add the UNDERSCORE between the LED and Color. Works AOK.
Using library Seeed Arduino LSM6DS3 at version 2.0.3 in folder: C:\Users\Value Pawn\Documents\Arduino\libraries\Seeed_Arduino_LSM6DS3
Using library Wire at version 1.0 in folder: C:\Users\Value Pawn\AppData\Local\Arduino15\packages\Seeeduino\hardware\nrf52\1.1.1\libraries\Wire
Using library U8g2 at version 2.34.22 in folder: C:\Users\Value Pawn\Documents\Arduino\libraries\U8g2
Using library SPI at version 1.0 in folder: C:\Users\Value Pawn\AppData\Local\Arduino15\packages\Seeeduino\hardware\nrf52\1.1.1\libraries\SPI
Using library Adafruit TinyUSB Library at version 1.7.0 in folder: C:\Users\Value Pawn\AppData\Local\Arduino15\packages\Seeeduino\hardware\nrf52\1.1.1\libraries\Adafruit_TinyUSB_Arduino
"C:\\Users\\Value Pawn\\AppData\\Local\\Arduino15\\packages\\Seeeduino\\tools\\arm-none-eabi-gcc\\9-2019q4/bin/arm-none-eabi-size" -A "C:\\Users\\Value Pawn\\AppData\\Local\\Temp\\arduino\\sketches\\2DE1FA2DE1DD6F8494C9A4EA6C38C633/tap_demo_w_blink.ino.elf"
Sketch uses 53796 bytes (6%) of program storage space. Maximum is 811008 bytes.
Global variables use 7968 bytes (3%) of dynamic memory, leaving 229600 bytes for local variables. Maximum is 237568 bytes.
Performing 1200-bps touch reset on serial port COM21
Waiting for upload port...
Upload port found on COM22
"C:\Users\Value Pawn\AppData\Local\Arduino15\packages\Seeeduino\hardware\nrf52\1.1.1/tools/adafruit-nrfutil/win32/adafruit-nrfutil.exe" --verbose dfu serial -pkg "C:\Users\Value Pawn\AppData\Local\Temp\arduino\sketches\2DE1FA2DE1DD6F8494C9A4EA6C38C633/tap_demo_w_blink.ino.zip" -p COM22 -b 115200 --singlebank
Upgrading target on COM22 with DFU package C:\Users\Value Pawn\AppData\Local\Temp\arduino\sketches\2DE1FA2DE1DD6F8494C9A4EA6C38C633\tap_demo_w_blink.ino.zip. Flow control is disabled, Single bank, Touch disabled
Opened serial port COM22
Starting DFU upgrade of type 4, SoftDevice size: 0, bootloader size: 0, application size: 53804
Sending DFU start packet
Sending DFU init packet
Sending firmware file
########################################
########################################
##########################
Activating new firmware
DFU upgrade took 4.045702219009399s
Device programmed.
HTH
GL PJ
LED pins are defined as follows
Seeed nRF52 Boards 1.1.1
red 11 LED_RED LED_BUILTIN PIN_LED
green 13 LED_GREEN
blue 12 LED_BLUE
Seeed nRF52 mbed-enabled Boards 2.9.2 (Older versions have bugs)
red P0_26 12 LEDR LED_RED LED_BUILTIN PIN_LED
green P0_20 13 LEDG LED_GREEN
blue P0_6 14 LRGB LED_BLUE
is this saying there are two different hardware versions of the board
one board is using pins 11, 12, 13
the other using 12, 13, 14?
hi there,
I don’t think so, Just the pins definitions’, the ports I believe are the same. I may be wrong?
HTH
GL
There are 2 board service packages for this board. And 11,12,13 are just symbols (letters). I don’t know why the definitions are different.