Files
python-gpiozero/docs/boards.md
2015-10-25 22:05:17 +00:00

295 lines
10 KiB
Markdown

# Add-on boards and accessories
These additional interfaces have been provided to group collections of
components together for ease of use, and as examples. They are made up of
components from the various [input devices](inputs.md) and
[output devices](outputs.md) provided by `gpiozero`. See those pages for more
information on using components individually.
*Note all GPIO pin numbers use BCM numbering. See the [notes](notes.md) page
for more information.*
## LED Board
A Generic LED Board or collection of LEDs.
### Code
Ensure the `LEDBoard` class is imported at the top of the file:
```python
from gpiozero import LEDBoard
```
Create an `LEDBoard` object by passing in the LED pin numbers:
```python
leds = LEDBoard(2, 3, 4, 5, 6)
```
#### Methods
| Method | Description | Arguments |
| ------ | ----------- | --------- |
| `on()` | Turn all the LEDs on. | None |
| `off()` | Turn all the LEDs off. | None |
| `toggle()` | Toggle all the LEDs. For each LED, if it's on, turn it off; if it's off, turn it on. | None |
| `blink()` | Make the LEDs turn on and off repeatedly. | `on_time` - The amount of time (in seconds) for the LED to be on each iteration. Default: `1` |
| | | `off_time` - The amount of time (in seconds) for the LED to be off each iteration. Default: `1` |
| | | `n` - The number of iterations. `None` means infinite. Default: `None` |
| | | `background` - If True, start a background thread to continue blinking and return immediately. If False, only return when the blink is finished (warning: the default value of n will result in this method never returning). Default: `True` |
#### Properties
| Property | Description | Type |
| -------- | ----------- | ---- |
| `leds` | A collection of LEDs to access each one individually, or to iterate over them in sequence. | Tuple |
## Traffic Lights
Generic Traffic Lights set.
### Code
Ensure the `TrafficLights` class is imported at the top of the file:
```python
from gpiozero import TrafficLights
```
Create a `TrafficLights` object by passing in the LED pin numbers by name:
```python
traffic = TrafficLights(red=2, amber=3, green=4)
```
or just in order (red, amber, green):
```python
traffic = TrafficLights(2, 3, 4)
```
#### Initialisation options
```python
TrafficLights(red=None, amber=None, green=None)
```
| Argument | Description | Values | Default |
| -------- | ----------- | ------ | ------- |
| `red` | The GPIO pin number the red LED is connected to. | Integer: `0` to `25` | *Required* |
| `green` | The GPIO pin number the green LED is connected to. | Integer: `0` to `25` | *Required* |
| `blue` | The GPIO pin number the blue LED is connected to. | Integer: `0` to `25` | *Required* |
#### Methods
| Method | Description | Arguments |
| ------ | ----------- | --------- |
| `on()` | Turn all three LEDs on. | None |
| `off()` | Turn all three LEDs off. | None |
| `toggle()` | Toggle all three LEDs. For each LED, if it's on, turn it off; if it's off, turn it on. | None |
| `blink()` | Make the LEDs turn on and off repeatedly. | `on_time` - The amount of time (in seconds) for the LED to be on each iteration. Default: `1` |
| | | `off_time` - The amount of time (in seconds) for the LED to be off each iteration. Default: `1` |
| | | `n` - The number of iterations. `None` means infinite. Default: `None` |
| | | `background` - If True, start a background thread to continue blinking and return immediately. If False, only return when the blink is finished (warning: the default value of n will result in this method never returning). Default: `True` |
#### Properties
| Property | Description | Type |
| -------- | ----------- | ---- |
| `red` | Direct access to the red light as a single `LED` object. | LED |
| `amber` | Direct access to the amber light as a single `LED` object. | LED |
| `green` | Direct access to the green light as a single `LED` object. | LED |
| `leds` | A collection of LEDs to access each one individually, or to iterate over them in sequence. | Tuple |
## PiLITEr
Ciseco Pi-LITEr: strip of 8 very bright LEDs.
### Code
Ensure the `PiLiter` class is imported at the top of the file:
```python
from gpiozero import PiLiter
```
Create a `PiLiter` object:
```python
lite = PiLiter()
```
#### Initialisation options
None
#### Methods
| Method | Description | Arguments |
| ------ | ----------- | --------- |
| `on()` | Turn all eight LEDs on. | None |
| `off()` | Turn all eight LEDs off. | None |
| `toggle()` | Toggle all eight LEDs. For each LED, if it's on, turn it off; if it's off, turn it on. | None |
| `blink()` | Make all the LEDs turn on and off repeatedly. | `on_time` - The amount of time (in seconds) for the LED to be on each iteration. Default: `1` |
| | | `off_time` - The amount of time (in seconds) for the LED to be off each iteration. Default: `1` |
| | | `n` - The number of iterations. `None` means infinite. Default: `None` |
| | | `background` - If True, start a background thread to continue blinking and return immediately. If False, only return when the blink is finished (warning: the default value of n will result in this method never returning). Default: `True` |
#### Properties
| Property | Description | Type |
| -------- | ----------- | ---- |
| `leds` | A collection of LEDs to access each one individually, or to iterate over them in sequence. | Tuple |
## PI-TRAFFIC
Low Voltage Labs PI-TRAFFIC: vertical traffic lights board on pins 9, 10 and 11.
Ensure the `PiTraffic` class is imported at the top of the file:
```python
from gpiozero import PiTraffic
```
Create a `PiTraffic` object:
```python
traffic = PiTraffic()
```
`PiTraffic` provides an identical interface to the generic `TrafficLights`
interface, without the need to specify the pin numbers to be used.
The interface is identical to the generic `TrafficLights` interface.
To use the PI-TRAFFIC board on another set of pins, just use the generic
`TrafficLights` interface.
## Fish Dish
Pi Supply Fish Dish: traffic light LEDs, a button and a buzzer.
### Code
Ensure the `FishDish` class is imported at the top of the file:
```python
from gpiozero import FishDish
```
Create a `FishDish` object:
```python
fish = FishDish()
```
#### Initialisation options
None
#### Methods
| Method | Description | Arguments |
| ------ | ----------- | --------- |
| `on()` | Turn all the board's output components on. | None |
| `off()` | Turn all the board's output components off. | None |
| `toggle()` | Toggle all the board's output components. For each component, if it's on, turn it off; if it's off, turn it on. | None || `toggle()` | Toggle all the LEDs. For each LED, if it's on, turn it off; if it's off, turn it on. | None |
| `blink()` | Make the LEDs turn on and off repeatedly. | `on_time` - The amount of time (in seconds) for the LED to be on each iteration. Default: `1` |
| | | `off_time` - The amount of time (in seconds) for the LED to be off each iteration. Default: `1` |
| | | `n` - The number of iterations. `None` means infinite. Default: `None` |
| | | `background` - If True, start a background thread to continue blinking and return immediately. If False, only return when the blink is finished (warning: the default value of n will result in this method never returning). Default: `True` |
#### Properties
| Property | Description | Type |
| -------- | ----------- | ---- |
| `lights` | Access to the three LEDs as a `TrafficLights` object. | TrafficLights |
| `buzzer` | Direct access to the buzzer as a single `Buzzer` object. | LED |
| `button` | Direct access to the button as a single `Button` object. | LED |
| `all` | A collection of the board's output components to access each one individually, or to iterate over them in sequence. | Tuple |
## Traffic HAT
Ryanteck Traffic HAT: traffic light LEDs, a button and a buzzer.
### Code
Ensure the `TrafficHat` class is imported at the top of the file:
```python
from gpiozero import TrafficHat
```
Create a `TrafficHat` object by passing in the LED pin numbers by name:
```python
traffic = TrafficHat()
```
The interface is identical to the `FishDish`.
## Robot
Generic two-motor robot.
### Code
Ensure the `Robot` class is imported at the top of the file:
```python
from gpiozero import Robot
```
Create a `Robot` object by passing in the pin numbers of the forward and back
pairs for each motor:
```python
robot = Robot(left=(4, 14), right=(17, 18))
```
#### Initialisation options
```python
Robot(left=None, right=None))
```
| Argument | Description | Values | Default |
| -------- | ----------- | ------ | ------- |
| `left` | The GPIO pins (forward and reverse) used by the left motor. | Tuple | *Required* |
| `right` | The GPIO pins (forward and reverse) used by the right motor. | Tuple | *Required* |
#### Methods
| Method | Description | Arguments |
| ------ | ----------- | --------- |
| `forward()` | Drive the robot forwards. | `speed` - Speed at which to drive the motors, `0` to `1`. Default: `1` |
| `backward()` | Drive the robot backwards. | `speed` - Speed at which to drive the motors, `0` to `1`. Default: `1` |
| `left()` | Make the robot turn left. | `speed` - Speed at which to drive the motors, `0` to `1`. Default: `1` |
| `right()` | Make the robot turn right. | `speed` - Speed at which to drive the motors, `0` to `1`. Default: `1` |
| `stop()` | Stop the robot. | None |
## Ryanteck MCB Robot
Generic robot controller with pre-configured pin numbers.
Ensure the `RyanteckRobot` class is imported at the top of the file:
```python
from gpiozero import RyanteckRobot
```
Create a `RyanteckRobot` object:
```python
robot = RyanteckRobot()
```
The interface is identical to the generic `Robot` interface.
There's no need to configure the pins if you're using the default pins
`(17, 18)` for the left motor and `(22, 23)` for the right motor.
To use the Ryanteck MCB on another set of pins, just use the generic `Robot`
interface.