Search code examples
pythonmicropythonbbc-microbit

I get AttributeError on micro:bit examples


I have been trying the micro:bit radio examples but I can't get them to work as explained in, for example,

radio.send_string("Hello World")

will show the following error

AttributeError: 'module' object has no attribute 'send_string'

However if I use

radio.send("Hello World")

the program works just fine. It happens in a lot of the instructions that are part of the docs, for example when trying to use

input.light_level()

I get

AttributeError: 'function' object has no attribute 'light_level'

but the following, which I cannot find on the docs, works fine

display.read_light_level()

What am I missing?

Edit: I am using the online micro:bit python editor on Chrome


Solution

  • There are two python editors available online which use two different Python libraries.

    1. MakeCode: https://makecode.microbit.org/#editor
    2. https://python.microbit.org/v/2

    It looks like you are using the second editor which is using MicroPython and is documented at: https://microbit-micropython.readthedocs.io/