CircuitPython makes programming easy by removing the need for a dedicated editor, and the need to compile the code. All you need to start programming is a text editor! There are some great free editors for CircuitPython that make coding even easier. We recommend Mu for editing in CircuitPython. Mu is free and easy to use, and it has a built-in serial monitor so interacting with your code in real time is very easy. As if that wasn’t enough Mu is made to be compatible with the Circuit Playground express and it works great. It also has an error checking option that gives easy to understand explanations of errors in your code! We will be using Mu in our CircuitPython Tutorials.

Transcript

Hi, Steven here Core Electronics. I'm here today to talk to you about Circuit Python for the Adafruit Circuit Playground Express. Circuit python is a cool new language based on Python, that's built specifically for microcontrollers and some of the great things about Circuit Python, is it doesn't need an editor like most programming languages you don't need to compile the code, everything's super simple you can program with just a board and a text editor on your computer and away you go. So today we're going to learn how to load Circuit Python on to your Circuit Playground Express and make a simple code that allows your lights to light up on the board, with a press of the two onboard buttons.

Now the first thing that you need to do to use Circuit Python on your Circuit Playground Express is to download a UF2 file, which is like the program file or firmware for your board. On our introducing Circuit python tutorial page, we have a link to the latest Circuit python UF2 and that will take you to Adafruit’s website and they have the most current link to the Circuit Python UF2 the latest stable version, so download that and the next step is to update the libraries on your Circuit Playground Express. Most Circuit Playground Express is ship with libraries, but it's always good to update them, the libraries that come on the board aren't the complete suite of libraries and it is important to make your code work. So, the link for the latest stable release of the library bundle is also available in this tutorial, it will take you to the Adafruit Circuit python home page. Where they link to the latest out fruit Circuit python library bundle release is.

So, the first step to putting our UF2 file onto our Circuit Playground Express, is to enter bootloader mode. So we double press on the reset button in the middle of the board, notice we have a circle of green lights that means that we're connected properly, so once we double press on the reset buttons and the lights have turned green, we can go to our this PC or my computer depending on the Windows version you have and see we have a device and drive hub CPLAYBOOT, now in our downloads folder we have the latest out of fruit Circuit Playground Circuit Python UF2 file and we just drag that into our CPLAYBOOT and now it's loaded on the board and the drive changes to Circuit python. So, we can see it there, device is in drive, Circuit Python, then that's the drive up the board itself and we can open that up and see all the files that are on it currently.

Now this is our library bundle that we download as well, it comes as a zip, so you'll need to extract it and once it's extracted there'll be a library folder in it and in that library folder, is all these library files that you can use while you're programming in Circuit python. On your Circuit Playground Express Drive, there is a library folder as well, if there's not a library folder just create your own title it all lowercase "lib" and put your libraries in there it'll work just fine.

So, we already have our libraries updated on this board but if you didn't, you can just select everything drag it over and copy it into the library folder of your drive and replace anything that's already there, since this will all be the latest version. On other boards you might need to be careful and you can choose which libraries you include because it's not enough storage but in the Circuit Playground Express, there's two megabytes of storage and there's more than enough room to stick all these libraries and other files that you need without running out of space. So, we'll just drag them all and not worry about the things that we're not going to use.

So now we have our libraries installed on the Circuit Playground Express we have our UF2 file loaded, so we're ready to code. A word about editors for Circuit Python, you don't necessarily need an editor, you can just use a regular text editor like notepad if you want, you don't need to compile your code, you just need to title your file main.py and drop it into your Circuit Playground Express Drive, however we use the editor MU and it's a great editor, it's made to interface with the Circuit Playground Express specifically and it has a built-in serial monitor, which is really nice when it comes to troubleshooting a mistake in your code.

So we open up MU this is the basic interface for MU it's a free program you can download and the first step to editing some code is to it load and if your Circuit Playground Express is connect to the computer, it will automatically open up that drive and if not you can just navigate to it and open main.py and this is where your code lives on the Circuit Playground Express. Whatever code you make it, needs to be toggled main.py, for the board to recognize it and know that that's what it needs to run.

So, we have here the code for the button press already loaded on to it and I'll just give you a quick run-through of what's going on. At the top of every code in Circuit Python, we have our import libraries. So first, import a library for the circle Playground Express or CPX and this says from and then import and that's because the CPX library 0is in a folder, and this is the only one really this in a folder, that you'll need to use regularly. So just leap from Adafruit Circuit program Express is the folder and then import the library and then we import the Neopixel libraries, so we can use the Neopixels on the board and we import board, so we can interface with the buttons on the board.

The next chunk of code we have here, sets up our Neopixels. So it just defines the pixels on the forward, identifies that there's ten of them, sets the brightness and this is one being full bright and decimal points smaller being less bright and we don't really see brightness linearly, so setting it to 0.5 doesn't make it seem half as bright that seems a little more than that, but it drops off the lower you get and we have Auto right to false and this is a command for Neopixels. Circuit python will send the data to every line that has something related to Neopixels and we want it to wait till it gets to the bottom of the section before it sends that data out, just to keep our code running smoothly. It wouldn't be much of an issue on a simple code like this but on a big program it could really bog it down. So, we have written turned auto write to pulse and when you do auto write false you need to have a pixel. Show command, to send that data to the pixels. Also, here we have a pixel spill, to turn all the pixels off and then this show sends that data to the pixels.

In our main body of the code and our while if true loop, we have two if statements and this is one of the ways that Circuit Python really makes coding simpler and easier. Is that normally you'd have to have a little bit more of a statement here within your if. but in Circuit Python we just need to say if and then include the button and then the if true part, is assumed basically. So, if the CPX button B is true so if that's pressed and it will run the code that's in this hanging indent and Circuit Python organizes all its code by indents. Which is something that's just a more way to keep organized and normal code this is in Circuit Python, it's how it knows what's within that "if" statement. So, no curly Q brackets needed. Just in hanging in the in debt.

So, if the Circuit Playground Express Button B is pressed, then we'll print a button B is pressed statement into the serial monitor and then we'll set pixel zero through four to the red. So, the 255 the values can be between 0 and 255 for RGV. So, we have red set 255 in all these Neopixels and this is a reminder that the pixels on the board start from zero at the USB port and go counter clockwise up to nine for 10 totals.

Then we have the if statement for button a which is the same CPX stop button A. We'll send a text string to the serial monitor, that button A is pressed and line up the five lights on the other side, for blue and then at the end of our if statements, we have pixels show, this so this is when the data that we've set our pixels to is sent to the Neopixels and then a fill to send them back to zero if the buttons aren't pressed anymore.

So just to give a demonstration with this serial monitor, our EPL as the serial monitor will hit the control D to reload it and as you can see, when we get the A button we have button is pressed appear once for every time the code loops through and the same thing for button B and if I'm pushing a both show up and in order to put it onto the board we just hit save. Now the main.PY, is saved directly to the drive and any changes we've made to the code are now on the board already it, automatically reboots it only takes a few seconds and you're back to testing again.

So this makes prototyping or trying new things in your code really quick, because you can make a change the code say we want to set the brightness to half we hit save and then it reboots and now our brightness is at half already and maybe half isn't enough so we wanted it point one its save again and then as you can see the lights are substantially dimmer.

That concludes our overview of Circuit python for the Circuit Playground Express. Check out our tutorials section for more tutorials on this Circuit Playground Express, Circuit Python and other ways to program with a certain Playground Express like MakeCode.

Thanks for watching.

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.