SERIAL output lossy?

Hi, I’m trying to build a data logger (Windows app) that reads serial output from a micro:bit via COM port and pipes it directly into Excel. The app works, but the data arriving from the micro:bit appears lossy. Is this something I am doing wrong?

This is the raw data I am receiving from the micro:bit, but there should be 3 values every time:

RAW: b’1532.37,\r\n’ --1 value

RAW: b’1535.86,1,1\r\n’ – correct 3 values

RAW: b’1539.241,1\r\n’ --2 values (3 but the comma is missing)

RAW: b’1540.931,1\r\n’ --2 values (3 but the comma is missing)

input.onButtonPressed(Button.A, function () {
datalogger.log(
datalogger.createCV(“CardType”, 1),
datalogger.createCV(“Stock”, 1)
)
stock += 1
basic.showNumber(stock)
})

input.onButtonPressed(Button.B, function () {
datalogger.deleteLog()
stock = 0
basic.showIcon(IconNames.Yes)
})

let stock = 0
serial.setTxBufferSize(128)
serial.redirectToUSB()
datalogger.setColumnTitles(“CardType”, “Stock”)
datalogger.includeTimestamp(FlashLogTimeStampFormat.Seconds)
datalogger.mirrorToSerial(true)
basic.showNumber(stock)

The missing data is being “stolen” by MakeCode’s WebUSB connection.

After using Download to transfer the program via WebUSB, MakeCode remains connected, and you can see the serial data in MakeCode by clicking “Show data Device”.

To receive serial data in another program, close MakeCode or use Disconnect on the Download button three dots menu.

Data logging serial mirroring can lose data

https://github.com/lancaster-university/codal-microbit-v2/issues/167

As data is added to flash memory, every 4K there is a need to erase a new memory page, which causes a 100ms delay, during which serial data can be lost.

Datalogger serial mirroring is OK for monitoring, but it may currently be best to avoid using it for actual data collection.

Perhaps turn off mirroring, and send serial data separately, after the datalogger.log call.

Some other things to watch out for…

When MakeCode is WebUSB connected, connecting the USB with MakeCode open, or opening or switching to a MakeCode browser tab, may trigger micro:bit to reset, which will reset time to zero.

The USB cable must be reconnected to see updated datalogger data in the MY_DATA file.

Avoid non-ASCII (e.g. accented) characters in datalogging data or column titles.

https://github.com/lancaster-university/codal-microbit-v2/issues/432