Error undefined reference to `Serial' in arduino IDE with XIAO nRF52840 Sense

Hi community, i tried to compile this code on my xiao sense with arduino IDE

bool lightOn = false;

// the setup routine runs once when you press reset:
void setup() {
  // initialize serial communication at 9600 bits per second:
  Serial.begin(9600);
  // make the pushbutton's pin an input:
  pinMode(LED_BUILTIN, OUTPUT);
}

// the loop routine runs over and over again forever:
void loop() {
  // print out the state of the button:
  if(Serial.available())
  {
    char c = Serial.read();
    if (c)
    {
      if(c == 'A')
      {
        lightOn = true;
      }
      else if(c == 'Z')
      {
        lightOn = false;
      }
      c = NULL;
    }
  }
  if(lightOn)
  {
    digitalWrite(LED_BUILTIN, HIGH);
    Serial.println("on");
  }
  else
  {
    digitalWrite(LED_BUILTIN, LOW);
    Serial.println("off");
  }
  delay(1000);        // delay in between reads for stability
}

but when i compile this the ide return this error

c:/users/damhir/documents/arduinodata/packages/seeeduino/tools/arm-none-eabi-gcc/9-2019q4/bin/…/lib/gcc/arm-none-eabi/9.2.1/…/…/…/…/arm-none-eabi/bin/ld.exe: sketch\sketch_aug15a.ino.cpp.o: in function loop': C:\Users\Damhir\Documents\Arduino\sketch_aug15a/sketch_aug15a.ino:7: undefined reference to Adafruit_USBD_CDC::available()’
c:/users/damhir/documents/arduinodata/packages/seeeduino/tools/arm-none-eabi-gcc/9-2019q4/bin/…/lib/gcc/arm-none-eabi/9.2.1/…/…/…/…/arm-none-eabi/bin/ld.exe: C:\Users\Damhir\Documents\Arduino\sketch_aug15a/sketch_aug15a.ino:9: undefined reference to Adafruit_USBD_CDC::read()' c:/users/damhir/documents/arduinodata/packages/seeeduino/tools/arm-none-eabi-gcc/9-2019q4/bin/../lib/gcc/arm-none-eabi/9.2.1/../../../../arm-none-eabi/bin/ld.exe: C:\Users\Damhir\Documents\Arduino\sketch_aug15a/sketch_aug15a.ino:23: undefined reference to Serial’
collect2.exe: error: ld returned 1 exit status
exit status 1
Error compilando para la tarjeta Seeed XIAO nRF52840 Sense.

maybe can help me?

Look at the first error, not the last

`C:\Users\Damhir\Documents\Arduino\sketch_aug15a/sketch_aug15a.ino:7: undefined reference to ` Adafruit_USBD_CDC::available()’

Now there is NOTHING in your sketch that should be dealing with something named Adafruit_USBD_CDC::available()

So, here’s the deal: Something is Wrong, Really Wrong, with your setup.

And here’s the Something Really Wrong that continues to disgust me:
Sigh…
Once again, the Seeed software tools developers have released a buggy hardware boards package. Oh, well…

I get your errors when I use the Seeed XIAO nRF52840 board from the Seeed nRF52 Boards package. That’s just flat wrong. No XIAO BLE (or XIAO BLE Sense) project with Serial anything can possibly compile with this selection.

So here’s what you do: (At least here’s what I did)
Use the Boards Manager to load the Seeed nrf52 mbed-enabled Boards package (See the attachment below)

Then select the Seeed XIAO BLE - nRF52840 board from that package. (Or you can select the Seeed XIAO BLE Sense - nRF52840 board — it makes no difference).

This works for me with your unmodified code. See Footnote.

Regards,

Dave

Footnote: When you get your code to compile and run, you will find that the LED is active-low. That is, digitalWrite(LED_BUILTIN, LOW) turns it on and digitalWrite(LED_BUILTIN, HIGH) turns it off

Thank you @davekw7x its working now!

1 Like

Just got my board today, was trying to write “hello world” to the console … and ran into the same issue.

Adding

#include “Adafruit_TinyUSB.h”

Fixes the issue for the Boards package.

Link has more details on why its happening.

Using the base boards package instead of the mbed-enabled saves quite a bit of precious space.

2 Likes

I am also encountering this issue. @davekw7x 's recommendation did the trick.