You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+1-1Lines changed: 1 addition & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -61,7 +61,7 @@ Reboot after this for the change to take effect.
61
61
62
62
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.
63
63
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`.
65
65
66
66
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`.
@@ -171,6 +182,7 @@ These give you access to objects that handle the motor and encoder functionality
171
182
172
183
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.
173
184
185
+
174
186
### Reading Motor Current
175
187
176
188
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)
181
193
182
194
The returned value is the current in amps (A).
183
195
196
+
184
197
### Skipping Initialisation
185
198
186
199
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.
This leaves `board.motors` and `board.encoders` set to `None`, letting you to use those board pins for any other purpose.
195
208
196
-
The pins available after this are:
209
+
The io expander pins available after this are:
197
210
198
211
*`board.IOE_MOTOR_A_PINS` = `(20, 19)`
199
212
*`board.IOE_MOTOR_B_PINS` = `(16, 15)`
@@ -203,7 +216,7 @@ The pins available after this are:
203
216
204
217
## Servos
205
218
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.
207
220
208
221
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:
209
222
@@ -218,9 +231,10 @@ From there the servo can be accessed by the following `board` variables:
218
231
servo = board.servos[SERVO_1]
219
232
```
220
233
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:
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.
This leaves `board.servos` set to `None`, letting you to use those board pins for any other purpose.
235
249
236
-
The pins available after this are:
250
+
The io expander pins available after this are:
237
251
238
252
*`board.IOE_SERVO_PINS` = `(23, 24, 25, 22)`
239
253
254
+
240
255
### As GPIOs
241
256
242
257
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.
243
258
244
-
To use a servo pin an input:
259
+
To use a servo pin as an input:
245
260
246
261
```python
247
262
# Initialise InventorHATMini without servos
@@ -254,7 +269,7 @@ board.servo_pin_mode(SERVO_1, IN) # or IN_PU of a pull-up is wanted
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.
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.
300
317
301
318
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.
302
319
303
320
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.
304
321
322
+
305
323
#### Limitations
306
324
307
325
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)
327
345
328
346
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.
329
347
348
+
330
349
## RGB LEDs
331
350
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:
333
352
334
353
```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
343
355
leds = board.leds
344
356
```
345
357
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:
347
359
*`board.leds`: [`Plasma` object](docs/plasma.md)
348
360
349
361
@@ -353,6 +365,7 @@ Inventor HAT Mini features an onboard I2S audio amplifier, letting it play any s
353
365
354
366
There are many ways sound can be created from code, some examples of which can be found in [examples/audio](/examples/audio/).
355
367
368
+
356
369
### Muting and Unmuting
357
370
358
371
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
362
375
363
376
## Watchdog Timer
364
377
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
+
366
384
367
385
### Configuring
368
386
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
+
369
408
### Activating
370
409
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
+
371
421
### Feeding
372
422
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
+
373
432
### Deactivating
374
433
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
+
376
452
377
453
## Function Reference
378
454
@@ -409,7 +485,6 @@ is_watchdog_active()
409
485
set_watchdog_control(divider)
410
486
```
411
487
412
-
413
488
## Constants Reference
414
489
415
490
Here is the complete list of constants on the `inventorhatmini` module:
0 commit comments