To start with we need to set up your micro:bit so that it can be programmed with MicroPython.

Transcript

Clinton here from Core Electronics. Welcome to part 2 of our workshop on using MicroPython on the Micro:Bit. For this tutorial what we're going to have a look at is getting everything set up and ready to start programming. And the first step in doing that is actually installing the firmware.

So the first thing we're going to do is actually flash the firmware onto the MicroPython. To do this we need to start up the MicroPython in maintenance mode. So if you turn your MicroPython over, on the back there is a switch here that says that's for resetting it. If we hold this switch down, like so, and then insert the micro USB cable while holding it down, you'll notice that it'll pop up. Instead of being Micro:bit as it normally is, it says maintenance. This means that we've started the MicroPython in the mode that lets us make changes to the software running on there.

So now we need to download the actual Micro:bit firmware. So you can find the link for that in the tutorial. So I've already got the page up, so you just scroll down to this download latest Micro:bit firmware. I click download, I go there, I can show in folder, and here I have my downloaded MicroPython firmware. To copy this on and to run this update, all I need to do is copy, drag that straight into the eDrive. This will copy over, and then I wait.

Once the firmware is copied on, the Micro:bit knows what it is, it runs that update, and then returns to us as Micro:Bit. So now we have the latest version, we can check this by just opening this details TXT. So down here, interface version 250, this matches the 250, 0250, so we know that our updates worked. We can now close all this down, because we're now ready to start actually programming on the board, and looking at how we can do that.

Okay, so now we're going to actually look at how to edit code on the Micro:bit using MicroPython. You can do this anyway, so you can write any files you want, any Python files, and copy them over, as long as they're called main.py, copy them into that thumb drive and they'll run. So you can use any editor you would like, anything from Notepad through to Visual Studio.

What we're going to be using today is an editor called Mew, which has been designed to work with the Micro:Bit. to give us a bit of extra features that will be really helpful for debugging and looking at other things. So, if you haven't installed it already, there are links in the tutorial that will let you do that. But so, I've already got it installed here, so I just go to the start menu, I type Mew, and I open it up. Wait a moment.

So, I've already loaded this up before, and so it's remembered my last state and come to MicroPython, Micro:Bit. If you haven't used it before, it will present you with this screen. So you can use this editor for doing CircuitPython with any of the Adafruit products, or the Micro:Bit. the Pygame Zero, or just any normal Python 3 programs.

So, I've got a piece of code already in here. This piece of code will run on any MicroPython board, so it doesn't matter if it's one of these, or an ESP32, or anything else, it will run. We don't need to worry too much, we'll look into it later. So here we have this bar across the top. This basically gives us access to the different functionality we need. We can create new files, we can load files, we can save our work, and we can also flash programs to our Micro:Bit.

Clicking the flash, it doesn't matter what name I have in my file, that will then write that file to the Micro:bit and execute it. It'll change the name on the board so that it will be main.py, so that it will actually run, which is kind of handy. So the next option along after flash, we have the files option, and this lets us explore the file system on the Micro:Bit. We can click on this, and it brings this up. It tells me what files I'm currently working with, and also what files I currently have on my Micro:Bit.

You'll probably notice even if you're not using a file named main.py, on the Micro:bit it will be called main.py. You'll also notice here that these other options have become greyed out. This is because the files has now taken control of the Micro:Bit. and we can't talk to it in any other way at the same time. So to use the next option, we need to click this again, and that will re-enable those other options.

So the next option along is REPL, and this stands for Read Evaluate Print Loop, and this is one of the most useful features you will find out of these. When I click this, my other options grey out, but I'm also presented with this terminal window down the bottom. In here, I can do maths, I can run Python code, and also this will output any code that's running on the board.

So if I were to reset the board by pressing Ctrl D, this soft resets the board, and we can see here, hello I'm Micro:Bit. I can do 16 million things per second. And this is the output of my code. This is incredibly useful when you're trying to debug your MicroPython code. So yeah, this tool you will be using a lot as you're kind of advanced with MicroPython. So I need to then click this again, and then I can start editing and doing other things.

That's everything we need to know for getting started with programming the Micro:bit with New Editor. In the next video, we're going to actually start doing some code and wiring up some circuits. We're going to be using digital inputs and if statements. So I look forward to seeing you in the next video, and thanks again for watching.

Comments


Loading...
Feedback

Please continue if you would like to leave feedback for any of these topics:

  • Website features/issues
  • Content errors/improvements
  • Missing products/categories
  • Product assignments to categories
  • Search results relevance

For all other inquiries (orders status, stock levels, etc), please contact our support team for quick assistance.

Note: click continue and a draft email will be opened to edit. If you don't have an email client on your device, then send a message via the chat icon on the bottom left of our website.

Makers love reviews as much as you do, please follow this link to review the products you have purchased.