If you are using one of our not-recommended-editors, not all is lost! You can still make
it work.
On Windows, you can Eject or Safe Remove the CIRCUITPY drive. It won't actually
eject, but it will force the operating system to save your file to disk. On Linux, use the
sync command in a terminal to force the write to disk.
You also need to do this if you use Windows Explorer or a Linux graphical file
manager to drag a file onto CIRCUITPY.
Oh No I Did Something Wrong and Now The CIRCUITPY
Drive Doesn't Show Up!!!
Don't worry! Corrupting the drive isn't the end of the world (or your board!). If this
happens, follow the steps found on the Troubleshooting(https://adafru.it/Den) page
of every board guide to get your board up and running again.
Back to Editing Code...
Now! Let's try editing the program you added to your board. Open your code.py file
into your editor. You'll make a simple change. Change the first 0.5 to 0.1 . The code
should look like this:
import board
import digitalio
import time
led = digitalio.DigitalInOut(board.LED)
led.direction = digitalio.Direction.OUTPUT
If nothing appears in the serial console, it may mean your code is done running
or has no print statements in it. Click into the serial console part of Mu, and press
CTRL+D to reload.
Serial Console Issues or Delays on Linux
If you're on Linux, and are seeing multi-second delays connecting to the serial
console, or are seeing "AT" and other gibberish when you connect, then the modemma
nager service might be interfering. Just remove it; it doesn't have much use unless
you're still using dial-up modems.
To remove modemmanager , type the following command at a shell:
sudo apt purge modemmanager
Setting Permissions on Linux
On Linux, if you see an error box something like the one below when you press the S
erial button, you need to add yourself to a user group to have permission to connect
to the serial console.
On Ubuntu and Debian, add yourself to the dialout group by doing:
sudo adduser $USER dialout
After running the command above, reboot your machine to gain access to the group.
On other Linux distributions, the group you need may be different. See the Advanced
The Traceback (most recent call last): is telling you the last thing your board
was doing before you saved your file. This is normal behavior and will happen every
time the board resets. This is really handy for troubleshooting. Let's introduce an error
so you can see how it is used.
Delete the e at the end of True from the line led.value = True so that it says le
d.value = Tru
import board
import digitalio
import time
led = digitalio.DigitalInOut(board.LED)
led.direction = digitalio.Direction.OUTPUT
while True:
print("Hello back to you!")
led.value = Tru
time.sleep(1)
led.value =False
time.sleep(1)
Save your file. You will notice that your red LED will stop blinking, and you may have a
colored status LED blinking at you. This is because the code is no longer correct and
can no longer run properly. You need to fix it!
Usually when you run into errors, it's not because you introduced them on purpose.
You may have 200 lines of code, and have no idea where your error could be hiding.
This is where the serial console can help. Let's take a look!
The Traceback (most recent call last): is telling you that the last thing it was
able to run was line 10 in your code. The next line is your error: NameError: name
'Tru' is not defined . This error might not mean a lot to you, but combined with
knowing the issue is on line 10, it gives you a great place to start!
To use the REPL, you first need to be connected to the serial console. Once that
connection has been established, you'll want to press CTRL+C.
If there is code running, in this case code measuring distance, it will stop and you'll
see Press any key to enter the REPL. Use CTRL-D to reload. Follow those
instructions, and press any key on your keyboard.
The Traceback (most recent call last): is telling you the last thing your board
was doing before you pressed Ctrl + C and interrupted it. The KeyboardInterrupt
is you pressing CTRL+C. This information can be handy when troubleshooting, but for
now, don't worry about it. Just note that it is expected behavior.
If your code.py file is empty or does not contain a loop, it will show an empty output
and Code done running. . There is no information about what your board was
doing before you interrupted it because there is no code running.
If you have no code.py on your CIRCUITPY drive, you will enter the REPL immediately
after pressing CTRL+C. Again, there is no information about what your board was
doing before you interrupted it because there is no code running.
Regardless, once you press a key you'll see a >>> prompt welcoming you to the
REPL!
If you have trouble getting to the >>> prompt, try pressing Ctrl + C a few more times.
The first thing you get from the REPL is information about your board.
This line tells you the version of CircuitPython you're using and when it was released.
Next, it gives you the type of board you're using and the type of microcontroller the
board uses. Each part of this may be different for your board depending on the
versions you're working with.
This is followed by the CircuitPython prompt.
Interacting with the REPL
From this prompt you can run all sorts of commands and code. The first thing you'll do
is run help() . This will tell you where to start exploring the REPL. To run code in the
First part of the message is another reference to the version of CircuitPython you're
using. Second, a URL for the CircuitPython related project guides. Then... wait. What's
this? To list built-in modules type `help("modules")`. Remember the
modules you learned about while going through creating code? That's exactly what
this is talking about! This is a perfect place to start. Let's take a look!
Type help("modules") into the REPL next to the prompt, and press enter.
This is a list of all the core modules built into CircuitPython, including board .
Remember, board contains all of the pins on the board that you can use in your
code. From the REPL, you are able to see that list!
Type import board into the REPL and press enter. It'll go to a new prompt. It might
look like nothing happened, but that's not the case! If you recall, the import
statement simply tells the code to expect to do something with that module. In this
case, it's telling the REPL that you plan to do something with that module.
Next, type dir(board) into the REPL and press enter.
This is a list of all of the pins on your board that are available for you to use in your
code. Each board's list will differ slightly depending on the number of pins available.
Do you see LED ? That's the pin you used to blink the red LED!
In the Interacting with the REPL section(https://adafru.it/Awz) on The REPL page(http
s://adafru.it/Awz) in this guide, the help("modules") command is discussed. This
command provides a list of all of the built-in modules available in CircuitPython for
your board. So, if you connect to the serial console on your board, and enter the
REPL, you can run help("modules") to see what modules are available for your
board. Then, as you read through the import statements, you can, for the purposes
of figuring out which libraries to load, ignore the statement that import modules.
The following is the list of modules built into CircuitPython for the Feather RP2040.
Your list may look similar or be anything down to a significant subset of this list for
smaller boards.
Now that you know what you're looking for, it's time to read through the import
statements. The first two, time and board , are on the modules list above, so they're
built-in.
The next one, neopixel , is not on the module list. That means it's your first library!
So, you would head over to the bundle zip you downloaded, and search for neopixel.
There is a neopixel.mpy file in the bundle zip. Copy it over to the lib folder on your CI
RCUITPY drive. The following one, adafruit_lis3dh , is also not on the module list.
Follow the same process for adafruit_lis3dh, where you'll find adafruit_lis3dh.mpy,
and copy that over.
The fifth one is usb_hid , and it is in the modules list, so it is built in. Often all of the
built-in modules come first in the import list, but sometimes they don't! Don't assume
that everything after the first library is also a library, and verify each import with the
modules list to be sure. Otherwise, you'll search the bundle and come up empty!
The final two imports are not as clear. Remember, when import statements are
formatted like this, the first thing after the from is the library name. In this case, the
library name is adafruit_hid . A search of the bundle will find an adafruit_hid folder.
When a library is a folder, you must copy the entire folder and its contentsas it is in
the bundle to the lib folder on your CIRCUITPY drive. In this case, you would copy the
entire adafruit_hid folder to your CIRCUITPY/lib folder.
Notice that there are two imports that begin with adafruit_hid . Sometimes you will
need to import more than one thing from the same library. Regardless of how many
times you import the same library, you only need to load the library by copying over
the adafruit_hid folder once.
That is how you can use your example code to figure out what libraries to load on
your CircuitPython-compatible board!
There are cases, however, where libraries require other libraries internally. The
internally required library is called a dependency. In the event of library
dependencies, the easiest way to figure out what other libraries are required is to
connect to the serial console and follow along with the ImportError printed there.
The following is a very simple example of an ImportError , but the concept is the
same for any missing library.
Example: ImportError Due to Missing Library
If you choose to load libraries as you need them, or you're starting fresh with an
existing example, you may end up with code that tries to use a library you haven't yet
loaded. This section will demonstrate what happens when you try to utilise a library
that you don't have loaded on your board, and cover the steps required to resolve the
issue.
This demonstration will only return an error if you do not have the required library
loaded into the lib folder on your CIRCUITPY drive.
Let's use a modified version of the Blink example.
import board
import time
import simpleio
led = simpleio.DigitalOut(board.LED)
while True:
led.value = True
time.sleep(0.5)
led.value = False
time.sleep(0.5)
Save this file. Nothing happens to your board. Let's check the serial console to see
what's going on.
You have an ImportError . It says there is no module named 'simpleio' . That's
the one you just included in your code!
Click the link above to download the correct bundle. Extract the lib folder from the
downloaded bundle file. Scroll down to find simpleio.mpy. This is the library file you're
looking for! Follow the steps above to load an individual library file.
The LED starts blinking again! Let's check the serial console.
No errors! Excellent. You've successfully resolved an ImportError !
If you run into this error in the future, follow along with the steps above and choose
the library that matches the one you're missing.
Library Install on Non-Express Boards
If you have an M0 non-Express board such as Trinket M0, Gemma M0, QT Py M0, or
one of the M0 Trinkeys, you'll want to follow the same steps in the example above to
install libraries as you need them. Remember, you don't need to wait for an ImportE
rror if you know what library you added to your code. Open the library bundle you
downloaded, find the library you need, and drag it to the lib folder on your CIRCUITPY
drive.
You can still end up running out of space on your M0 non-Express board even if you
only load libraries as you need them. There are a number of steps you can use to try
My RGB NeoPixel/DotStar LED is blinking funny colors what does it mean?
The status LED can tell you what's going on with your CircuitPython board. Read
more here for what the colors mean!(https://adafru.it/Den)
What is a MemoryError?
Memory allocation errors happen when you're trying to store too much on the
board. The CircuitPython microcontroller boards have a limited amount of memory
available. You can have about 250 lines of code on the M0 Express boards. If you
try to import too many libraries, a combination of large libraries, or run a program
with too many lines of code, your code will fail to run and you will receive a
MemoryError in the serial console.
What do I do when I encounter a MemoryError?
Try resetting your board. Each time you reset the board, it reallocates the memory.
While this is unlikely to resolve your issue, it's a simple step and is worth trying.
Make sure you are using .mpy versions of libraries. All of the CircuitPython libraries
are available in the bundle in a .mpy format which takes up less memory than .py
format. Be sure that you're using the latest library bundle(https://adafru.it/uap) for
your version of CircuitPython.
If that does not resolve your issue, try shortening your code. Shorten comments,
remove extraneous or unneeded code, or any other clean up you can do to
shorten your code. If you're using a lot of functions, you could try moving those
into a separate library, creating a .mpy of that library, and importing it into your
code.
You can turn your entire file into a .mpy and import that into code.py. This means
you will be unable to edit your code live on the board, but it can save you space.
Can the order of my import statements affect memory?
It can because the memory gets fragmented differently depending on allocation
order and the size of objects. Loading .mpy files uses less memory so its
recommended to do that for files you aren't editing.
From time to time, you will run into issues when working with CircuitPython. Here are
a few things you may encounter and how to resolve them.
As CircuitPython development continues and there are new releases, Adafruit
will stop supporting older releases. Visit https://circuitpython.org/downloads to
download the latest version of CircuitPython for your board. You must download
the CircuitPython Library Bundle that matches your version of CircuitPython.
Please update CircuitPython and then visit https://circuitpython.org/libraries to
download the latest Library Bundle.
Always Run the Latest Version of
CircuitPython and Libraries
As CircuitPython development continues and there are new releases, Adafruit will
stop supporting older releases. You need to update to the latest CircuitPython.(https:
//adafru.it/Em8).
You need to download the CircuitPython Library Bundle that matches your version of
CircuitPython. Please update CircuitPython and then download the latest bundle(http
s://adafru.it/ENC).
As new versions of CircuitPython are released, Adafruit will stop providing the
previous bundles as automatically created downloads on the Adafruit CircuitPython
Library Bundle repo. If you must continue to use an earlier version, you can still
download the appropriate version of mpy-cross from the particular release of
CircuitPython on the CircuitPython repo and create your own compatible .mpy library
files. However, it is best to update to the latest for both CircuitPython and the library
bundle.
I have to continue using CircuitPython 5.x or earlier.
Where can I find compatible libraries?
Adafruit is no longer building or supporting the CircuitPython 5.x or earlier library
bundles. You are highly encourged to update CircuitPython to the latest version(http
s://adafru.it/Em8) and use the current version of the libraries(https://adafru.it/ENC).
you have probably seen higher and higher COM port numbers used, seemingly
without end. This will fix that problem.
Serial Console in Mu Not Displaying
Anything
There are times when the serial console will accurately not display anything, such as,
when no code is currently running, or when code with no serial output is already
running before you open the console. However, if you find yourself in a situation
where you feel it should be displaying something like an error, consider the following.
Depending on the size of your screen or Mu window, when you open the serial
console, the serial console panel may be very small. This can be a problem. A basic
CircuitPython error takes 10 lines to display!
Auto-reload is on. Simply save files over USB to run them or enter REPL to disable.
code.py output:
Traceback (most recent call last):
File "code.py", line 7
SyntaxError: invalid syntax
Press any key to enter the REPL. Use CTRL-D to reload.
More complex errors take even more lines!
Therefore, if your serial console panel is five lines tall or less, you may only see blank
lines or blank lines followed by Press any key to enter the REPL. Use CTRL-D
to reload. . If this is the case, you need to either mouse over the top of the panel to
utilise the option to resize the serial panel, or use the scrollbar on the right side to
scroll up and find your message.
This applies to any kind of serial output whether it be error messages or print
statements. So before you start trying to debug your problem on the hardware side,
be sure to check that you haven't simply missed the serial messages due to serial
This error occurs when importing a module that is stored as a .mpy binary file that
was generated by a different version of CircuitPython than the one its being loaded
into. In particular, the mpy binary format changed between CircuitPython versions 6.x
and 7.x, 2.x and 3.x, and 1.x and 2.x.
So, for instance, if you upgraded to CircuitPython 7.x from 6.x you’ll need to download
a newer version of the library that triggered the error on import . All libraries are
available in the Adafruit bundle(https://adafru.it/y8E).
CIRCUITPY Drive Issues
You may find that you can no longer save files to your CIRCUITPY drive. You may find
that your CIRCUITPY stops showing up in your file explorer, or shows up as NO_NAM
E. These are indicators that your filesystem has issues. When the CIRCUITPY disk is
not safely ejected before being reset by the button or being disconnected from USB,
it may corrupt the flash drive. It can happen on Windows, Mac or Linux, though it is
more common on Windows.
Be aware, if you have used Arduino to program your board, CircuitPython is no longer
able to provide the USB services. You will need to reload CircuitPython to resolve this
situation.
The easiest first step is to reload CircuitPython. Double-tap reset on the board so you
get a boardnameBOOT drive rather than a CIRCUITPY drive, and copy the latest
version of CircuitPython (.uf2) back to the board. This may restore CIRCUITPY
functionality.
If reloading CircuitPython does not resolve your issue, the next step is to try putting
the board into safe mode.
Safe Mode
Whether you've run into a situation where you can no longer edit your code.py on
your CIRCUITPY drive, your board has gotten into a state where CIRCUITPY is read-
only, or you have turned off the CIRCUITPY drive altogether, safe mode can help.
However there are still some cases where hidden files will be created by MacOS. In
particular if you copy a file that was downloaded from the internet it will have special
metadata that MacOS stores as a hidden file. Luckily you can run a copy command
from the terminal to copy files without this hidden metadata file. See the steps below.
Copy Files on MacOS Without Creating Hidden Files
Once you've disabled and removed hidden files with the above commands on macOS
you need to be careful to copy files to the board with a special command that
prevents future hidden files from being created. Unfortunately you cannotuse drag
and drop copy in Finder because it will still create these hidden extended attribute
files in some cases (for files downloaded from the internet, like Adafruit's modules).
To copy a file or folder use the-Xoption for thecpcommand in a terminal. For
example to copy a file_name.mpy file to the board use a command like:
cp -X file_name.mpy /Volumes/CIRCUITPY
(Replace file_name.mpy with the name of the file you want to copy.)
Or to copy a folder and all of the files and folders contained within, use a command
like:
cp -rX folder_to_copy /Volumes/CIRCUITPY
If you are copying to the lib folder, or another folder, make sure it exists before
copying.
#if lib does not exist, you'll create a file named lib !
cp -X file_name.mpy /Volumes/CIRCUITPY/lib
#This is safer, and will complain if a lib folder does not exist.
cp -X file_name.mpy /Volumes/CIRCUITPY/lib/
Other MacOS Space-Saving Tips
If you'd like to see the amount of space used on the drive and manually delete hidden
files here's how to do so. First, move into the Volumes/ directory with cd /Volumes/ ,
and then list the amount of space used on the CIRCUITPY drive with the df
That's not very much space left! The next step is to show a list of the files currently on
the CIRCUITPY drive, including the hidden files, using the ls command. You cannot
use Finder to do this, you must do it via command line!
There are a few of the hidden files that MacOS loves to generate, all of which begin
with a ._ before the file name. Remove the ._ files using the rm command. You can
remove them all once by running rm CIRCUITPY/._* . The * acts as a wildcard to
apply the command to everything that begins with ._ at the same time.
Finally, you can run df again to see the current space used.
Nice! You have 12Ki more than before! This space can now be used for libraries and
code!
Device Locked Up or Boot Looping
In rare cases, it may happen that something in your code.py or boot.py files causes
the device to get locked up, or even go into a boot loop. A boot loop occurs when the
board reboots repeatedly and never fully loads. These are not caused by your
everyday Python exceptions, typically it's the result of a deeper problem within
CircuitPython. In this situation, it can be difficult to recover your device if CIRCUITPY
is not allowing you to modify the code.py or boot.py files. Safe mode is one recovery
// the setup function runs once when you press reset or power the board
void setup() {
// initialize digital pin 13 as an output.
pinMode(13, OUTPUT);
}
// the loop function runs over and over again forever
void loop() {
digitalWrite(13, HIGH); // turn the LED on (HIGH is the voltage level)
delay(1000); // wait for a second
digitalWrite(13, LOW); // turn the LED off by making the voltage LOW
delay(1000); // wait for a second
}
Make sure the LED(s) are still green, then click Upload to upload Blink. Once it has
uploaded successfully, the serial Port will change so re-select the new Port!
Once Blink is uploaded you should no longer need to double-click to enter
bootloader mode. Arduino will automatically reset when you upload.
Next, you set up the LED. To interact with hardware in CircuitPython, your code must
let the board know where to look for the hardware and what to do with it. So, you
create a digitalio.DigitalInOut() object, provide it the LED pin using the boa
rd module, and save it to the variable led . Then, you tell the pin to act as an OUTP
UT .
Finally, you create a while True: loop. This means all the code inside the loop will
repeat indefinitely. Inside the loop, you set led.value = True which powers on the
LED. Then, you use time.sleep(0.5) to tell the code to wait half a second before
moving on to the next line. The next line sets led.value = False which turns the
LED off. Then you use another time.sleep(0.5) to wait half a second before
starting the loop over again.
With only a small update, you can control the blink speed. The blink speed is
controlled by the amount of time you tell the code to wait before moving on using ti
me.sleep() . The example uses 0.5 , which is one half of one second. Try increasing
or decreasing these values to see how the blinking changes.
That's all there is to blinking an LED using CircuitPython!
Digital Input
The CircuitPython digitalio module has many applications. The basic Blink
program sets up the LED as a digital output. You can just as easily set up a digital
input such as a button to control the LED. This example builds on the basic Blink
example, but now includes setup for a button switch. Instead of using the time
module to blink the LED, it uses the status of the button switch to control whether the
Note that the code is a little less "Pythonic" than it could be. It could also be written as
led.value = not button.value . That way is more difficult to understand if you're
new to programming, so the example is a bit longer than it needed to be to make it
easier to read.
First you import two modules: board and digitalio . This makes these modules
available for use in your code. Both are built-in to CircuitPython, so you don't need to
download anything to get started.
Next, you set up the LED. To interact with hardware in CircuitPython, your code must
let the board know where to look for the hardware and what to do with it. So, you
create a digitalio.DigitalInOut() object, provide it the LED pin using the boa
rd module, and save it to the variable led . Then, you tell the pin to act as an OUTP
UT .
You include setup for the button as well. It is similar to the LED setup, except the
button is an INPUT , and requires a pull up.
Inside the loop, you check to see if the button is pressed, and if so, turn on the LED.
Otherwise the LED is off.
That's all there is to controlling an LED with a button switch!
Keypad
To use the keypad module, you must be running at least CircuitPython 7.0.0-
alpha.4!
Using the keys on the Adafruit MacroPad in CircuitPython is super simple, thanks to
the keypad module. This module allows you to print the key number, and read key
press and releases. The rotaryio module allows you to read the rotation of the
rotary encoder, and digitalio allows you to read the rotary encoder button switch
presses. All of these modules are built into CircuitPython, meaning to use them, you
do not need to load any separate libraries onto your MacroPad.
However, the following example involves the NeoPixel LEDs, which do require a
separate library - Adafruit CircuitPython NeoPixel.
Save the following to your CIRCUITPY drive as code.py.
"""
Simpletest demo for MacroPad. Prints the key pressed, the relative position of the
rotary
encoder, and the state of the rotary encoder switch to the serial console.
"""
import time
from adafruit_macropad import MacroPad
macropad = MacroPad()
while True:
key_event = macropad.keys.events.get()
if key_event and key_event.pressed:
print("Key pressed: {}".format(key_event.key_number))
print("Encoder: {}".format(macropad.encoder))
print("Encoder switch: {}".format(macropad.encoder_switch))
time.sleep(0.4)
Now, connect to the serial console(https://adafru.it/Bec). Try pressing keys, rotating
the rotary encoder, and pressing the rotary encoder switch to see the results printed
out.
To use the MacroPad library, you need to import it and instantiate it with the following
code:
from adafruit_macropad import MacroPad
macropad = MacroPad()
Once, instantiated as macropad , you have access to all the features of the MacroPad
library. To use the features of the library, you include macropad.feature_name in
your code. This example uses the following features:
keys - The keys on the MacroPad. Uses events to track key number and state,
•
e.g. pressed or released. You must fetch the events using keys.events.get()
and then the events are available for usage in your code. Each event has three
properties: key_number , pressed , and released .
encoder - The rotary encoder relative rotation position. Always begins at 0
•
when the code is run, so the value returned is relative to the initial location.
encoder_switch - The rotary encoder switch. Returns True when pressed.
•
Therefore, to read the rotary encoder, you would include macropad.encoder in your
code.
In this example, you first import time , then the MacroPad library, and instantiate the
library as macropad .
Inside the loop, the first thing you do is setup to look for the key press by creating the
key_event variable and assigning it to macropad.keys.events.get() . Then, you
check to see if there is a key_event (i.e. a key being pressed) and if it is a key being
pressed ( key_event.pressed ). Then, if so, print the key number ( key_event.key_
number ) being pressed to the serial console.
Then, you print to the serial console the relative position of the rotary encoder (with m
acropad.encoder ) and the state of the encoder switch (with macropad.encoder_s
witch ).
Finally, you include a time.sleep(0.4) to print the information every 0.4 seconds to
keep the serial console results readable.
That's all there is to reading the key presses, rotary encoder relative position, and
rotary encoder switch state on the Adafruit MacroPad using the CircuitPython
MacroPad library!
MacroPad Display Text
The Adafruit MacroPad RP2040 features a 3x4 key pad with NeoPixel LEDs, a rotary
encoder with push switch, and a display. This example reads the key presses, the
relative position of the rotary encoder and the state of the rotary encoder switch, and
displays the information on the display.
Update your code.py to the following.
Click the Download Project Bundle button below to download the necessary libraries
and the code.py file in a zip file. Extract the contents of the zip file, open the folder
"""
Simpletest demo for MacroPad. Displays the key pressed, the relative position of
the rotary
encoder, and the state of the rotary encoder switch to the built-in display. Note
that the key
pressed line does not appear until a key is pressed.
"""
To use the display_text feature of the MacroPad library, you need to instantiate it
by assigning it to a variable, e.g. text_lines =
macropad.display_text(title="MacroPad Info") . Once created, the title cannot
be updated. Note that if you want to be able to dynamically update the title, simply
instantiate it without a tittle ( text_lines = macropad.display_text() ), and treat
the first line of text as the title, which can be dynamically updated.
Once you've instantiated it, you can create lines of text below the title with dynamic
information in them, such as the key number being pressed or the relative position of
the rotary encoder. To do this, you use the text_lines object, and provide it a line
number and a string to display. Remember, Python begins counting at 0. For example,
to display a line of text with the rotary encoder relative position below the title, you
would include text_lines[0].text = "Rotary encoder
{}".format(macropad.encoder) in your code. To include a second line of code,
you would use text_lines[1].text = and provide a string to display.
This feature uses the Simple Text Display library; for advanced usage check out the
Simple Text Display documentation(https://adafru.it/U9D).
In your code, first, you import the MacroPad library, and then instantiate it.
Then, you create a text_lines variable, initialise the display_text feature by
assigning text_lines = macropad.display_text() , and, inside the parentheses,
provide it the title as a string, e.g. title="MacroPad Info" .
Inside the loop, the first thing you do is setup to look for the key press by creating the
key_event variable and assigning it to macropad.keys.events.get() . Then, you
check to see if there is a key_event (i.e. a key being pressed) and if it is a key being
pressed ( key_event.pressed ). Then, if so, if so, update the first line of text to
appear on the display showing which key number ( key_event.key_number ) was
pressed.
Next, you display two more lines of text - one for the rotary encoder relative position
and one for the rotary encoder switch state. Each of these updates when you rotate
the rotary encoder or press on the rotary encoder switch.
Finally, you call text_lines.show() to make the lines of text show up on the
display.
That's all there is to displaying lines of text on the built-in display of the Adafruit
MacroPad using the CircuitPython MacroPad library!
MacroPad Display Image
The Adafruit MacroPad comes with a built in display. The MacroPad library makes it
super simple to display a CircuitPython-compatible bitmap image on the display. To
learn more about how to create a CircuitPython-compatible bitmap, check out this
guide(https://adafru.it/MbZ) - the difference here is, the MacroPad display is
monochrome, so you'll want a black and white image.
You can easily update the code to use any compatible bitmap you'd like, but for this
example, download the following image and save it to your CIRCUITPY drive as blink
a.bmp.
Update your code.py to the following.
Click the Download Project Bundle button below to download the necessary libraries
and the code.py file in a zip file. Extract the contents of the zip file, open the folder
that matches your CircuitPython version, and copy the entire lib folder and the code.