Merge pull request #532 from pimoroni/hel-automation-mini

Automation Mini tidyup
hel-enviroplus-into-adafruit
Hel Gibbons 2022-10-06 16:09:41 +01:00 zatwierdzone przez GitHub
commit a27a539a1f
Nie znaleziono w bazie danych klucza dla tego podpisu
ID klucza GPG: 4AEE18F83AFDEB23
7 zmienionych plików z 72 dodań i 24 usunięć

Wyświetl plik

@ -1,6 +1,7 @@
# Automation 2040 W Micropython Examples <!-- omit in toc -->
- [Function Examples](#function-examples)
- [PWM Outputs](#pwm-outputs)
- [Read ADCs](#read-adcs)
- [Read Inputs](#read-inputs)
- [Toggle Relays](#toggle-relays)
@ -13,16 +14,23 @@
## Function Examples
These examples will work with Automation 2040 W and Automation 2040 W Mini. If you have an Automation 2040 W Mini, initialise your board with `board = Automation2040WMini` to see the correct numbers of inputs, outputs and relays!
### PWM Outputs
[pwm_outputs.py](pwm_outputs.py)
Shows how to PWM the output terminals of Automation 2040 W.
### Read ADCs
[read_adcs.py](read_adcs.py)
Shows how to read the 3 ADC terminals of Automation 2040 W.
Shows how to read the ADC terminals of Automation 2040 W.
### Read Inputs
[read_inputs.py](read_inputs.py)
Shows how to read the 3 Input terminals of Automation 2040 W.
Shows how to read the input terminals of Automation 2040 W.
### Toggle Relays
@ -50,11 +58,11 @@ A simple program that resets Automation 2040 W, turning off its Relays, Outputs,
## Wireless Examples
The wireless examples need `network_manager.py` and `WIFI_CONFIG.py` from the `common` directory to be saved to your Pico W. Open up `WIFI_CONFIG.py` in Thonny to add your wifi details (and save it when you're done).
The wireless examples need `network_manager.py` and `WIFI_CONFIG.py` from the `micropython/examples/common` directory to be saved to your Pico W. Open up `WIFI_CONFIG.py` in Thonny to add your wifi details (and save it when you're done).
### Web IO Interface
[web_io_interface/](web_io_interface/)
Provides a basic web interface for all your Automation 2040W features.
Needs `lib/tinyweb` from `common`!
Needs `lib/tinyweb` from `micropython/examples/common`!

Wyświetl plik

@ -1,6 +1,9 @@
import time
from automation import Automation2040W, SWITCH_A
# Uncomment for Automation2040W Mini and comment out above import
# from automation import Automation2040WMini, SWITCH_A
"""
Demonstrates how to toggle each of Automation 2040 W's output terminals.
@ -12,6 +15,8 @@ OUTPUT_NAMES = ("O1", "O2", "O3") # The friendly names to give each digital ou
# Create a new Automation2040W
board = Automation2040W()
# Uncomment for Automation2040W Mini
# board = Automation2040WMini()
# Enable the LED of the switch used to exit the loop
board.switch_led(SWITCH_A, 50) # Half Brightness

Wyświetl plik

@ -1,7 +1,7 @@
import time
from automation import Automation2040W, SWITCH_A
# Uncomment fo Automation2040W Mini and comment out above import
# Uncomment for Automation2040W Mini and comment out above import
# from automation import Automation2040WMini, SWITCH_A
"""
@ -15,7 +15,7 @@ INPUT_NAMES = ("I1", "I2", "I3", "I4") # The friendly names to give each digita
# Create a new Automation2040W
board = Automation2040W()
# Uncomment fo Automation2040W Mini
# Uncomment for Automation2040W Mini
# board = Automation2040WMini()
# Enable the LED of the switch used to exit the loop

Wyświetl plik

@ -1,6 +1,9 @@
import time
from automation import Automation2040W, SWITCH_A
# Uncomment for Automation2040W Mini and comment out above import
# from automation import Automation2040WMini, SWITCH_A
"""
Demonstrates how to toggle each of Automation 2040 W's output terminals.
@ -12,6 +15,8 @@ OUTPUT_NAMES = ("O1", "O2", "O3") # The friendly names to give each digital ou
# Create a new Automation2040W
board = Automation2040W()
# Uncomment for Automation2040W Mini
# board = Automation2040WMini()
# Enable the LED of the switch used to exit the loop
board.switch_led(SWITCH_A, 50) # Half Brightness

Wyświetl plik

@ -1,6 +1,9 @@
import time
from automation import Automation2040W, SWITCH_A
# Uncomment for Automation2040W Mini and comment out above import
# from automation import Automation2040WMini, SWITCH_A
"""
Demonstrates how to toggle the actuation state of each of Automation 2040 W's relays.
@ -12,7 +15,7 @@ RELAY_NAMES = ("R1", "R2", "R3") # The friendly names to give each relay
# Create a new Automation2040W
board = Automation2040W()
# Uncomment fo Automation2040W Mini
# Uncomment for Automation2040W Mini
# board = Automation2040WMini()
# Enable the LED of the switch used to exit the loop

Wyświetl plik

@ -1,9 +1,10 @@
# Automation 2040W MicroPython <!-- omit in toc -->
# Automation 2040 W MicroPython <!-- omit in toc -->
This library offers convenient functions for interacting with your new [Pimoroni Automation 2040W](https://shop.pimoroni.com/products/automation-2040-w), an all-in-one, Pico W powered industrial/automation controller with 2.4GHz wireless connectivity, relays and a plethora of inputs and outputs.
This library offers convenient functions for interacting with [Automation 2040 W](https://shop.pimoroni.com/products/automation-2040-w) and [Automation 2040 W Mini](https://shop.pimoroni.com/products/automation-2040-w-mini) - all-in-one, Pico W powered industrial/automation controllers with 2.4GHz wireless connectivity, relays and a plethora of inputs and outputs.
## Table of Content
- [Automation 2040W Class](#automation-2040w-class)
- [Table of Content](#table-of-content)
- [Automation Classes](#automation-classes)
- [User Switches and LEDs](#user-switches-and-leds)
- [Connectivity LED](#connectivity-led)
- [Actuating the Relays](#actuating-the-relays)
@ -17,43 +18,53 @@ This library offers convenient functions for interacting with your new [Pimoroni
- [Function Reference](#function-reference)
## Automation 2040W Class
## Automation Classes
The `Automation2040W` class deals with the initialisation of each of the board's functions. To create one, import the `automation` module, then define a new `board` variable:
The `Automation2040W` and `Automation2040WMini` classes deal with the initialisation of each of the board's functions. To create one, import the `automation` module, then define a new `board` variable:
For Automation 2040 W:
```python
import automation
board = automation.Automation2040W()
```
From here, all features of Automation 2040W can be accessed by calling functions on `board`. In addition, when using Qwiic / Stemma QT devices, the I2C channel to use can be accessed with `board.i2c`.
For Automation 2040 W Mini:
```python
import automation
board = automation.Automation2040WMini()
```
From here, all features can be accessed by calling functions on `board`. In addition, when using Qwiic / Stemma QT devices, the I2C channel to use can be accessed with `board.i2c`.
Automation 2040 W Mini has the same pinout as Automation 2040 W, but with fewer inputs, outputs and relays.
### User Switches and LEDs
Automation 2040W has two handy switches onboard, with neighbouring LEDs, offering a tactile way to interact with your program and be notified of actions that need attention.
Automation 2040 W has two handy switches onboard with neighbouring LEDs, offering a tactile way to interact with your program and be notified of actions that need attention.
To read one of the switches, call `.switch_pressed(switch)`, where `switch` is a value from `0` to `.NUM_SWITCHES - 1`. This returns `True` when the specified switch is pressed, and `False` otherwise.
To set a switch's neighbouring LED, call `.switch_led(switch, brightness)`, where `switch` is a value from `0` to `.NUM_SWITCHES - 1`, and `brightness` is either `True`, `False`, or a number from `0.0` to `100.0`.
To make it easier to use a specific switch or it's LED, the `automation` module contains these handy constants:
To make it easier to use a specific switch or its LED, the `automation` module contains these handy constants:
* `SWITCH_A` = `0`
* `SWITCH_B` = `1`
### Connectivity LED
In addition to the Switch LEDs, Automation 2040W has a user-controllable connectivity LED near the top-right of the board.
In addition to the Switch LEDs, Automation 2040 W has a user-controllable connectivity LED near the top-right of the board.
To set this led, call `.conn_led(brightness)`, where `brightness` is either `True`, `False`, or a number from `0.0` to `100.0`.
### Actuating the Relays
Three relays are featured on Automation 2040W. By default these are in a released state, which connects the terminal labelled `NC` to `COM`. By actuating them, a connection from `NO` to `COM` can be made instead.
Three relays are featured on Automation 2040 W (one on the Mini version). By default these are in a released state, which connects the terminal labelled `NC` to `COM`. By actuating them, a connection from `NO` to `COM` can be made instead.
A relay can be actuated by calling `.actuate_relay(relay)`, or released by calling `.release_relay(relay)`. Additionally the actuated state can be set by providing a boolean to the `actuate` parameter of `.relay(relay, actuate)`.
@ -67,7 +78,7 @@ For all these functions, `relay` is a value from `0` to `.NUM_RELAYS - 1`. To co
### Setting the Outputs
Three sourcing outputs, capable of PWM at up to 2A, are present on Automation 2040W.
Three sourcing outputs, capable of PWM at up to 2A, are present on Automation 2040 W (two on the Mini version).
An output can be controlled by calling `.output(output, value)`, where `output` is a value from `0` to `.NUM_OUTPUTS - 1`, and `value` is `True`, `False` or a number between `0.0` and `100.0`
@ -91,7 +102,7 @@ The PWM frequency of the output can be set by calling `.change_output_freq(outpu
### Reading the Inputs
Automation 2040W has four buffered digital inputs. These can be read by calling `.read_input(input)`, where `input` is a value from `0` to `.NUM_INPUTS - 1`.
Automation 2040 W has four buffered digital inputs (two on the Mini version). These can be read by calling `.read_input(input)`, where `input` is a value from `0` to `.NUM_INPUTS - 1`.
To read a specific input, the `automation` module contains these handy constants:
* `INPUT_1` = `0`
@ -102,7 +113,7 @@ To read a specific input, the `automation` module contains these handy constants
### Reading the ADCs
Automation 2040W has three analog inputs, capable of reading up to 40V. The voltage on these can be read by calling `.read_adc(adc)`, where `adc` is a value from `0` to `.NUM_ADCS - 1`.
Automation 2040 W has three analog inputs, capable of reading up to 40V. The voltage on these can be read by calling `.read_adc(adc)`, where `adc` is a value from `0` to `.NUM_ADCS - 1`.
To read a specific adc, the `automation` module contains these handy constants:
* `ADC_1` = `0`
@ -112,7 +123,7 @@ To read a specific adc, the `automation` module contains these handy constants:
### Extra GPIOs
On the left hand side of Automation 2040W are three GPIO pins. These are 3.3V logic only, and are connected to GP0, GP1, and GP2 of the Pico W. These pins can be referenced in code using `0`, `1`, and `2`, or by one of these handy constants on the `automation` module:
On the left hand side of Automation 2040 W are three GPIO pins. These are 3.3V logic only, and are connected to GP0, GP1, and GP2 of the Pico W. These pins can be referenced in code using `0`, `1`, and `2`, or by one of these handy constants on the `automation` module:
* `GP0` = `0`
* `GP1` = `1`
* `GP2` = `2`
@ -122,12 +133,12 @@ There is also a `.NUM_GPIOS` for times when any iteration needs to be performed.
### Software Reset
If there is a need to put Automation 2040W back into a known safe-state, without resorting to the hardware reset switch, then `.reset()` can be called. This deactivates all outputs, releases all relays, and turns off all user-controllable LEDs.
If there is a need to put Automation 2040 W back into a known safe-state, without resorting to the hardware reset switch, then `.reset()` can be called. This deactivates all outputs, releases all relays, and turns off all user-controllable LEDs.
### Function Reference
Here is the complete list of functions available on the `Automation2040W` class:
Here is the complete list of functions available on the `Automation2040W` and `Automation20404Mini` classes:
```python
Automation2040W()
@ -145,4 +156,20 @@ change_output_freq(output, freq)
read_input(input)
read_adc(adc)
reset()
Automation2040WMini()
conn_led(brightness)
switch_pressed(switch)
switch_led(switch, brightness)
relay(relay)
relay(relay, actuate)
actuate_relay(relay)
release_relay(relay)
output(output)
output(output, value)
output_percent(output)
change_output_freq(output, freq)
read_input(input)
read_adc(adc)
reset()
```

Wyświetl plik

@ -306,7 +306,7 @@ class Automation2040WMini():
self.__conn_led_pwm.duty_u16(65535)
elif brightness is False:
self.__conn_led_pwm.duty_u16(0)
elif brightness > 0.0 or brightness > 100.0:
elif brightness < 0.0 or brightness > 100.0:
raise ValueError("brightness out of range. Expected 0 to 100, or True or False")
else:
gamma = 2.8