# Micro:bit multiple "serial on data recieved" don't work properly (only the last one works)

**URL:** <https://forum.makecode.com/t/micro-bit-multiple-serial-on-data-recieved-dont-work-properly-only-the-last-one-works/43793>\
**Category:** micro:bit\
**Created:** [May 2, 2026, 3:46am UTC](https://forum.makecode.com/t/micro-bit-multiple-serial-on-data-recieved-dont-work-properly-only-the-last-one-works/43793 "2026-05-02T03:46:45Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Peteer](https://avatars.discourse-cdn.com/v4/letter/p/f14d63/32.png) [@Peteer](https://forum.makecode.com/u/Peteer)\
**Post date:** [May 2, 2026, 3:46am UTC](https://forum.makecode.com/t/micro-bit-multiple-serial-on-data-recieved-dont-work-properly-only-the-last-one-works/43793/1 "2026-05-02T03:46:45Z")

</div>

Unless I’m doing something wrong here - when I use multiple `serial.onDataReceived` only the last one actually works. The `serial.readString()` I was using clearly shows that both the `#` and `$` sign get sent over serial and get properly received, but only the LAST `serial.onDataReceived` with a `.` actually works.

[https://youtu.be/2iKxum5Tk4A](https://youtu.be/2iKxum5Tk4A) (I press each key at least 3 times)

Here’s the code ifrom the video:

```auto
serial.onDataReceived(serial.delimiters(Delimiters.Dollar), function () {
    basic.showLeds(`
        . . . . .
        . # . . .
        # # # # #
        . # . . .
        . . . . .
        `)
    basic.pause(1000)
    basic.clearScreen()
})
input.onButtonPressed(Button.AB, function () {
    serial.writeLine("A")
})
serial.onDataReceived(serial.delimiters(Delimiters.Hash), function () {
    basic.showLeds(`
        . . # # #
        . . # # #
        . . # # #
        . . . . .
        . . . . .
        `)
    basic.pause(1000)
    basic.clearScreen()
})
serial.onDataReceived(serial.delimiters(Delimiters.Fullstop), function () {
    basic.showIcon(IconNames.Sword)
    basic.pause(1000)
    basic.clearScreen()
})
basic.forever(function () {
    basic.showString(serial.readString())
})

```

---

<div class="post-metadata">

**Author:** ![martinwork](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/martinwork/32/3977_2.png) [@martinwork](https://forum.makecode.com/u/martinwork)\
**Post date:** [May 9, 2026, 7:23pm UTC](https://forum.makecode.com/t/micro-bit-multiple-serial-on-data-recieved-dont-work-properly-only-the-last-one-works/43793/2 "2026-05-09T19:23:01Z")

</div>

Yes, I think you’re right. Looking at the code, each handler block overwrites the same delimiter string, and the same pointer to the event’s handler.

It’s the same for Bluetooth UART: [https://forum.makecode.com/t/bluetooth-uart-command-to-move-servo-only-work-in-one-direction/29202](https://forum.makecode.com/t/bluetooth-uart-command-to-move-servo-only-work-in-one-direction/29202)

> <https://github.com/microsoft/pxt-microbit/blob/master/libs/core/serial.cpp#L84>

[https://github.com/microbit-foundation/codal-core/blob/master/source/driver-models/Serial.cpp#L932](https://github.com/microbit-foundation/codal-core/blob/master/source/driver-models/Serial.cpp#L932)

> <https://github.com/microsoft/pxt-common-packages/blob/master/libs/base/core.cpp#L33>

---

<div class="post-metadata">

**Author:** ![Peteer](https://avatars.discourse-cdn.com/v4/letter/p/f14d63/32.png) [@Peteer](https://forum.makecode.com/u/Peteer)\
**Post date:** [May 16, 2026, 8:57pm UTC](https://forum.makecode.com/t/micro-bit-multiple-serial-on-data-recieved-dont-work-properly-only-the-last-one-works/43793/3 "2026-05-16T20:57:48Z")

</div>

So is this fixable in any way?

---

<div class="post-metadata">

**Author:** ![martinwork](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/martinwork/32/3977_2.png) [@martinwork](https://forum.makecode.com/u/martinwork)\
**Post date:** [May 20, 2026, 5:06pm UTC](https://forum.makecode.com/t/micro-bit-multiple-serial-on-data-recieved-dont-work-properly-only-the-last-one-works/43793/4 "2026-05-20T17:06:42Z")

</div>

What do you want the project to do?

---

<div class="post-metadata">

**Author:** ![martinwork](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/martinwork/32/3977_2.png) [@martinwork](https://forum.makecode.com/u/martinwork)\
**Post date:** [May 22, 2026, 7:35pm UTC](https://forum.makecode.com/t/micro-bit-multiple-serial-on-data-recieved-dont-work-properly-only-the-last-one-works/43793/5 "2026-05-22T19:35:33Z")

</div>

I think this behaves the same as the original intended.

> **[test-serial](https://makecode.microbit.org/81522-49439-87064-92329)**
>
> Made with ❤️ in Microsoft MakeCode for micro:bit.

If you don’t want inputs to queue up (as they would with data received events too), how to decide which inputs to use?

The last?

> **[test-serial2](https://makecode.microbit.org/92641-16644-94137-59221)**
>
> Made with ❤️ in Microsoft MakeCode for micro:bit.

Or the first?

> **[test-serial3](https://makecode.microbit.org/52609-10847-95974-99511)**
>
> Made with ❤️ in Microsoft MakeCode for micro:bit.

---

<div class="post-metadata">

**Author:** ![Peteer](https://avatars.discourse-cdn.com/v4/letter/p/f14d63/32.png) [@Peteer](https://forum.makecode.com/u/Peteer)\
**Post date:** [May 26, 2026, 2:09am UTC](https://forum.makecode.com/t/micro-bit-multiple-serial-on-data-recieved-dont-work-properly-only-the-last-one-works/43793/6 "2026-05-26T02:09:01Z")

</div>

I wanted to control a computer by sending and receiving serial commands from the micro:bit to and from the computer. I ended up working around the issue by just ending everything with a dot, still pretty annoying since it’s a bit of a rigid system

---

<div class="post-metadata">

**Author:** ![martinwork](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/martinwork/32/3977_2.png) [@martinwork](https://forum.makecode.com/u/martinwork)\
**Post date:** [May 31, 2026, 7:55pm UTC](https://forum.makecode.com/t/micro-bit-multiple-serial-on-data-recieved-dont-work-properly-only-the-last-one-works/43793/7 "2026-05-31T19:55:20Z")

</div>

I think one separator is probably a good idea. If it was possible to have 3 independent event handlers, it could get tricky to ensure they read their bit from the serial buffer - e.g. by calling them in the right order.

Similarly, when writing to serial from multiple loops/handlers, only one can write at a time. If a call has to wait for the serial to send, other loop/handlers will run, and serial writes from them will just return, and the output will be lost. I think micro:bit V1 always waits for the output to send, and V2 waits when the send buffer is full.
