# Help Needed converting python code to Makecode

**URL:** <https://forum.makecode.com/t/help-needed-converting-python-code-to-makecode/32654>\
**Category:** micro:bit\
**Created:** [December 22, 2024, 4:03pm UTC](https://forum.makecode.com/t/help-needed-converting-python-code-to-makecode/32654 "2024-12-22T16:03:58Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![dsssssssss9](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/dsssssssss9/32/861_2.png) [@dsssssssss9](https://forum.makecode.com/u/dsssssssss9)\
**Post date:** [December 22, 2024, 4:03pm UTC](https://forum.makecode.com/t/help-needed-converting-python-code-to-makecode/32654/1 "2024-12-22T16:03:58Z")

</div>

HI

I have a device that is controlled via commands sent over serial,

I am trying to convert the existing micro python code to makecode for Microbit but am getting stuck on converting the following code…

uart.write(bytes([0x7E, 0x03, 0x00, 0x02, 0x00, track\_number, 0xEF]))

any help or suggestions gratefully received

---

<div class="post-metadata">

**Author:** ![chedder](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/chedder/32/18905_2.png) [@chedder](https://forum.makecode.com/u/chedder)\
**Post date:** [December 23, 2024, 3:39pm UTC](https://forum.makecode.com/t/help-needed-converting-python-code-to-makecode/32654/2 "2024-12-23T15:39:36Z")

</div>

you could ask chatgpt to do it, other than that idk any other ideas

---

<div class="post-metadata">

**Author:** ![bsiever](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/bsiever/32/1032_2.png) [@bsiever](https://forum.makecode.com/u/bsiever)\
**Post date:** [December 24, 2024, 3:24pm UTC](https://forum.makecode.com/t/help-needed-converting-python-code-to-makecode/32654/3 "2024-12-24T15:24:47Z")

</div>

Hi @dsssssssss9 ,

I haven’t tried this, but I think the JavaScript equivalent would be something like:

```auto
    let track_number = 5;
    let l = pins.createBuffer(8)
    l.setUint8(0, 0x7E);
    l.setUint8(1, 0x03);
    l.setUint8(2, 0x00);
    l.setUint8(3, 0x02);
    l.setUint8(4, 0x00);
    l.setUint8(5, 0x02);
    l.setUint8(6, track_number);
    l.setUint8(7, 0xEF);

    serial.writeBuffer(l)

```

See [https://makecode.microbit.org/S73730-18716-20158-85140](https://makecode.microbit.org/S73730-18716-20158-85140) .

And in Python:

```auto
track_number = 5
    l = bytearray(8)
    l.set_uint8(0, 0x7E)
    l.set_uint8(1, 0x03)
    l.set_uint8(2, 0x00)
    l.set_uint8(3, 0x02)
    l.set_uint8(4, 0x00)
    l.set_uint8(5, 0x02)
    l.set_uint8(6, track_number)
    l.set_uint8(7, 0xEF)
    serial.write_buffer(l)

```

See [https://makecode.microbit.org/S99388-10508-07062-49540](https://makecode.microbit.org/S99388-10508-07062-49540) .

---

<div class="post-metadata">

**Author:** ![dsssssssss9](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/dsssssssss9/32/861_2.png) [@dsssssssss9](https://forum.makecode.com/u/dsssssssss9)\
**Post date:** [December 24, 2024, 9:16pm UTC](https://forum.makecode.com/t/help-needed-converting-python-code-to-makecode/32654/4 "2024-12-24T21:16:43Z")

</div>

Hi

Thanks for the advice …

Will try chatgpt & see what it comes up with

Seasons greetings

---

<div class="post-metadata">

**Author:** ![dsssssssss9](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/dsssssssss9/32/861_2.png) [@dsssssssss9](https://forum.makecode.com/u/dsssssssss9)\
**Post date:** [December 24, 2024, 9:20pm UTC](https://forum.makecode.com/t/help-needed-converting-python-code-to-makecode/32654/5 "2024-12-24T21:20:50Z")

</div>

Hi

works fine - many thanks

had to alter the bytearray slightly due to typo in my original question

Do you think this is possible in purely blocks ??

Also is there a good guide on how to write an extension for MakeCode as would love to let others use this

Many Thanls

---

<div class="post-metadata">

**Author:** ![bsiever](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/bsiever/32/1032_2.png) [@bsiever](https://forum.makecode.com/u/bsiever)\
**Post date:** [December 28, 2024, 2:36pm UTC](https://forum.makecode.com/t/help-needed-converting-python-code-to-makecode/32654/6 "2024-12-28T14:36:30Z")

</div>

Hi @dsssssssss9 ,

Glad you were able to get it to work. I don’t think blocks include all the parts needed, but writing an extension would allow you to provide code in JavaScript and use it from blocks.

I’m not aware of any truly ideal, up-to-date tutorials on extensions, but some resources I’ve used in the past include:

- [GitHub for Extensions](https://www.youtube.com/watch?v=ztrm4XehfGo)
- [Custom blocks](https://www.youtube.com/watch?v=Ku_nHstZS64)
- Look at the GtiHub repos for any extensions that are comparable.
- Previous post here: [Any help or guidance in making my own code blocks for a motor hat - #2 by bsiever](https://forum.makecode.com/t/any-help-or-guidance-in-making-my-own-code-blocks-for-a-motor-hat/17477/2) (A little redundant with the above)
- [MakeCode Blocks Playground](https://makecode.com/playground) for testing the shape/structure of blocks.
- You can join the Slack for the developer community at [https://tech.microbit.org/community/](https://tech.microbit.org/community/) (It has very little traffic though)

I hope that helps a bit!
