Introduction¶
SimpleIO features a number of helpers to simplify hardware interactions. Many of the functions and classes are inspired by Arduino APIs to make it easier to move to CircuitPython from Arduino.
Dependencies¶
This driver depends on:
Please ensure all dependencies are available on the CircuitPython filesystem. This is easily achieved by downloading the Adafruit library and driver bundle.
Usage Example¶
TODO
Contributing¶
Contributions are welcome! Please read our Code of Conduct before contributing to help this project stay welcoming.
API Reference¶
simpleio
- Simple, beginner friendly IO.¶
The simpleio
module contains classes to provide simple access to IO.
-
class
simpleio.
DigitalIn
(pin)[source]¶ Simple digital input that is valid until soft reset.
-
value
¶ The digital logic level of the input pin.
-
-
class
simpleio.
DigitalOut
(pin)[source]¶ Simple digital output that is valid until soft reset.
-
value
¶ The digital logic level of the output pin.
-
-
class
simpleio.
Servo
(pin, min_pulse=0.5, max_pulse=2.5)[source]¶ Easy control for hobby (3-wire) servos
Parameters: Example for Metro M0 Express:
import simpleio import time from board import * pwm = simpleio.Servo(D9) while True: pwm.angle = 0 print("Angle: ", pwm.angle) time.sleep(2) pwm.angle = pwm.microseconds_to_angle(2500) print("Angle: ", pwm.angle) time.sleep(2)
-
angle
¶ Get and set the servo angle in degrees
-
-
simpleio.
bitWrite
(x, n, b)[source]¶ Based on the Arduino bitWrite function, changes a specific bit of a value to 0 or 1. The return value is the original value with the changed bit. This function is written for use with 8-bit shift registers
Parameters: - x – numeric value
- n – position to change starting with least-significant (right-most) bit as 0
- b – value to write (0 or 1)
-
simpleio.
map_range
(x, in_min, in_max, out_min, out_max)[source]¶ Maps a number from one range to another. Note: This implementation handles values < in_min differently than arduino’s map function does.
Returns: Returns value mapped to new range Return type: float
-
simpleio.
shift_in
(data_pin, clock, msb_first=True)[source]¶ Shifts in a byte of data one bit at a time. Starts from either the LSB or MSB.
Warning
Data and clock are swapped compared to other CircuitPython libraries in order to match Arduino.
Parameters: - data_pin (DigitalInOut) – pin on which to input each bit
- clock (DigitalInOut) – toggles to signal data_pin reads
- msb_first (bool) – True when the first bit is most significant
Returns: returns the value read
Return type:
-
simpleio.
shift_out
(data_pin, clock, value, msb_first=True)[source]¶ Shifts out a byte of data one bit at a time. Data gets written to a data pin. Then, the clock pulses hi then low
Warning
Data and clock are swapped compared to other CircuitPython libraries in order to match Arduino.
Parameters: - data_pin (DigitalInOut) – value bits get output on this pin
- clock (DigitalInOut) – toggled once the data pin is set
- msb_first (bool) – True when the first bit is most significant
- value (int) – byte to be shifted
Example for Metro M0 Express:
import digitalio import simpleio from board import * clock = digitalio.DigitalInOut(D12) data_pin = digitalio.DigitalInOut(D11) latchPin = digitalio.DigitalInOut(D10) clock.direction = digitalio.Direction.OUTPUT data_pin.direction = digitalio.Direction.OUTPUT latchPin.direction = digitalio.Direction.OUTPUT while True: valueSend = 500 # shifting out least significant bits # must toggle latchPin.value before and after shift_out to push to IC chip # this sample code was tested using latchPin.value = False simpleio.shift_out(data_pin, clock, (valueSend>>8), msb_first = False) latchPin.value = True time.sleep(1.0) latchPin.value = False simpleio.shift_out(data_pin, clock, valueSend, msb_first = False) latchPin.value = True time.sleep(1.0) # shifting out most significant bits latchPin.value = False simpleio.shift_out(data_pin, clock, (valueSend>>8)) latchPin.value = True time.sleep(1.0) latchpin.value = False simpleio.shift_out(data_pin, clock, valueSend) latchpin.value = True time.sleep(1.0)