Seeeduino Xiao nRF52840 Serial.read()

I’m using for the .ini:

; PlatformIO Project Configuration File
;
;   Build options: build flags, source filter
;   Upload options: custom upload port, speed and extra flags
;   Library options: dependencies, extra library storages
;   Advanced options: extra scripting
;
; Please visit documentation for the other options and examples
; https://docs.platformio.org/page/projectconf.html

[env:xiaoblesense]
platform = https://github.com/maxgerhardt/platform-nordicnrf52
board = xiaoblesense
framework = arduino
monitor_speed = 115200

lib_deps = 
    U8g2
    Wire

And Version:2.0.3
Seeed XIAO nRF52840 Sense for Arduino

How can that be? The package index has the nRF52 cores 2.6.1 to 2.8.1 (ArduinoCore-mbed fork) or 1.0.0 (Adafruit_nRF52_Arduino fork).

Can you post the package URL that you added in File->Preferences?

Oh sorry I misread!

It is:
https://files.seeedstudio.com/arduino/package_seeeduino_boards_index.json

Should be:
ArduinoCore-mbed-Seeed-2.8.1

I see. My custom platform uses the at-the-time-of-writing up-to-date core version, 2.6.1. I’ll update it to 2.8.1 so that we can compare apples to apples.

1 Like

I did update the core to the latest one but the changes are extremely small and none of them relate to the USB Serial: Update core to 2.8.1 · maxgerhardt/framework-mbed-seeed@b7a8974 · GitHub.

Can you grab the changes by using the CLI with the command

pio pkg update -g -p "https://github.com/maxgerhardt/platform-nordicnrf52"

and recompiling and reuploading the project anyways?

Thanks for the help! I updated the package and it still works for the serial monitor but not from the usbC cable to the nRF52840 plugged into my computer that is sending the serial data.

And just to make tripple sure that you’re not using the 1.0.0 version accidentally, you have this board selected right in the “Seeed nRF52 mbed-enabled Boards” right?

(Well, the one below that with the “Sense” in it)

Good catch. I am not using the mbed-enabled board version, but the Version 1.0.0 Seeed nRF52 Board in Arduino.

image

I see.

Two options from here (well, parallel):

  • I update the platform to allow using the “1.0.0” version (extremely badly named by Seeed for another Adafruit_nRF52_Arduino fork, don’t know why they have the same board support in two different cores at all)
  • or, please try to see if in the Qt C++ code, you can assert the “DTR” (data terminal ready) signal of the opened serial port. Some Arduino cores have the pecularity that they will silently ignore and data sent to the virtual USB serial port if the virtual DTR signal is not asserted. The RTS can be left alone. This could unblock the firmware running with the PlatformIO fimware (using ArduinoCore-mbed fork) from accepting data from your Qt program.

Specifically, code from QSerialPort sets DTR to high upon closing port; won't emit readyReady when DTR is otherwise held high. | Qt Forum looks good. Try with both false and true in serial.setDataTerminalReady().

1 Like

Awesome let me try and update my Qt code first and add the DTR signal.

You’re a genius. Adding that to my QSerialPort initiallization fixed the problem. I think, exactly like you said the Arduino core was ignoring the data without the DTR signal. It works now with this:

        xiaoNRF52840->setBaudRate(QSerialPort::Baud115200);
        xiaoNRF52840->setDataBits(QSerialPort::Data8);
        xiaoNRF52840->setParity(QSerialPort::NoParity);
        xiaoNRF52840->setStopBits(QSerialPort::OneStop);
        xiaoNRF52840->setFlowControl(QSerialPort::NoFlowControl);
        xiaoNRF52840->setDataTerminalReady(true);
1 Like

Great to hear! I’ll still work on getting the “1.0.0” supported in PlatformIO. If you were to use the custom built-in libraries of the Arduino core like BLE, they would be different between ArduinoCore-mbed and Adafruit_nRF52_Arduino, and the sketch would not compile anymore under PlatformIO.

Makes sense, so currently the only PlatfromIO support is for the ArduinoCore-mbed that you created. If I run into those issues I’ll bug you again :wink:

I’ve created a xiaoblesense_adafruit and xiaoble_adafruit board that make use of the “1.0.0” Seeed Adafruit nRF52 core version. Can you execute the update command again (or if that doesn’t work, delete <home directory>/.platformio/platforms/nrf52*) and flash the example code from GitHub - maxgerhardt/pio-xiao-ble-test: Test programs for PlatformIO support for Xiao BLE (Sense) boards. on it, which is from here? I’d very much like to know whether the project can be uploaded and the BLE Uart service shows up in the App and can be connected to.

What settings should I use in the .ini file?

For your board and the given example file,

[env:xiaoblesense_adafruit]
platform = https://github.com/maxgerhardt/platform-nordicnrf52
board = xiaoblesense_adafruit
framework = arduino
monitor_speed = 115200

Hmm, I have the same problem:

platform.ini

[env]
framework = arduino
platform = https://github.com/maxgerhardt/platform-nordicnrf52
monitor_speed = 115200

[env:xiaoble_adafruit]
board = xiaoble_adafruit

main.cpp

#include <Arduino.h>

// google suggested this one. It helps on the compiler, but does not yield anything in the serial monitor
//#include "Adafruit_TinyUSB.h"

void setup() {
  Serial.begin(115200);
  pinMode(LED_BUILTIN, OUTPUT);
}

void loop() {
  Serial.println("hello world");
  digitalWrite(LED_BUILTIN, ! digitalRead(LED_BUILTIN));
  delay(500);
}

Compiler cant find Serial

.pio/build/xiaoble_adafruit/src/main.cpp.o: In function `setup':
main.cpp:(.text.setup+0x8): undefined reference to `Adafruit_USBD_CDC::begin(unsigned long)'
main.cpp:(.text.setup+0x18): undefined reference to `Serial'
.pio/build/xiaoble_adafruit/src/main.cpp.o: In function `loop':
main.cpp:(.text.loop+0x2c): undefined reference to `Serial'
collect2: error: ld returned 1 exit status
*** [.pio/build/xiaoble_adafruit/firmware.elf] Error 1

If I use the mbed variant it will compile, but then I am not able to get into the 5uA region when sleeping in delay()

As code hints, I have including the Adafruit_TinyUSB.h, bit it didn’t really help

This is correct.

Try further adding

monitor_dtr = 1

(or 0) to the platformio.ini, it might unblock the serial monitor.