Pyboard Hookup Guide
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 main.py 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:
minicom /dev/tty.usbmodem*
When you are finished type "CTRL -A CTRL-\" to exit.
Linux
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".
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.
Let's explore some things from here.
Playing with the Onboard LEDs.
In your terminal type:
>>>pyb.LED(1).on()
>>>pyb.LED(2).on()
>>>pyb.LED(3).on()
>>>pyb.LED(4).on()
You'll see each LED turn on as you enter a new line in the terminal.
USR Switch
The switch class makes it easy to obtain a switch state. From the terminal:
>>>mySwitch = pyb.Switch()
>>>mySwitch
>>>mySwitch()
You should false if you are not pressing the USR switch and true if you are pressing the switch when the function is called.
Accelerometer
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 accelerometer.
>>>accel = pyb.Accel()
>>>accel.x()
The corresponding x-value will be returned.
>>>accel.y()
The corresponding y-value will be returned.
>>>accel.z()
The corresponding z-value will be returned.
>>>accel.filtered_xyz()
This will return a list of comma separated x, y, and z values.