-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtest_blink.py
executable file
·51 lines (41 loc) · 1.52 KB
/
test_blink.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
#
# Copyright 2020 by Murray Altheim. All rights reserved. This file is part
# of the pimaster2ardslave project and is released under the MIT Licence;
# please see the LICENSE file included as part of this package.
#
# author: Murray Altheim
# created: 2020-04-30
# modified: 2020-05-04
#
# This test blinks an LED connected to pin 5 of the Arduino. This requires
# a Raspberry Pi connected to an Arduino over I²C on address 0x08. Because
# an LED cannot directly handle a 5 volt supply you should connect the LED
# to ground through a resistor of about 330 ohms. The exact value will
# depend on the dropping voltage of the LED (which varies) and how bright
# you want it to appear.
#
# This also requires installation of pigpio, e.g.:
#
# % sudo pip3 install pigpio
#
from lib.logger import Level
from lib.i2c_master import I2cMaster
# ..............................................................................
def main():
try:
_device_id = 0x08 # must match Arduino's SLAVE_I2C_ADDRESS
_master = I2cMaster(_device_id, Level.INFO)
if _master is not None:
_master.test_blink_led(7) # see documentation for hardware configuration
else:
raise Exception('unable to establish contact with Arduino on address 0x{:02X}'.format(_device_id))
except KeyboardInterrupt:
self._log.warning('Ctrl-C caught; exiting...')
finally:
if _master:
_master.close()
if __name__== "__main__":
main()
#EOF