I’ve got a question, regarding this documentaton:
In my Microsoft MakeCode Editor it marks me audio as red, because it cannot find any such module, also not in the extensions.
So, this Microsoft gadget is uncomplete, or the documentation is not for the v2?
I would like to use microbit’s own built in speaker. (you can also write an example to use it).
Thanks is advance for your help
There are two different versions of python for the Micro:bit:
- MicroPython, which is what that documentation is from. To use the MicroPython version go to: https://python.microbit.org/v/2 (Not MakeCode)
- MakeCode’s version, which supports different features and has different functions/methods that aren’t usually compatible with the MicroPython version (That is, MakeCode has a different API). MakeCode’s documentation is at Reference. If you click on a palette (like
Basic) and then click on each command (like
For more details on MakeCode’s Python vs. MicroPython see: MakeCode Python and MicroPython
@erkman, there is a simple way to do this with the Micro:bit, and it’s in the
Music Section. The MakeCode Micro:bit Python code will be listed below too.
Open up your MakeCode editor
open up the
Scroll all the way down the
section till you reach the
set built-in speaker <ON/OFF>
block to your
block and set it to
Then attach any music making block and do whatever you want! If you upload this to the Micro:bit V2 it should play the sounds you coded it to run.
The next part is the same code but in the MakeCode Micro:bit Python Editor (you’ll probably find this more useful, since you’re using MicroPython, but just in case other people with this issue come to this post and want the block solution, it’s there for them):
My code, you can use something different if you want.
Hope this helped
Thank you for the information.
This is a lettle pretty sad that the modules are not compatible which each other’s platforms:
For e.x. Bluetooth modul is working for communication through pc via bluezero (I use Ubuntu server 20) only via the for education based makecode website but there is NO split command that works or there is not any break command to break out of any loop.
You have to choose useage between extensions. Ex. Bluetooth or Datetime. If you use them booth in the same script you get an error code of 071 (this code is not doxumented any where).
Yes, I know this gadget is more for education but I thought before using a microcontroller this would be a good entry.
Now I see it is very limited.
Yep @erkman, as you said, the Micro:bit is designed for learning to code with a pre-set microcontroller, maybe consider the Raspberry Pi?
Hi, Yes, I’ve already have a Raspy, my Ubuntu Server is running there, and for me set up a server is much easier than it was for Microbit. But Im an experienced, finally, I got it work, so I see now my server important paramters on the Microbit Screen, with mani warnings (accustic also). So what I have done with Microbit:
My server refresh with its data every minute (there is a cronjob for that):
The microbit shows me server time, there is an alarm clock, show server CPU temp, load and 1-2 extra thing which I can see next to my bed without using the smartphone
The built in speaker is good for acustic notifications for that purpose (scripted in microbit the thresholds for watching) my server is within bluetooth range. Bonus: at night the leds are dimmed automacially adjusted to the months…So my microbit isn’t a toy anymore
@Erkman Your project sounds really cool and I hope you share more details here (maybe create an instructable and/or a video showing it off)!
Some background and updates on what you’ve experienced:
MicroPython, which is a “true” python, uses too much memory to support bluetooth on the V1 microbit. It sounds like work is underway to add bluetooth support to the V2.
MakeCode translates code to native ARM instructions, which leaves enough space for Bluetooth (but just barely enough on the V1). MakeCode chose to use an API that was consistent among the three languages they support (blocks, static TypeScript, and Python). That seems like a reasonable choice to me. I prefer the event handling approach used by MakeCode’s API.
I’m not sure what you mean about
split. It looks like you can
break out of loops in MakeCode and strings do support
A few details about the
datetime module (assuming you’re referring to microbit-pxt-datetime):
It was developed before the V2 existed. There wasn’t enough memory for both
bluetooth on the V1, so using both led to memory errors (020).
It was developed for some specific applications and
bluetooth wasn’t an important feature, although
radio was. You can use serial,
radio, and two micro:bits to “relay” messages without bluetooth. See the Remote Data Collection example. That approach would work with both the V1 and V2.
This is an open source project that the developer (me) does in free time. As with all open source/free projects, there may be imperfections. Other developers are welcome to contribute patches and users are encouraged to share details about problems with the developer(s).
I’ve now updated the code to avoid the 071 (CPU Fault) error:
- I’ve only done one quick test with
bluetooth on a V2 and it seemed to work.
- There still isn’t enough memory for it to work on a V1 with
bluetooth (020 error).
- I ran my non-bluetooth test suites to try to ensure that it continues to work when there isn’t
- I’ll try to do some more testing if/when time permits, but my job is very busy this time of year and leaves little time for this work.
- The latest release is v2.0.23. If you go to the Python view, expand the “Explorer” in the simulator pane, and the hit the refresh button on the module, it should update. Or you can start a new project from scratch, but you should still look at the Explorer to confirm you’re using v2.0.23 or later.
I use the V2 with bluetooth, and it works as expected with very limited funtions. (with bluetooth uart read you get the data )
Yes I maybe I can share, but this is very specific useage of the tools I don’t know if it is interessting anybody.
Thanks for the error code update, I thought it was something with memory because it would be more obviously if running with two modules which are incompatible (why?) with each other.
Yes, I’ve used makecode editor for the bluetooth support (micropython doesn’t have any unfortunately)
I do not know, how you tested, but if you want to import microbit-pxt-datetime and bluetooth in the same project, it seems working in the simulator, but if you deploy your code on the real microbit, then you get this 071 error code on startup, and then you have to choose, which is more important for you…
Maybe there is a split command and break command in micropython (and javascipt also), but in the makecode however it does not work nor effect. I know what I say since I used to use them years ago. Maybe this is a bug, try this, nothing will happen no error codes also:
array_string = “1,2,3,4,5,A”
array_s = array_string.split(",")
for i in range(array_s.length):
Here’s a working example (on the V2) of the
datetime being used with Bluetooth: https://makecode.microbit.org/_hHu51icChhdM
split is finicky and doesn’t work well. I may be good to open an issue on the GitHub repo for
pxt showing your example. That being said, here’s an example that does work:
array_string = ""
array_string = "1,2,3,4,5,A"
for value in array_string.split(","):
serial.write_line("" + (value))
Link to example: https://makecode.microbit.org/_A04TAgD2V3E0
I do not know where the issue is, but look at this:
I’ve put into an existing working example your microbit-pxt-timeanddate extension…
now I get the compile error:
“The hex file is not available, please connect to internet and try again.”
In booth codeeditors: online and Win installed offline version.
So there is something more then a little bug… I saw your example, but please look at my example, and tell me, what went wrong only by include (!) the extension (In the code I did not make any changes).
I’m not exactly sure what’s going on, but here are some things of interest:
- It looks like the backend compiler is timing out. It eventually reports “abandoning C++ build”. (Anyone familiar with the backend compiler??? Any idea what may be going on? Here’s a project that contains just
Bluetooth and another extension with C++ (date-and-time): https://makecode.microbit.org/_A5HDvR1P77Mc )
- The time-and-date extension uses C++ code, which uses a backend compiler. I don’t think it’s accessible in the offline version of MakeCode.
- Something is a little wrong with your project, but it’s not the cause of this error.
Radio should be mutually exclusive, but your project seems to include both. Normally when you add
Radio blocks are removed.
Sorry I don’t have any immediate solutions. I’ll try to provide more of an update when I have a better understanding of the issue. I think either the compiler is timing out too quickly or there is some unusual compilation problem.
@erkman I’m not sure what’s changed, but it appears to work fine now. I just:
- Created a new project.
- Added the
- Added the
Time and Date extension
- Hit Download and it worked
Everything appeared to work.
After that I updated the code to ensure the time was usable and to change how some things are being done. My updated version seems ok on a v2 micro:bit (v1 doesn’t have enough memory for it to run correctly). Here it is: https://makecode.microbit.org/_4k01JmPXfU3s
I have a V2.
may be interpreting python code is a problem? Next issue I faced today (there is a github msg for that also): I fed up with the software rtc so I bought a kitronic klimate board which has real rtc module, fitting for me (not the extra costs), so I set it up, worked like a charm, but next error: import this extension with bluetooth, now I had remaing approx 260 lines of code (!) The thruth was, I had already pre-code more then 300 lines of code (yes, only remainging bytes are shown in the error msg, so I tried to figure out how many code can be pleaced in the script… and then compacting shorting variables, remove unnececary but nice to have gadgets in the code itself.
So that’s all, but now, I re focus on my microcontroller boards, in the meantime I’ve succcessfully set up a TTO T-Call ESP32 with PIR motion alarm. I rather say that one was much easier than microbit.
Yes, I accept, this is more a learning tool for kids between 6-12, but the bluetooth feature was to impressive, I cannot withstand to try out, but reached the limits very fast.
But V2 should have more abilities then V1., combine the extensions should be possible without any issues I think and not causing memory, or any problems. (or the basic concept and kernel is not finetuned).
Now the Microbit does it’s work, but I won’t say, I’ve planned that it consume so much time.
Thank you for your help and care, the future generation needs this