Pyboard Hookup Guide Datasheet by SparkFun Electronics

Page 1 of 10
Pyboard Hookup Guide
The pyboard is a powerful microcontroller board designed to run
MicroPython code that also happens to be conveniently compact. There is
a pyboard can be sold without headers and with headers.
MicroPython pyboard v1.1
MicroPython pyboard v1.1 (with Headers)
Page 1 of 10
Page 2 of 10
Materials Required
A Computer
Windows(XP, Vista, 7, 8, 8.1) Not Windows 10
Mac OS X
A Micro-B USB cable
Your favorite text editor
Notepad ++
sudo apt-get update
sudo apt-get install vim
sudo apt-get install gedit
Your Favorite Serial Terminal
Suggested Reading and Viewing
Serial Terminal Basics
• MicroPython
Pyboard Documentation
Here is great video tutorial from MicroPython on getting started with your
Hardware Overview
Pyboard comes fully loaded with hardware features:
STM32F405RG microcontroller
168 MHz Cortex M4 CPU with hardware floating point
1024KiB flash ROM and 192KiB RAM
Micro USB connector for power and serial communication
Micro SD card slot, supporting standard and high capacity SD cards
3-axis accelerometer (MMA7660)
Real time clock with optional battery backup
Micro Python pyboard overview
Page 2 of 10
Page 3 of 10 .PYBvlfl inf-6m _ a 5’9' w o o puniégga o cuug
3x 12-bit analog to digital converters, available on 16 pins, 4 with
analog ground shielding
2x 12-bit digital to analog (DAC) converters, available on pins X5 and
•4 LEDs
1 reset and 1 user switch
On-board 3.3V LDO voltage regulator, capable of supplying up to
250mA, input voltage range 3.6V to 16V
DFU bootloader in ROM for easy upgrading of firmware
Easily control the following peripherals using the the pyb module’s built-in
classes for:
SD Card storage
Click the image for a closer look. Image courtesy of
The pyboard has four LEDs. We are going to use the REPL to interactively
determine how these LEDs are numbered and what color they are. The
LEDs are also indicators for the current state of the board. Here are some
examples of what you might see:
The red and green LEDs flash alternatively: has an error use
the REPL to debug
All four LEDs cycle on and off: You must perform a hard reset of the
Only the Red LED is on: You may just tried to save to the
drive. Do not eject the flash drive before the red LED turns off!
Page 3 of 10
Page 4 of 10
There are two switches, one labeled “USR” for user and the other “RST” for
reset. Micropython handles switch input very easily on this board and we
will use the USR switch to prove it. The Switch class has three methods
that allow you obtain the switch state or register when there has been a
change in the switch state.
MicroSD Socket
There is a drive on the pyboard called /flash. When an microSD card is
inserted this drive becomes available as /sd.
The pyboard has an accelerometer-MMA766FC that can be used to detect
the angle and motion of the board. The Accel class of the pyb module has
five methods which allow you get the x, y, z axis info, access the tilt
register, and a 3-tuple of x,y,z values.
Page 4 of 10
Page 5 of 10
Getting Started with MicroPython for
You can control your pyboard in two ways:
One from loading Python scripts in your favorite text editor, editing, and saving it via the pyboard drive.
Or through a serial terminal using REPL (Note: To use the use REPL
you need to install drivers. Depending on your system, the install
For more information on these methods, check out the sections below!
MicroPython Programming Examples
A cool feature of the pyboard is that you can write Python scripts in any text
editor and save the file directly to the pyboard drive. No IDE is required!
Let’s explore the pyboard, control some peripheral, and do some
Let’s start with some code. We are going to turn on all the onboard LEDS
one by one and figure out which one is which.
Connect the pyboard to a computer’s COM port using a USB cable.
Navigate to the drive called “PYBFLASH”. Open in a text editor of
your choice. Once opened you should see this:putyourcodehere!
Let’s turn on LED 1 and make a note of its color and location.putyourcodehere!
Save the file to the drive - don’t change the name. For the script to run you
must first reset the board. It is recommended you safely remove the
hardware first by ejecting the drive from your computer and then press the
RST button. Which LED is on and what color is it?
Note: If you do not follow these steps to safely remove the hardware
from your computer, it will become corrupt and a hard reset will be
Page 5 of 10
Page 6 of 10
Now run through that same code three more times but change the number
within the parenthesis after LED.
Toggling LEDs
In this example, we will toggle each of the onboard LEDs! Go to the
PYBFLASH and open in a text editor. Copy the code below.putyourcodehere!
Save in the PYBFLASH drive. The red LED will be on while the
program loads. After the LED is turned off, eject the PYBFLASH and then
press the RST button. Your program will now execute. This is the process
for loading a new script.
Note on Indentation: In Python, indentation matters for the code
blocks. Make sure that the indentation is formatted correctly for each
code blocks or the script will not function as expected. The number of
spaces used for each indentation can vary for each code block but you
must make sure that each block of code has the same amount.
PWM and LED 4: The Blue One is Special
LED 4 is the blue LED towards the edge of the pyboard. This LED can be
controlled through PWM. In the pyb module LED class, there is a method
called intensity. When called it looks like pyb.LED.intensity([value])
where value is a number between 0-255.
In this example, we will change the intensity of the LED. Go to the
PYBFLASH and open in a text editor. Copy the code below.
Page 6 of 10
Page 7 of 10putyourcodehere!
Attaching a Servo
There are four dedicated 3-pin headers labeled X1, X2, X3, & X4. You can
drive up to four hobby servo motors. At the top of the row is GND, the
middle of the row is VCC and the bottom row are the 4 PWM signal lines.
Once you’ve got a servo hooked up, we can look at what we can do within
the Servo Class.
For this example, we will be using a generic sub-micro hobby servo and
some jumper wire with pins. Assuming that headers are soldered on the
board, connect the servo to the respective pins.
pyboard Generic Sub-Micro Servo
GND GND (Black)
V+ Vcc (Red)
X1 Control Signal (White)
Follow the steps to load the python script again using the code below.
Page 7 of 10
Page 8 of 10putyourcodehere!
Once the script is loaded, the servo connected to pin X1 will sweep
between two positions and stop.
Using the REPL
Another method of controlling the pyboard is using the REPL. REPL stands
for Read Evaluate Print Loop. It is an interactive command prompt from a
serial terminal that allows access to your pyboard. It is an easy way to
iteratively write and test code. Once you’ve got your code hammered out,
you can copy it into to run without a computer. Before we are able
to use the REPL, we must install the drivers for your operating system.
Windows Install
This process has worked best on a computer with Windows 7.
Unfortunately, it doesn’t seem there is support for Windows 10 yet.
To install this driver you need to go to your computer’s Device Manager,
find the pyboard USB in the list of ports (it should have a warning sign next
to it because it’s not working yet), right click on the device, select
Properties, then Install Driver. You need to then select the option to find the
driver manually (don’t use Windows auto update), navigate to the pyboard’s
USB drive, and select that. It should then install.
After installing, go back to the Device Manager to find the installed pyboard,
and see which COM port it is (e.g. COM3). More comprehensive
instructions can be found in the Guide for pyboard on Windows. Please
consult this guide if you are having problems installing the driver.
Mac OS X
Simply open a terminal and run:
When you are finished type “CTRL -A CTRL-\” to exit.
Open a terminal and run: screen /dev/ttyACM0
The 0 at the end there may need to be updated to 1 or higher and you may
need the correct permissions to access this device. So try Sudo .
REPL via Serial Terminal
Now that you have installed the drivers we can start working with the
pyboard within an interactive serial terminal. In this example, we will be
using Putty on a Windows OS. To connect the pyboard to the right port,
open Device Manager and look under “Ports”.
Page 8 of 10
1‘"'PunsLCOM awn cammummnspcn(cm; ' Lammumanunsvomwwv [CF Prm‘irPuflhPTl} var vyhrmu54 h'Qu :myn M Page 9 of 10
Open your favorite serial terminal and configure the settings to connect.
Make sure on the “Serial line” you specify the correct port.
Once Putty has been configured, click on the Open button.
As a good first step, let explore the help() menu. Type the command into
the serial terminal and hit enter.
Click the image for a closer look.
Let’s explore some things from here.
Playing with the Onboard LEDs.
In your terminal type:
You’ll see each LED turn on as you enter a new line in the terminal.
Page 9 of 10
Pagc100f10—hookup 9/ / 7
USR Switc
The switch class makes it easy to obtain a switch state. From the terminal:
>>>mySwitch = pyb.Switch()
You should false if you are not pressing the USR switch and true if you are
pressing the switch when the function is called.
The accelerometer y, y, z methods return a signed number between -30
and 30. There are a few methods we can call here to obtain values from the
>>>accel = pyb.Accel()
The corresponding x-value will be returned.
The corresponding y-value will be returned.
The corresponding z-value will be returned.
This will return a list of comma separated x, y, and z values.
Resources and Going Further
Now that you’ve successfully got your pyboard up and running, it’s time to
incorporate it into your own project!
For more information, check out the resources below:
Pyboard Datasheets - For the components on the pyboard.
MicroPython Documentation
MicroPython Libraries
Pyboard Quick Reference Guide - Super useful
Skins - Like Arduino shields but for the pyboard.
Pyboard and MicroPython Examples
MicroPython Forum
Page 10 of 10