Skip to content

Commit d94997d

Browse files
Finished off reference readme, and a few tweaks
1 parent 4d1cd6c commit d94997d

3 files changed

Lines changed: 99 additions & 24 deletions

File tree

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ Reboot after this for the change to take effect.
6161

6262
To use the audio output of your Inventor HAT Mini you will need to modifying your Pi's configuration file. To do this run `sudo nano /boot/config.txt` to open a terminal text editor.
6363

64-
Within the editor navigate to the bottom of the file and include the lines `dtoverlay=hifiberry-dac` and `gpio=25=op,dh`. The first line switches the audio to use the GPIO header of your Pi for audio output, and the second line will cause your Pi to enable the audio output on bootup, by setting pin BCM 25 to high. Then scroll up to find any existing mention to `dtparam=i2s=on`. If it is commented out with a `#` or says `off`, change it to `on`.
64+
Within the editor navigate to the bottom of the file and include the lines `dtoverlay=hifiberry-dac` and `gpio=25=op,dh`. The first line switches the audio to use the GPIO header of your Pi for audio output, and the second line will cause your Pi to enable the audio output on bootup, by setting pin BCM 25 to high. Then navigate up to the line `dtparam=i2s=on`. If this says `off` or is commented out with a `#`, uncomment it and change it to `on`.
6565

6666
Depending on your setup, you may also need to disable other audio outputs of your Pi (for example audio over HDMI). Look through the file for any existing mention to `dtparam=audio=on` and change it to `dtparam=audio=off`. There may the line `dtoverlay=vc4-kms-v3d`. Modify this to be `dtoverlay=vc4-kms-v3d,noaudio`.
6767

REFERENCE.md

Lines changed: 97 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,21 @@ This is the library reference for the [Pimoroni Inventor HAT Mini](https://pimor
1818
- [Reading Motor Current](#reading-motor-current)
1919
- [Skipping Initialisation](#skipping-initialisation)
2020
- [Servos](#servos)
21-
21+
- [Skipping Initialisation](#skipping-initialisation-1)
22+
- [As GPIOs](#as-gpios)
23+
- [As PWM](#as-pwm)
24+
- [Delayed Loading](#delayed-loading)
25+
- [Limitations](#limitations)
26+
- [As Motor](#as-motor)
27+
- [RGB LEDs](#rgb-leds)
2228
- [Audio](#audio)
2329
- [Muting and Unmuting](#muting-and-unmuting)
24-
30+
- [Watchdog Timer](#watchdog-timer)
31+
- [Configuring](#configuring)
32+
- [Activating](#activating)
33+
- [Feeding](#feeding)
34+
- [Deactivating](#deactivating)
35+
- [Handling a Time-Out](#handling-a-time-out)
2536
- [Function Reference](#function-reference)
2637
- [Constants Reference](#constants-reference)
2738
- [Motor Constants](#motor-constants)
@@ -171,6 +182,7 @@ These give you access to objects that handle the motor and encoder functionality
171182

172183
The motor outputs of Inventor HAT Mini can be enabled and disabled at any time by calling `.enable_motors()` and `.disable_motors()`. These functions call both motor's respective `.enable()` and `.disable()` functions.
173184

185+
174186
### Reading Motor Current
175187

176188
The current draw of each motor output can be measured by calling `.read_motor_current(motor)`, where motor is either `MOTOR_A` or `MOTOR_B`:
@@ -181,6 +193,7 @@ current = board.read_motor_current(MOTOR_A)
181193

182194
The returned value is the current in amps (A).
183195

196+
184197
### Skipping Initialisation
185198

186199
For some projects the automatic initialisation of motors and their encoders may not be wanted. For example if you instead wanted to use the motor outputs to drive another kind of inductive load.
@@ -193,7 +206,7 @@ board = InventorHATMini(init_motors=False)
193206

194207
This leaves `board.motors` and `board.encoders` set to `None`, letting you to use those board pins for any other purpose.
195208

196-
The pins available after this are:
209+
The io expander pins available after this are:
197210

198211
* `board.IOE_MOTOR_A_PINS` = `(20, 19)`
199212
* `board.IOE_MOTOR_B_PINS` = `(16, 15)`
@@ -203,7 +216,7 @@ The pins available after this are:
203216

204217
## Servos
205218

206-
Inventor HAT Mini four servo outputs. These are setup by default when creating a new `InventorHATMini` object.
219+
Inventor HAT Mini has four servo outputs. These are setup by default when creating a new `InventorHATMini` object.
207220

208221
To start using a servo, first import one of the handy constants used to reference them (see [Servo Constants](#servo-constants)). For example, to use the first servo:
209222

@@ -218,9 +231,10 @@ From there the servo can be accessed by the following `board` variables:
218231
servo = board.servos[SERVO_1]
219232
```
220233

221-
This gives you access to an object that handle the servo functionality. For details of what can be done with them, check out their respective documentation pages:
234+
This gives you access to an object that handle the servo functionality. For details of what can be done with it, check out its documentation page:
222235
* `board.servos`: [`Servo` object](https://github.com/pimoroni/ioe-python/blob/master/docs/servo.md)
223236

237+
224238
### Skipping Initialisation
225239

226240
For some projects the automatic initialisation of servos may not be wanted. For example if you instead wanted to use the servo outputs to drive another kind of PWM device.
@@ -233,15 +247,16 @@ board = InventorHATMini(init_servos=False)
233247

234248
This leaves `board.servos` set to `None`, letting you to use those board pins for any other purpose.
235249

236-
The pins available after this are:
250+
The io expander pins available after this are:
237251

238252
* `board.IOE_SERVO_PINS` = `(23, 24, 25, 22)`
239253

254+
240255
### As GPIOs
241256

242257
With servos uninitialised, the servo pins can be interacted with like regular GPIO pins (see [GPIOs](#gpios)), using the functions `.servo_pin_mode()` and `.servo_pin_value()`. The one exception to this is that these pins are not ADC capable.
243258

244-
To use a servo pin an input:
259+
To use a servo pin as an input:
245260

246261
```python
247262
# Initialise InventorHATMini without servos
@@ -254,7 +269,7 @@ board.servo_pin_mode(SERVO_1, IN) # or IN_PU of a pull-up is wanted
254269
value = board.servo_pin_value(SERVO_1)
255270
```
256271

257-
To use a servo pin an output:
272+
To use a servo pin as an output:
258273

259274
```python
260275
# Initialise InventorHATMini without servos
@@ -267,6 +282,7 @@ board.servo_pin_mode(SERVO_1, OUT)
267282
board.servo_pin_value(i, True)
268283
```
269284

285+
270286
### As PWM
271287

272288
To support their use with servos, the servo pins accept the `PWM` pin mode. This constant can be imported from the `ioexpander` module, and passed into the `.servo_pin_mode()` function.
@@ -294,14 +310,16 @@ board.servo_pin_frequency(SERVO_1, 25000)
294310
board.servo_pin_value(SERVO_1, 0.5)
295311
```
296312

297-
#### Delayed PWM Loading
313+
314+
#### Delayed Loading
298315

299316
By default, changes to a servo pin's frequency or value are applied immediately. However, sometimes this may not be wanted, and instead you want all pins to receive updated parameters at the same time, regardless of how long the code ran that calculated the update.
300317

301318
For this purpose, `.servo_pin_frequency()` and `.servo_pin_value()` include an optional parameter `load`, which by default is `True`. To avoid this "loading" include `load=False` in the relevant function calls. Then either the last call can include `load=True`, or a specific call to `.servo_pin_load()` can be made.
302319

303320
In addition, any function that performs a load, including the `.servo_pin_load()` function, can be made to wait until the new PWM value has been sent out of the pins. By default this is disabled, but can be enabled by including `wait_for_load=True` in the relevant function calls.
304321

322+
305323
#### Limitations
306324

307325
Inventor HAT Mini has limitations on which PWM signals can be controlled independently. For the servo pins, this means that Servo 1 and 2 must share the same frequency, and similarly for Servo 3 and 4.
@@ -327,23 +345,17 @@ motor = board.motor_from_servo_pins(SERVO_1, SERVO_2)
327345

328346
This function returns a new `Motor` object that uses the specified pins. To use this object, refer to the [`Motor` object](https://github.com/pimoroni/ioe-python/blob/master/docs/motor.md) reference.
329347

348+
330349
## RGB LEDs
331350

332-
To make getting started with Inventor HAT Mini easier, the necessary objects for interacting with motors, encoders, servos, and leds are automatically initialised when creating a new `InventorHATMini` object. These can be accessed as variables, like so:
351+
There are 8 independently addressable RGB LEDs on Inventor HAT Mini, positioned nearby the four servo and four GPIO pins. These LEDs are automatically initialised when creating a new `InventorHATMini` object and can be accessed using the following variable:
333352

334353
```python
335-
# Access a motor and its encoder
336-
motor = board.motors[MOTOR_A]
337-
encoder = board.encoders[MOTOR_A]
338-
339-
# Access a servo
340-
servo = board.servos[SERVO_1]
341-
342-
# Access the Neopixel LEDs
354+
# Access the RGB LEDs
343355
leds = board.leds
344356
```
345357

346-
For details of what can be done with these objects, check out their respective documentation pages:
358+
For details of what can be done with this object, check out its documentation page:
347359
* `board.leds`: [`Plasma` object](docs/plasma.md)
348360

349361

@@ -353,6 +365,7 @@ Inventor HAT Mini features an onboard I2S audio amplifier, letting it play any s
353365

354366
There are many ways sound can be created from code, some examples of which can be found in [examples/audio](/examples/audio/).
355367

368+
356369
### Muting and Unmuting
357370

358371
The audio output of Inventor HAT Mini can be muted at any time by calling `.mute_audio()`. Similarly, the audio output can be unmuted by calling `.unmute_audio()`.
@@ -362,17 +375,80 @@ Additionally, when creating a new `InventorHATMini` object, the starting audio o
362375

363376
## Watchdog Timer
364377

365-
Inventor HAT Mini features an onboard [Watchdog timer](https://en.wikipedia.org/wiki/Watchdog_timer), that can be used to turn off motor and servo outputs in the event of an issue with your code.
378+
Inventor HAT Mini features an onboard [Watchdog timer](https://en.wikipedia.org/wiki/Watchdog_timer), that can be used to turn off motor and servo outputs in the event of an issue with your code that stops it communicating with the board.
379+
380+
This is especially useful if you are creating a driving robot, to stop it from driving off uncontrolled!
381+
382+
To see an example of the Watchdog timer in action, visit [examples/extras/watchdog_reset.py](examples/extras/watchdog_reset.py).
383+
366384

367385
### Configuring
368386

387+
To start using the watchdog timer, first it's duration needs to be set. This is done using the `.set_watchdog_control()` function, which accepts one of the following multiple of 2 clock divider values:
388+
389+
| Clock Divider | Time-Out |
390+
|-----------------|----------|
391+
| 1 | 6.40ms |
392+
| 2 | - |
393+
| 4 | 25.6ms |
394+
| 8 | 51.2ms |
395+
| 16 | 102.4ms |
396+
| 32 | 204.8ms |
397+
| 64 | 409.6ms |
398+
| 128 | 819.2ms |
399+
| 256 | 1.638s |
400+
401+
For example, here is how to set the watchdog to the longest time-out:
402+
403+
```python
404+
board.set_watchdog_control(256)
405+
```
406+
407+
369408
### Activating
370409

410+
Once configured, the watchdog can be activated by calling:
411+
412+
```python
413+
board.activate_watchdog()
414+
```
415+
416+
There is now limited time (1.638 seconds in this example) to communicate with the Inventor HAT Mini before the watchdog timer reaches zero and resets the board!
417+
418+
The active state of the watchdog timer can be checked by calling `.is_watchdog_active()`.
419+
420+
371421
### Feeding
372422

423+
To prevent the watchdog time from reaching zero, your code needs to "feed" the watchdog regularly. This is done by calling:
424+
425+
```python
426+
board.feed_watchdog()
427+
```
428+
429+
This will return the watchdog timer back up to the original value it was at when activated.
430+
431+
373432
### Deactivating
374433

375-
### Checking
434+
If your code reaches a point where you know it will take longer than the time set, or you otherwise no longer need the watchdog, it can be deactivated by calling:
435+
436+
```python
437+
board.deactivate_watchdog()
438+
```
439+
440+
441+
### Handling a Time-Out
442+
443+
If the watchdog does reset your Inventor HAT Mini whilst your code is running, it is possible to check for this by calling `.watchdog_timeout_occurred()`, then handle the event. The `InventorHATMini` class has a `.reinit()` function intended for this exact case:
444+
445+
```python
446+
if board.watchdog_timeout_occurred():
447+
board.reinit()
448+
```
449+
450+
There is also `.clear_watchdog_timeout()` that should be called if you wanted to configure Inventor HAT Mini without calling `.reinit()`.
451+
376452

377453
## Function Reference
378454

@@ -409,7 +485,6 @@ is_watchdog_active()
409485
set_watchdog_control(divider)
410486
```
411487

412-
413488
## Constants Reference
414489

415490
Here is the complete list of constants on the `inventorhatmini` module:

examples/extras/watchdog_reset.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ def sleep_until(end_time):
3434
offset = 0.0
3535

3636
# Configure and activate the watchdog
37-
board.set_watchdog_control(128) # Accepts a multiple of two, up to 128
37+
board.set_watchdog_control(256) # Accepts a multiple of two (except 4), up to 256
3838
board.activate_watchdog()
3939
print("Watchdog active")
4040

0 commit comments

Comments
 (0)