Raspberry Pi library for interaction with a Amperka TroykaHAT.
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.
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.
Use pip to install the library:
pip3 install troykahat
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