Core UnitClass Library Reference

Created April 23rd, 2019

Revision History

Date Revised

Revised Contents

2019/4/23

First release2019/9/20

board Module information added

2020/2/19

Mu Editor is now the recommended programming environment
Added module information to the Class Table appendix

Index1.

Getting Started ....................................................................................................... 1

2.

Studuino:bit ............................................................................................................ 1
2.1.

Studuino:bit Layout .................................................................................................. 1

2.2.

MicroPython ............................................................................................................. 1

3.

Development Environment ..................................................................................... 2

4.

Studuino:bit Class Library ...................................................................................... 2
4.1.

The StuduinoBitDisplay Class ................................................................................. 2

4.1.1.

Constructors .................................................................................................... 2

4.1.2.

LED Settings .................................................................................................... 3

4.1.3.

Retrieving Data from LEDs .............................................................................. 3

4.1.4.

Animation ......................................................................................................... 4

4.1.5.

Display Power Settings.................................................................................... 5

4.2.

The StuduinoBitImage Class ................................................................................... 6

4.2.1.

Constructors .................................................................................................... 6

4.2.2.

Finding Image Size .......................................................................................... 7

4.2.3.

Image Settings ................................................................................................. 7

4.2.4.

Finding Image Data ......................................................................................... 8

4.2.5.

Manipulating Images ....................................................................................... 8

4.2.6.

Included Images .............................................................................................. 9

4.3.

The StuduinoBitBuzzer Class ................................................................................ 10

4.3.1.

Constructors .................................................................................................. 10

4.3.2.

Adjusting the Sound ...................................................................................... 10

4.3.3.

Releasing PWMs ........................................................................................... 10

4.4.

The StuduinoBitButton Class ................................................................................. 10

4.4.1.

Constructors .................................................................................................. 10

4.4.2.

Finding Button States .................................................................................... 11

4.5.

The StuduinoBitLightSensor Class ........................................................................ 11

4.5.1.

Constructors .................................................................................................. 11

4.5.2.

Finding Brightness ......................................................................................... 11

4.6.

The StuduinoBitTemperature Class ...................................................................... 11

4.6.1.

Constructors .................................................................................................. 12

4.6.2.

Finding the Temperature ............................................................................... 12

4.7.

The StuduinoBitAccelerometer Class .................................................................... 12

4.7.1.

Constructors .................................................................................................. 124.7.2.

Accelerometer Settings ................................................................................. 12

4.7.3.

Finding the Acceleration ................................................................................ 13

4.8.

The StuduinoBitGyro Class ................................................................................... 13

4.8.1.

Constructors .................................................................................................. 13

4.8.2.

Gyroscope Settings ....................................................................................... 13

4.8.3.

Finding Angular Velocity ................................................................................ 13

4.9.

The StuduinoBitCompass Class ............................................................................ 14

4.9.1.

Constructors .................................................................................................. 14

4.9.2.

Calibration...................................................................................................... 14

4.9.3.

Finding Directions .......................................................................................... 14

4.9.4.

Finding Compass Values............................................................................... 14

4.10. The StuduinoBitTerminal Class ............................................................................. 15

5.

4.10.1.

Constructors .................................................................................................. 15

4.10.2.

Digital Input/Output ........................................................................................ 16

4.10.3.

Digital Input/Output and Analog Input ........................................................... 16

4.10.4.

Digital and Analog Input ................................................................................ 16

Appendices .......................................................................................................... 16
5.1.

The board Module .................................................................................................. 16

5.2.

Sound Output ......................................................................................................... 17

5.3.

Included Images..................................................................................................... 17

5.4.

Class Table ............................................................................................................ 20

1. Getting Started
This manual is a reference guide for the ArtecRobo2.0 Studuino Class Library. Using thismanual requires some prior understanding of the basics of Python.

2. Studuino:bit
The Studuino:bit is a computing device equipped with microcontrollers, sensors, LEDs, andother parts. MicroPython is one of the programming environments compatible with
Studuino:bit.

2.1. Studuino:bit Layout
The layout of the Studuino:bit is shown below.

The hardware parts operable with the Studuino:bit Class Library are ① Temperature
Sensor, ② A button, ③ B button, ⑤ Full Color 5 x 5 LED Matrix, ⑥ Light Sensor, ⑨Buzzer, ⑩ 9-Axis Sensor (3-axis accelerometer, 3-axis gyroscope, 3-axis compass),and ⑪ Edge Connectors.
From here on, the Full Color 5 x 5 LED Matrix will be referred to as the LED Display.
The 9-Axis Sensor’s three parts (3-axis accelerometer, 3-axis gyroscope, 3-axis
compass) will be referred to as the Accelerometer, Gyroscope, and Geomagnetism
Sensor respectively. The Edge Connectors will be called Ports.

2.2. MicroPython
MicroPython is version of Python developed specifically for use with microcontrollers. The
programming syntax is identical to Python 3.0, but some Python libraries are not usable in
MicroPython because they’re not designed to work with the limited memory and CPU of a
microcontrolller. However, some MicroPython-specific libraries (such as the library for GPIO
microcontrollers) are included as standard.
MicroPython has been widely ported to different microcontrollers, and the Studuino:bit
library utilizes a Studuino:bit specific version.
13. Development Environment
Some MicroPython development environments you can use with Studuino:bit are Mu Editor
and uPyCraft. We provide an installer and instructions for using the Mu Editor on website at
this URL:
https://www.artec-kk.co.jp/artecrobo2/en/software/python.php

4. Studuino:bit Class Library
The Studuino:bit class library is structured as follows.
Package

ModuleClass

Hardwarepystubitdsply

StuduinoBitDisplay

LED Display

image

StuduinoBitImagebzr

StuduinoBitBuzzer

BuzzerbuttonStuduinoBitButton

A/B Buttons

sensorStuduinoBitLightSensor

Light Sensors

StuduinoBitTemperature

Temperature Sensor

StuduinoBitAccelerometer

Accelerometer

StuduinoBitGyro

Gyroscope

StuduinoBitCompass

Geomagnetism
Sensor (Compass)terminal

StuduinoBitTerminal

Port

Importing the board Module will let you use objects from the classes above (seesection 5.1).

4.1. The StuduinoBitDisplay ClassThe StuduinoBitDisplay class is used to operate the 5 x 5 full color LED display on the frontof the Studuino:bit Core Unit. This class can be used to make the LEDs display images,
animations, and text.

4.1.1. Constructors
Use this to make an object that operates the LED display.
from pystubit.dsply import StuduinoBitDisplay
display = StuduinoBitDisplay()2

4.1.2. LED Settings
0

+x

1

2

3

4

0
1
2
3

+y

4

Use the method set_pixel(x, y, color) to change specific LEDs’ settings. Each LED in thedisplay is designated by a specific set of x-y coordinates (see image above). The x
parameter in the set_pixel method picks the x-coordinate, y picks the y-coordinate, and color
sets the color. The color parameter can be specified using a list, a tuple, or an integer. If
using a tuple or list, use (R, G, B) or [R, G, B] to set the red, green and blue light levels. If
using an integer, set the colors using a hex code as shown below. You can also use theclear() method to set the brightness of all LEDs in the display to 0 (off).

0xffffff

RedGreenBluefrom pystubit.dsply import StuduinoBitDisplay
display = StuduinoBitDisplay()display.set_pixel(1, 1, (0, 0, 10))display.clear()
Running each of these methods should make the LED display respond as shown below.

Running
methodtheset_pixel

4.1.3. Retrieving Data from LEDs

Running the clear
methodUse the method get_pixel(x, y) to get information from specific LEDs. Set the x and yparameters to match the LED’s x-y coordinates on the display to find out that LED’s color intuple format.

3

from pystubit.dsply import StuduinoBitDisplay
display = StuduinoBitDisplay()display.set_pixel(1, 1, (0, 0, 10))c1 = display.get_pixel(0, 0)
c2 = display.get_pixel(1, 1)
Variable c1 gets the data (0, 0, 0) from the LED at coordinates (0, 0) on the display, whilevariable c2 will get the data (0, 0, 10) from coordinates (1, 1).

4.1.4. Animation
The method show(value, delay, wait=True, loop=False, clear=False, color=None) can beused to display letters and images with the LEDs.
Any string of numbers or letters you set in the value parameter will by displayed in sequenceby the LEDs. If you instead set arrays for image objects (see section 4.2) in the value
parameter, the LEDs will display each image in sequence. The delay parameter can be use
to set the speed at which the display switches between images in milliseconds. If the wait
parameter is set to True, other methods will be blocked until the display animation has
finished. If it is set to False, other methods will run in the background. If the loop parameteris set to True, the animation will play on loop. If the clear parameter is set to True, the LED
display will be cleared once the animation has finished. Set the color of the displayed image
using the color parameter. The color parameter can be specified using a list, a tuple, or an
integer.
from pystubit.dsply import StuduinoBitDisplay
display = StuduinoBitDisplay()display.show('OK', 100, wait=True, loop=True, clear=True, color=(10, 0, 0))
Running the show method like this will make the LEDs display the letter O in red for 100
milliseconds, then the letter K for 100 milliseconds, and finally clear the display. This
animation will play on loop.
color

delay
clear
loop
The method display.scroll(string,delay,wait=True,loop=False,color=None) can be used tomake a series of characters scroll across the display.
4You can set the string of letters and numbers to display in your scroll using the string
parameter. Use the delay parameter to set how fast your string scrolls. If the wait parameteris set to True, other methods will be blocked until the display animation has finished. If it is
set to False, other methods will run in the background. If the loop parameter is set to True,
the animation will play on loop. Set the color of the displayed image using the color
parameter. The color parameter can be specified using a list, a tuple, or an integer.
from pystubit.dsply import StuduinoBitDisplay
display = StuduinoBitDisplay()display.scroll('Hello', 100, wait=True, loop=True, color=(10, 0, 0))
Running the scroll method like this will make the string Hello repeatedly scroll across thedisplay in red, as shown below.
delay

color
loop

4.1.5. Display Power Settings
If the brightness of the all the LEDs in the display is set to 0, power to the display will beturned off. You can also use the off() method to switch the LED display’s power OFF.
Likewise, the on() method can be used to switch the LED display’s power ON. You cancheck the status of the display’s power using the is_on() method.
from pystubit.dsply import StuduinoBitDisplay
display = StuduinoBitDisplay()display.set_pixel(1, 2, (10, 0, 0))
display.set_pixel(2, 2, (0, 10, 0))
display.set_pixel(3, 2, (0, 0, 10))display.off()
ds1 = display.is_on()
display.on()
ds2 = display.is_on()
In the example below, the LED display has the LED at coordinates (1, 2) lit up in red, (2, 2)
in green, and (3, 2) in blue. Running the off method turns off the LEDs, and running the on
method turns them on again.

5

Before running the OFF method
Running the OFF method Running the ON method
The variable ds1 will be set to False, while ds2 will be set to True.

4.2. The StuduinoBitImage Class
Using the StuduinoBitImage class makes it easy to create images to display with your LEDs.
Images are made up of a pattern and color data for the LEDs to display. Patterns are written
using series of 0s (meaning OFF) and 1s (meaning ON). See the picture below for an
example of how an image translate to the LED display.
Image

LED Display■ Pattern:
00000
01010
00000
10001
01110

■ Base color: Red

4.2.1. Constructors
There are four ways to make an image.
StuduinoBitImage(*,color)

Makes image using all 5 x 5 spaces (all 0).

StuduinoBitImage(string,*,color)

Makes a patter from a string of 0s and 1s in the string
parameter.

StuduinoBitImage(width, height,*,
color)

Makes an image using spaces within the specified
width (the width parameter) and height (the heightparameter).

StuduinoBitImage(width, height,

Makes an image using spaces within the specified

buffer,*,color)width (the width parameter) and height (the heightparameter) using a specified pattern (the buffer
parameter).

The color parameter can be used to set the base color in all constructors. The color
parameter can be specified using a list, a tuple, or an integer. If the color variable has not
6been set, the base color will be red (31,0,0).
from pystubit.image import StuduinoBitImage
img1 = StuduinoBitImage()
img2 = StuduinoBitImage('00000:''01010:''00000:''10001:''01110:')img3 = StuduinoBitImage(2,2)
img4 = StuduinoBitImage(2,2, bytearray([1,1,1,1]))
Images you’ve created can be displayed using display objects, as shown below.
from pystubit.dsply import StuduinoBitDisplay
display.show(img1)
Variables img1, img2, img3, and img4 will appear on the LED display as shown below.

img1

img2

img3

img4

Constructors set with the string parameter can be displayed in a single line, as shown below.
img2 = StuduinoBitImage('00000:01010:00000:10001:01110:')4.2.2. Finding Image Size
Find the size of an image using methids width() and height().
from pystubit.image import StuduinoBitImage
img = StuduinoBitImage(2,3)
w = img.width()h = img.height()
The variable w will be set 2, while h will be set to 3.

4.2.3. Image Settings
Use the set_pixel(x, y, value) method to edit an image pattern. Specify pixel positions using
x-y coordinates just like the LEDs in the display, then set the value parameter to either 0 or 1.
You can also use the set_pixel_color(x, y, color) method to change a single pixel’s color
setting. Specify the pixel’s coordinates (x and y parameters) abd set the color in the color
parameter.
The set_base_color(color) method can be used to set the base color.

7

from pystubit.image import StuduinoBitImage
original = StuduinoBitImage('00000:01010:00000:10001:01110:')
img1.set_base_color((0,0,10))
img2.set_pixel(2,2,1)
img3.set_pixel_color(2,2,(0,10,0))Variables original, img1, img2, and img3 will appear on the LED display as shown below. In
img1 you can see that the base color has been changed to blue (0, 0, 10) with
set_base_color. In img2 you can see that the pixel at (2, 2) has been set to 1 with set_pixel(making it display the base color). In img3 you can see that the pixel at (2, 2) has beenchanged to green (0, 10, 0) with set_pixel.

original

img1

img2

img3

4.2.4. Finding Image Data
Use the get_pixel(x, y) method to find pattern information for an image. Specifying the pixel’s
coordinates (x and y parameter) will return the pattern data for that pixel (0 or 1).
Use the get_pixel_color(x, y) method to find data for a single pixel in an image. Specify the
pixel’s coordinates (x and y parameters) to find its color in tuple format.
from pystubit.image import StuduinoBitImage
original = StuduinoBitImage('00000:01010:00000:10001:01110:')v1 = img.get_pixel(0, 0)
c1 = img.get_pixel_color(0, 0)
v2 = img.get_pixel(1, 1)
c2 = img.get_pixel_color(1, 1)
Variables v1 and c1 get the pattern data (0) and color data (0, 0, 0) from the LED at
coordinates (0, 0) on the image, while variables v2 and c2 will get the pattern data (1) andcolor data (31, 0, 0) from coordinates (1, 1).

4.2.5. Manipulating Images
The methods shift_up(n), shift_down(n), shift_left(n), and shift_right(n) can be used to shift
an image up, down, left, or right by the amount specified in the n parameter.

8from pystubit.dsply import StuduinoBitImage
original = StuduinoBitImage('00000:01010:00000:10001:01110:')up = original.shift_up(1)down = original.shift_down(1)left = original.shift_left(1)right = original.shift_right(1)Variables original, up, down, left, and right will appear on the LED display as shown below.
You can see that each image has been moved one line up, down, left, or right.

original

up

down

left

right

Using a + operator lets you combine several images into one.
from pystubit.dsply import StuduinoBitImage
img1 = StuduinoBitImage('00000:01110:01110:01110:00000',color=(10,0,0))
img2 = StuduinoBitImage('10001:00000:00000:00000:10001',color=(0,10,0))
img3 = img 1 + img2
Variables img1, img2, and img3 will appear on the LED display as shown below. You cansee how img1 and img2 have been combined to make img3.

img1

img2

img3

You can use the copy() method to make a copy of an image.

4.2.6. Included Images
StuduinoBitImage lets you use a variety of patterns that are included in your Studuino:bit bydefault.
from pystubit.dsply import StuduinoBitImage
img1 = StuduinoBitImage.HAPPY
img2 = StuduinoBitImage.SAD
img3 = StuduinoBitImage.ANGRY
Variables img1, img2, and img3 will appear on the LED display as shown below.

9

img1

img2

img3

For a list of all the included images accessible with StuduinoBitImage, see section 5.3.

4.3. The StuduinoBitBuzzer ClassThe StuduinoBitBuzzer class is used to control the buzzer.

4.3.1. Constructors
Use this to make an object that operates the Buzzer.
from pystubit.bzr import StuduinoBitBuzzer
buzzer = StuduinoBitBuzzer()

4.3.2. Adjusting the SoundYou can use the method on(sound, *, duration=None) to play sound from the buzzer. Use
the sound parameter to set the frequency of the sound using a MIDI note number or note
name. For a list of usable note numbers and names, see section 5.2. The duration
parameter is used to set the length of the sound output in milliseconds. If the duration
parameter is left unspecified, the off() method can be used to stop the buzzer.
from pystubit.bzr import StuduinoBitBuzzer
buzzer = StuduinoBitBuzzer()
buzzer.on('C4', duration=1000)
This will make the buzzer play the note C4 for 1 second.

4.3.3. Releasing PWMs
The Studuino:bit uses PWM for its sound output. It can use up to four PWMs simultaneously.
If no PWM is available, you will be unable to use any buzzer objects you make. You canresolve this by using the release() method to release a PWM assigned to a different buzzer
object.

4.4. The StuduinoBitButton ClassThe StuduinoBitButton class is used to operate the two buttons on the face of theStuduino:bit’s Main Unit.

4.4.1. Constructors
Use this to make an object that operates the buttons. Set A or B in the parameter.
10from pystubit.button import StuduinoBitButton
button_a = StuduinoBitButton('A')

4.4.2. Finding Button States
Use the get_value() method to find the value (0/1) of a button as an integer, Using theis_pressed() method will return a True/False to tell you whether a button is being pressed.
was_pressed() will return a True/False telling you whether a button was pressed in the past.
The get_presses() method find how many times a button was pressed in the past.
from pystubit.button import StuduinoBitButton
button_a = StuduinoBitButton('A')
button_b = StuduinoBitButton('B')
print('Press A button')while not button_a.is_pressed:
pass
print('A button is pressed')This will display the words “A button is pressed” on the standard display when the A Button
has been pressed.

4.5. The StuduinoBitLightSensor ClassThe StuduinoBitLightSensor class is used to operate the Light Sensor in the Main Unit.

4.5.1. Constructors
Use this to make an object that operates the Light Sensor.
from pystubit.sensor import StuduinoBitLightSensor
light_sensor = StuduinoBitLightSensor()

4.5.2. Finding Brightness
Use the method get_value() to find the analog value of the Light Sensor. It will be formatted
as an integer from 0 to 4095.
from pystubit.sensor import StuduinoBitLightSensor
import timelight_sensor = StuduinoBitLightSensor()while True:
print(light_sensor.get_value())
time.sleep_ms(500)This will display the value of the Light Sensor on the standard display every 500
milliseconds.

4.6. The StuduinoBitTemperature ClassThe StuduinoBitTemperature class is used to operate the Temperature Sensor in the Main
11

Unit.

4.6.1. Constructors
Use this to make an object that operates the Temperature Sensor.
from pystubit.sensor import StuduinoBitTemperaturetemperature = StuduinoBitTemperature ()4.6.2. Finding the Temperature
Use the method get_value() to find the analog value of the Temperature Sensor. It will beformatted as an integer from 0 to 4095. Use the method get_celsius(ndigits= 2) to get thetemperature in degrees Celsius from the Temperature Sensor. The ndigits parameter canbe used to set the number of decimal places.
from pystubit.sensor import StuduinoBitTemperatureimport time
temperature = StuduinoBitTemperature ()while True:
print(temperature.get_value())
print(temperature.get_celsius())
time.sleep_ms(500)This will display the analog value and the temperature in Celsius from the Temperature
Sensor on the standard display every 500 milliseconds.

4.7. The StuduinoBitAccelerometer ClassThe StuduinoBitAccelerometer class is used to operate the Accelerometer in the Main Unit.

4.7.1. Constructors
Use this to make an object that operates the Accelerometer.
from pystubit.sensor import StuduinoBitAccelerometer
acc = StuduinoBitAccelerometer(fs='2g', sf='ms2')
You can use the fs (full scale, meaning the maximum end of the measurement scale) and sf
parameters in StuduinoBitAccelerometer constructors to set your units. Set 2g, 4g, 8g, or
16g in the fs parameter to measure up to 2G, 4G, 8G, or 16G of acceleration. It will be set to2G by default. Set either ms2 or mg in the sf parameter to measure acceleration in either
m/sec^2 or milli-Gs. It will be set to m/sec^2 by default.

4.7.2. Accelerometer Settings
Use the set_fs(value) method to set your Gyroscope’s maximum measurement. You can set
the value parameter to 2g, 4g, 8g, or 16g. You can also use the set_sf(value) method to set
the units of measurement. In can be set to either ms2 or mg.
12

4.7.3. Finding the Acceleration
Use the get_values(ndigits=2) method to find your Accelerometer’s values. The values will
be returned in a tuple (x, y, z) format. The get_x(ndigits=2), get_y(ndigits=2) and
get_z(ndigits=2) methods can each be used find the x-axis, y-axis and z-axis acceleration
separately. Regardless of method, the ndigits parameter can be used to set the number ofdecimal places.
from pystubit.sensor import StuduinoBitAccelerometer
import timeacc = StuduinoBitAccelerometer()while True:
print(acc.get_values())
time.sleep_ms(500)This will display the Accelerometer values on the standard display every 500 milliseconds.

4.8. The StuduinoBitGyro ClassThe StuduinoBitGyro class is used to operate the Gyroscope in the Main Unit.

4.8.1. Constructors
Use this to make an object that operates the Gyroscope.
from pystubit.sensor import StuduinoBitGyro
gyro = StuduinoBitGyro (fs='250dps', sf='dps'))
You can use the fs (maximum end of the measurement scale) and sf parameters in
StuduinoBitGyro constructors to set your units. Set 250dps, 500dps, 1000dps, or 2000dps in
the fs parameter to measure up to 250 deg/s, 500 deg/s, 1000 deg/s, or 2000 deg/s ofangular velocity. It will be set to 250 deg/s by default. Set either dps or rps in the sf
parameter to take measurements in either deg/s or rad/s. It will be set to deg/s by default.

4.8.2. Gyroscope Settings
Use the set_fs(value) method to set your Gyroscope’s maximum measurement. You can set
the value parameter to 250dps, 500dps, 1000dps, or 2000dps. You can also use theset_sf(value) method to set the units of measurement. In can be set to either dps or rps.

4.8.3. Finding Angular Velocity
Use the method get_values(ndigits=2) to find the value of the Gyroscope. The values will be
returned in the units specificed by either the constructor or the set_sf method, in a tuple (x, y,z) format.
The get_x(ndigits=2), get_y(ndigits=2) and get_z(ndigits=2) methods can each be used findthe x-axis, y-axis and z-axis angular velocity separately. Regardless of method, the ndigits
13parameter can be used to set the number of decimal places.
from pystubit.sensor import StuduinoBitGyro
import time
gyro = StuduinoBitGyro ()while True:
print(gyro.get_values())
time.sleep_ms(500)This will display the Gyroscope’s values on the standard display every 500 milliseconds.

4.9. The StuduinoBitCompass ClassThe StuduinoBitCompass class is used to operate the geomagnetism sensor (or Compass)in the Main Unit.

4.9.1. Constructors
Use this to make an object that operates the Compass.
from pystubit.sensor import StuduinoBitCompass
compass = StuduinoBitCompass ()4.9.2. Calibration
Calibrate the Compass using the calibrate() method. The calibration process will use the
LED display.
Use the is_calibrated() method to find out whether the Compass has been calibrated. Use
the clear_calibration() method to clear any existing calibration data.

4.9.3. Finding Directions
Use the heading() method to find directional information (in degrees 0-360). If yourCompass has not been calibrated, calibration will begin automatically when you run theheading() method. 0° is defined as when the Main Unit is placed with the LED Display facing
up and the USB connector facing due south. Angles increase from there in a clockwise
fashion.

4.9.4. Finding Compass Values
Use the method get_values() to find the Compass’s values. The values will be returned in atuple (x, y, z) format, using μT (micro tesla) units.
The get_x(), get_y() and get_z() methods can each be used find what direction the x-axis,
y-axis and z-axis are facing separately.

14

from pystubit.sensor import StuduinoBitCompass
import timecompass = StuduinoBitCompass ()while True:
print(compass.get_values())
time.sleep_ms(500)This will display the Compass’s values on the standard display every 500 milliseconds.

4.10. The StuduinoBitTerminal ClassThe StuduinoBitTerminal class is used to operate the ports in the Main Unit.

4.10.1. Constructors
StuduinoBitTerminal constructors can be used to make objects that operate all the ports on
Main Unit from P0 to P20, except for P17 and P18. The ports operable with theStuduinoBitTerminal class are shown below, P0-P20.

Use this to make an object that operates a specified port between P0 and P20.
from pystubit.terminal import StuduinoBitTerminal
p0 = StuduinoBitTerminal(‘P0’)
The input/output capabilities of the ports between P0 and P20 are listed below.
Port

I/O TypePort

I/O Type

P0

Digital Input/Output and Analog

P10

Digital Input/Output

P11

Digital Input/Output

Input
P1

Digital Input/Output and Analog
Input

P2

Digital and Analog Input

P12

Digital Input/Output

P3

Digital and Analog Input

P13

Digital Input/Output

P4

Digital Input/Output

P14

Digital Input/Output

P5

Digital Input/Output

P15

Digital Input/Output

P6

Digital Input/Output

P16

Digital Input/Output

P7

Digital Input/Output

P19

Digital Input/Output

P8

Digital Input/Output

P20

Digital Input/Output
15

P9

Digital Input/Output

4.10.2. Digital Input/Output
If the port object you’ve made is a digital input/output type, you can use thewrite_digital(value) method to send digital signals with it. The value parameter can be set toeither 0 or 1. You can also use the read_digital() method to read digital signals. Use the
set_analog_hz() method to pick a PWM output frequency to use, and then use thewrite_analog(value) method to send PWM signals.

4.10.3. Digital Input/Output and Analog Input
If the port object you’ve made is a digital input/output and analog input type, you can use thedigital input/output methods described above, as well as the read_analog() method to readanalog signals.

4.10.4. Digital and Analog Input
If the port object you’ve made is a digital and analog input type, you can use only theread_digital() and read_analog() methods with it.

5. Appendices5.1. The board Module
The board module contains the definitions of the objects used to operate the Studuino:bit
hardware. Make a declaration as shown to use an object.
from pystubit.board import *The objects defined by the board module are listed below.
ObjectHardwaredisplay

LED Display

Image (Class)

LED Display (Image)buzzerBuzzerbutton_a, button_b

A/B Buttons

lightsensor

Light Sensors

temperature

Temperature Sensor

accelerometer

Accelerometer

gyro

Gyroscopecompass

Geomagnetism Sensor (Compass)

P0-16, P19, P20

Edge Connector

pin0-pin3

Edge Connector for micro:bit (★)
16

★: The following objects cannot be used together at the same time: pin0 and p0, pin1 andp1, pin2 and p2, pin3 and p3.
★: The objects pin0-pin3 can use the same method as objects p0-p3, but the read_analog()
method will return values from 0 to 1023.

5.2. Sound Output
The MIDI note numbers and note names used in the StuduinoBitBuzzer class are as follows.
MIDI

Note

MIDI

Note

MIDI

Note

MIDI

Note

MIDI

Note

MIDI

Note

MIDI

Note

48
49
50
51
52
53
54
55
56
57
58
59

C3
CS3
D3
DS3
E3
F3
FS3
G3
GS3
A3
AS3
B3

60
61
62
63
64
65
66
67
68
69
70
71

C4
CS4
D4
DS4
E4
F4
FS4
G4
GS4
A4
AS4
B4

72
73
74
75
76
77
78
79
80
81
82
83

C5
CS5
D5
DS5
E5
F5
FS5
G5
GS5
A5
AS5
B5

84
85
86
87
88
89
90
91
92
93
94
95

C6
CS6
D6
DS6
E6
F6
FS6
G6
GS6
A6
AS6
B6

96
97
98
99
100
101
102
103
104
105
106
107

C7
CS7
D7
DS7
E7
F7
FS7
G7
GS7
A7
AS7
B7

108
109
110
111
112
113
114
115
116
117
118
119

C8
CS8
D8
DS8
E8
F8
FS8
G8
GS8
A8
AS8
B8

120
121
122
123
124
125
126
127

C9
CS9
D9
DS9
E9
F9
FS9
G9

5.3. Included Images
The images included in the Studuino:bit library are as follows.
StuduinoBitImage.HEART
StuduinoBitImage.HEART_SMALL
StuduinoBitImage.HAPPY
StuduinoBitImage.SMILE
StuduinoBitImage.SAD
StuduinoBitImage.CONFUSEDStuduinoBitImage.ANGRY
StuduinoBitImage.ASLEEP
StuduinoBitImage.SURPRISED
StuduinoBitImage.SILLY
StuduinoBitImage.FABULOUS
StuduinoBitImage.MEH
StuduinoBitImage.YES
StuduinoBitImage.NO
StuduinoBitImage.CLOCK12,
StuduinoBitImage.CLOCK11,
17

StuduinoBitImage.CLOCK10,
StuduinoBitImage.CLOCK9,
StuduinoBitImage.CLOCK8,
StuduinoBitImage.CLOCK7,
StuduinoBitImage.CLOCK6,
StuduinoBitImage.CLOCK5,
StuduinoBitImage.CLOCK4,
StuduinoBitImage.CLOCK3,
StuduinoBitImage.CLOCK2,
StuduinoBitImage.CLOCK1
StuduinoBitImage.ARROW_N,
StuduinoBitImage.ARROW_NE,
StuduinoBitImage.ARROW_E,
StuduinoBitImage.ARROW_SE,
StuduinoBitImage.ARROW_S,
StuduinoBitImage.ARROW_SW,
StuduinoBitImage.ARROW_W,
StuduinoBitImage.ARROW_NW
StuduinoBitImage.TRIANGLE
StuduinoBitImage.TRIANGLE_LEFT
StuduinoBitImage.CHESSBOARD
StuduinoBitImage.DIAMOND
StuduinoBitImage.DIAMOND_SMALL
StuduinoBitImage.SQUARE
StuduinoBitImage.SQUARE_SMALL
StuduinoBitImage.RABBIT
StuduinoBitImage.COW
StuduinoBitImage.MUSIC_CROTCHET
StuduinoBitImage.MUSIC_QUAVER
StuduinoBitImage.MUSIC_QUAVERS
StuduinoBitImage.PITCHFORKStuduinoBitImage.XMAS
StuduinoBitImage.PACMAN
StuduinoBitImage.TARGET
StuduinoBitImage.TSHIRT
18

StuduinoBitImage.ROLLERSKATE
StuduinoBitImage.DUCK
StuduinoBitImage.HOUSE
StuduinoBitImage.TORTOISE
StuduinoBitImage.BUTTERFLY
StuduinoBitImage.STICKFIGURE
StuduinoBitImage.GHOST
StuduinoBitImage.SWORD
StuduinoBitImage.GIRAFFE
StuduinoBitImage.SKULL
StuduinoBitImage.UMBRELLA
StuduinoBitImage.SNAKE

19

5.4. Class Table
This table lists the methods available for each class, and which objects from the board module the classes correspond to.

FunctionClass

The board Module

Buttons

StuduinoBitButton

button_abutton_b

LED Display(Full color)

StuduinoBitDisplay

display

MethodInstructions
Used to make objects that operate the A/B buttons. The ab parameter can__init__(ab)be set to either A or B.
get_value()
Returns a 0 if the the button is being pressed and 1 if not.
is_pressed()
Returns a True if the button is being pressed.
Button objects store the information that the button has been pressed.
was_pressed()This method returns a True if the button is has been pressed in the past.
The information is reset when this method is called.
Button objects store the information that the button has been pressed.
get_presses()This method returns the number of times a button has been pressed in thepast. The count is reset when this method is called.
__init__()Makes display objects.
Returns the color of the LED at row x of column y. The color will be
get_pixel(x, y)
displayed in (R,G,B).
Set the color of the LED at row x of column y. The parameter can be set
set_pixel(x, y, color)using (R,G,B), [R,G,B] or #RGB.
clear()
Set the brightness of all LEDs in the display to 0 (off).
show(iterable,delay=400, *,wait=True,
Displays the iterable parameter (an image, string, or number) in sequence.
loop=False,
clear=False,
color=None)
scroll(string,
delay=150, *,Scrolls the value parameter (letters/numbers) across the display
wait=True,horizontally.
loop=False,
color=None)on()
Turn on power to the LED display.
off()Turn off power to the LED display. (This allows you to used GPIO terminals
20

ImageStuduinoBitImage

Image

connected to the display for other purposes.)is_on()
Returns True if the display’s power is ON, and False if it’s OFF.
Makes image objects using a pattern written in 0s (LED OFF) and 1s (LEDON) in the string parameter.
__init__(string,
StuduinoBitImage('01100:10010:11110:10010:10010:', color=(0,0,10))color=None)
Makes an image object using spaces within the specified width (the width__init__(width=None,parameter) and height (the hight parameter).
height=None,
StuduinoBitImage(2, 2,bytearray([0,1,0,1])
buffer=None, ,StuduinoBitImage(3, 3)
color=None)
As with micro:bit, any number 0-9 can be used, but 1-9 all translate to ON,
while 0 is OFF. If the color variable has not been set, (RGB)= (31,0,0).
width()
Returns how wide the image is in columns.
height()Returns how tall the image is in rows.
The value parameter sets the value of the pixel at coordinates (x, y) in the
set_pixel(x, y, value)
image. The value parameter can be set to either 0 (OFF) or 1 (ON).
set_pixel_color(x, y, The color parameter sets the color of the pixel at coordinates (x, y) in thecolor)
image. The color parameter can be set using (R, G, B), [R, G, B] or #RGB.
get_pixel(x, y)
Returns the value of the pixel at coordinates (x, y) in the image.
Returns the color of the pixel at coordinates (x, y) in the image.
get_pixel_color(x, y,
If the hex parameter is set to False, the color will be written in (R,G,B). If
hex=False)
set to True, it will be written in #RGB.
set_base_color(self, The color parameter sets the color of all the pixels in the image. The color
color)
parameter can be set using (R, G, B), [R, G, B] or #RGB.
Makes a next image by shifting the current image a number of spaces left
shift_left(n)set in the n parameter.
shift_right(n)Identical to shift_left(-n).
Makes a next image by shifting the current image a number of spaces up
shift_up(n)set in the n parameter.
shift_down(n)Identical to shift_up(-n).
copy()
Returns a complete copy of the image.
repr(image)Get a compact string representing the image.
str(image)Get a readable string representing the image.
21

+Combine all the pixels from two images to make a new image.
Included Images (See 5.3)

Port

StuduinoBitTerminal

See port modules
below.

__init__(pin)write_digital(value)p0, p1, p2, p3
read_digital()

DigitalInput/Output andStuduinoBitAnalogDigitalPin

Analog Input（※）

Note:
p2 and p3 cannot
be used for digital
input/output. Using
the write_digital
method with themwill cause an error.
The read_digital
method is
implemented withanalog input, so it
can be used.

write_analog(value)
set_analog_period(period, timer=-1)
set_analog_period_m
icroseconds(period,
timer=-1)
set_analog_hz(hz,timer=-1)
status()read_analog(mv=Fal
se)write_digital(value)
read_digital()

DigitalInput/Output (★)

StuduinoBitDigitalPin

p4-p16, p19, p20

write_analog(value)

Make a terminal object that applies to a designated Studuino:bit port
P0-P16, P19, or P20.
Sets digital signals to High if the value parameter is 1, and Low if the value
parameter is 0.
Reads digital signals. Returns High if the received value is 0, and Low if it’s
1.
Sends PWM signals through the port. The value parameter can be set from
0 (0%) to 1023 (100%).
Sets the period of the PWM signal in milliseconds.
Sets the period of the PWM signal in microseconds.
Sets the period of the PWM signal by frequency.
Shows the current usage status of the PWMs.
Reads voltage from the port and, if the mv parameter is set to False,
returns it as an integer between 0 (0V) and 4096 (3.3V). If mv=True, thevoltage will be written in mV.
Sets digital signals to High if the value parameter is 1, and Low if the value
parameter is 0.
Reads digital signals. Returns High if the received value is 0, and Low if it’s
1.
Sends PWM signals through the port. The value parameter can be set from
0 (0%) to 1023 (100%).

set_analog_period(pSets the period of the PWM signal in milliseconds.
eriod, timer=-1)
set_analog_period_m
icroseconds(period, Sets the period of the PWM signal in microseconds.
timer=-1)
22

set_analog_hz(hz,timer=-1)
status()__init__()BuzzerStuduinoBitBuzzer

Temperature
SensorStuduinoBitTemperatureLight Sensors

StuduinoBitLightSensor

buzzertemperatureon(sound, *,duration=-1)

off()__init__()get_value()
get_celsius()

lightsensor__init__()get_value()__init__(fs=’2G’,
sf=’mg2’)

Accelerometers

StuduinoBitAccelerometer

accelerometer

get_x
get_y
get_z
get_values()
set_axis(mode)
set_fs(value)
set_sf(value)

Sets the period of the PWM signal by frequency.
Shows the current usage status of the PWMs.
Make objects that operate the Buzzer.
Set the Buzzer’s sound in the sound and duration parameters. sound can be
set using note names (C3-G9), MIDI note numbers (48-127), or frequency (asan integer), duration can be set in ms. If the duration parameter is left
unspecified, the Buzzer will keep playing until you call the off method.
bzr.on('50', duration=1000)# The buzzer will play the note corresponding
to MIDI note number 50 for 1 second.
bzr.on('C4', duration=1000)# The buzzer will play the note C4 for 1 second
bzr.on(440)
Make the Buzzer stop playing sound.
Make objects that operate the Temperature Sensor.
Returns the value (0-4095) of the Temperature Sensor in the Main Unit.
Returns the value of the Temperature Sensor in the Main Unit in degrees
Celsius.
Make objects that operate the Light Sensor.
Returns the value (0-4095) of the Light Sensor in the Main Unit.
Make an Accelerometer object by setting the fs parameter to 2g, 4g, 8g, or
16g to set maximum acceleration to measure, and the sf parameter to mg
or ms2 to pick your units of measurement.
The default settings are fs=2G and sf=ms2.
Measure acceleration along the x-axis.
Measure acceleration along the y-axis.
Measure acceleration along the x-axis.
=(get_x(), get_y(), get_z())
mode can be set with one of the following strings: sbmp (for Studuino:bit
MicroPython), sbs (for Studuino:bit Software) or mb (for micro:bit). It will be
set to sbmp by default.
Set the maximum acceleration to measure with 2g, 4g, 8g, or 16g.
Set the units of measurement with mg or ms2.
23

__init__(fs=’250dps’, sf=’dps’)

Gyroscope

StuduinoBitGyro

gyro

get_x
get_y
get_z
get_values()
set_axis(mode)
set_fs(value)
set_sf(value)__init__()
get_x
get_y
get_z
get_values()

Compass

StuduinoBitCompass

compass

set_axis(mode)
calibrate()
is_calibrated()clear_calibration()
heading()

BLE
Wireless

StuduinoBitBLE
StuduinoBitRadio

There are no__init()__Make a Gyroscope object by setting the fs parameter to 250dps, 500dps,
1000dps, or 2000dps to set maximum angular velocity to measure, and thesf parameter to dps or rps to pick your units of measurement.
The default settings are fs=250dps and sf=dps.
Measure angular velocity along the x-axis.
Measure angular velocity along the y-axis.
Measure angular velocity along the x-axis.
=(get_x(), get_y(), get_z())
mode can be set with one of the following strings: sbmp (for Studuino:bit
MicroPython), sbs (for Studuino:bit Software) or mb (for micro:bit). It will be
set to sbmp by default.
Set the maximum angular velocity to measure with 250dps, 500dps,
1000dps, or 2000dps.
Set the units of measurement with dps or rps.
Make objects that operate the Compass. The maximum measurable value is±4500μT, and the units are μT (micro teslas).
Finds the magnetic force along the x-axis.
Finds the magnetic force along the y-axis.
Finds the magnetic force along the z-axis.
=(get_x(), get_y(), get_z())
mode can be set with one of the following strings: sbmp (for Studuino:bit
MicroPython), sbs (for Studuino:bit Software) or mb (for micro:bit). It will be
set to sbmp by default.
Starts the Compass calibration process. Rotate the Main Unit until the LED
Display draws a full circle around its border.
Returns false True if the Compass has been calibrated and False if it
hasn’t.
Erases existing calibration data.
Finds which direction the Compass is facing. In integers 0-360°counting
clockwise, with 180°being North.
T.B.D
Make objects that operate the unit’s wireless communications.
24Communications

Wi-Fi

objects for thisclass.

StuduinoBitWiFi

Turns on wireless communications. Wireless communications must beon()
explicitly called up as they consume power and take up memory that may
be necessary for other functions.
Turns off wireless communications, conserving the unit’s power andoff()memory.
The following methods cannot be used unless wireless communications have been turned on.
Set the group parameter to a number between 0 and 255 to pick a group
start(group)and begin wireless communications.
send_number(n)Broadcasts a number. The number will be a 32-bit integer.
Broadcasts a number and variable name. The number will be a 32-bit
send_value(s, n)
integer, the the variable name can be up to 13 characters long.
send_string(s)Broadcasts a string. The string can be up to 19 characters long.
send_buffer(buf)Broadcasts a byte sequence. It can be up to 19 bytes.
recv()
Receives data. If no data has been received, returns None.
group(group=-1)
Set the group parameter to a number between 0 and 255 to pick a group.
T.B.D(★) The individual Digital Input/Output, Analog Input, and Digital and Analog Input/Output classes are intended to be made into instances. Instances are intended up be madevia the Terminal class.

082683 K0302
25

26