Raspberry Pi library for interaction with a Amperka TroykaHAT.
Project description
TroykaHatPython
Raspberry Pi library for interaction with a Amperka TroykaHAT.
Enabled I²C Interface
If you haven’t enabled I²C support in your Raspbian Linux yet, open the terminal and run the following commands:
- Run
sudo raspi-config
. - Use the down arrow to select Interfacing Options.
- Arrow down to I²C.
- Select <Yes> when it asks you to enable I²C.
- Press <Ok> when it tells you that I²C is enabled.
- Use the right arrow to select the <Finish> button.
- Reboot your Raspberry Pi to make the I²C interface appear.
After the reboot, log in and enter the following command:
$ ls /dev/i2c*
The Pi should respond with:
/dev/i2c-1
This means that the I²C is on.
Testing I²C Device Connection
For testing connection Troyka HAT board to Raspberry Pi, useful package I²C scanner.
Install the I²C scanner.
sudo apt-get install i2c-tools
Turn it on.
sudo i2cdetect -y 1
In response, Raspberry Pi will show the addresses of all connected I²C devices. Check if the 0x2A
address is present.
Installation Library
Use pip to install the library:
pip3 install troykahat
Quickstart example
import troykahat
from time import sleep
# Constant for Pin 7 of Wiring PI IO.
# Connect an LED to this pin.
PIN_WP_LED = 7
# Constant for Pin 7 of Analog PI IO.
# Connect an LED to this pin.
PIN_AP_LED = 7
# Gives access to all the functions of GPIO, that are labeled "Wiring PI IO" on the HAT.
# Check WiringPI library API (https://github.com/WiringPi/WiringPi-Python)
# for the functions reference.
wp = troykahat.wiringpi_io()
# Gives access to all the functions of GPIO, that are labeled "Analog IO" on the HAT.
# Check API.md for the functions reference.
ap = troykahat.analog_io()
# Configures the LED pin of Wiring PI IO to an output mode.
wp.pinMode(PIN_WP_LED, wp.OUTPUT)
# Configures the LED pin of Analog IO to an output mode.
ap.pinMode(PIN_AP_LED, ap.OUTPUT)
while True:
# Sets HIGH voltage level for the LED pin of Wiring PI IO.
wp.digitalWrite(PIN_WP_LED, True)
# Sets HIGH voltage level for the LED pin of Analog IO.
ap.digitalWrite(PIN_AP_LED, True)
# Wait 500 ms.
sleep(0.5)
# Sets HIGH voltage level for the LED pin of Wiring PI IO.
wp.digitalWrite(PIN_WP_LED, False)
# Sets HIGH voltage level for the LED pin of Analog IO.
ap.digitalWrite(PIN_AP_LED, False)
# Wait 500 ms.
sleep(0.5)
See full API reference in API.md
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
File details
Details for the file troykahat-1.0.0.tar.gz
.
File metadata
- Download URL: troykahat-1.0.0.tar.gz
- Upload date:
- Size: 17.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.4.1 importlib_metadata/4.0.1 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.61.0 CPython/3.9.5
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 26f50313baad2d342597fcfc8db60cb11773e3e53a5789afcf4a71fd24ae1822 |
|
MD5 | 32c6cd8c30289411d48db2ccd8630d45 |
|
BLAKE2b-256 | bbcedf57c55772ff3d65058a54ede06c6e6df25da8de5d76f3f1235dee8e174e |