I wanna send data from microbit to PC. All the connections work fine. However I find that data is only sent to the computer if the serial write function is written within an event, for example, I use Makecode, and the following two work:
input.onButtonPressed(Button.B, () => {
serial.writeLine("data from micro:bit!")
})
basic.forever(function () {
serial.writeLine("data from micro:bit!")
})
However if I just write one line like this, it doesn't work:
serial.writeLine("data from micro:bit!")
I suspect that the serial write function has to be triggered by something, likely a callback or loop etc? But it seems that the micropython one doesn't have such problem.
Some more background, I'm using Windows 10 and I use the Node.js serialPort package to receive the message. I'm not sure if the environment will affect the behavior.
I appreciate if someone here can share some experience, thank you very much.