Knowing what a microcontroller is and how to use one is an important step in understanding programming for devices.
Many devices have small computers built into them. For example, a car has many separate computers to control driving, safety and climate. Each of these small computers is a microcontroller.
What is a Microcontroller?
A microcontroller acts like a mini computer. It is a device that can take in code and perform actions. Devices from refrigerators to robots may use these small computers to control actions.
How do Microcontrollers Work?
Microcontrollers act on programs that people write. They translate the code to device actions.
How to get started with microcontrollers
There are many microcontrollers that individuals can purchase and program to learn more about how they work. If you would like to get started, this article of the, Best Microcontrollers For Beginners, from MakeUseOf, is a good read.
We will describe the Circuit Playground Express (CPE) board here.
What is a Circuit Playground Express, and What Can It Do?
A Circuit Playground Express (CPX) board is a microcontroller with an assortment of built-in electronics. CPX understands a programming language that uses readymade coding blocks to create instructions. This allows beginners to program the microcontroller with ease.
The CPX board can do multiple actions. It can take in data from different types of inputs like built-in buttons, sensors, and switches. It can also use those inputs to output actions via lights and speakers. The CPX board also contains 14 different capacitive pads that you can wire different electronics too. These pads can send electricity when touched by a wire or finger, which will allow the CPX board to interact with electronics such as motors and light strips.
How to Code the CPX Board?
In order to write a program for the Circuit Playground Express board, we use an app called “Microsoft MakeCode for the Circuit Playground Express”. Download MakeCode on a Windows computer at the Microsoft store. Alternately, access it using a web browser at makecode.adafruit.com.
Creating the Program
Below is a MakeCode program that causes the CPX Board to display a white light when the room is dark, and a red light when the room is bright, using the light sensor. Click the blue New Project button on the left side of the screen to get started.
After creating a new program, drag the On Light block in the Input code block section. Do this two times.
In the on Light block, there is a dropdown menu which has a bright or dark options depending on the application. If the CPX Board action is to do something in a dark room, use the dark option. If the board action is to do something is a bright room, select the bright option. Make one of the two code blocks bright, and the other dark.
Next, grab two of the set all pixels to blocks from the lights section. Make sure to change the color to red for the on light bright block, and to white for the on light dark block.
Once finished, click the Magenta colored Download button on the bottom left side of the screen. The program will be downloaded and instructions will popup.
After the MakeCode program is downloaded, plug a micro USB cable into both the CPX board and the computer. Press the RESET button on the CPX board to allow it to go into programming mode. The RESET button is a tiny button in the center of the board. When the LEDs on the board turn green, the program can be uploaded to the board.
There should be a drive that says CPLAYBOOT in your laptop’s file manager. Drag the program file into this drive. The drive will disappear and the program will begin. If you want to upload a brand new file, simply hit the tiny RESET button and do the same uploading steps above.
The program will run when you press the button or switch that is the trigger for the action.
If you would like help with this process, just call or email and we’ll be happy to assist you! If you have specific questions, or if our terminology isn’t clear, please use our contact form to send us a message. Thank you!