PCF8591.py
Go to the documentation of this file.
1 #!/usr/bin/env python
2 
3 # 2014-08-26 PCF8591.py
4 
5 import time
6 import curses
7 
8 import pigpio
9 
10 # sudo pigpiod
11 # ./PCF8591.py
12 
13 # Connect Pi 3V3 - VCC, Ground - Ground, SDA - SDA, SCL - SCL.
14 
15 YL_40=0x48
16 
17 pi = pigpio.pi() # Connect to local Pi.
18 
19 handle = pi.i2c_open(1, YL_40, 0)
20 
21 stdscr = curses.initscr()
22 
23 curses.noecho()
24 curses.cbreak()
25 
26 aout = 0
27 
28 stdscr.addstr(10, 0, "Brightness")
29 stdscr.addstr(12, 0, "Temperature")
30 stdscr.addstr(14, 0, "AOUT->AIN2")
31 stdscr.addstr(16, 0, "Resistor")
32 
33 stdscr.nodelay(1)
34 
35 try:
36  while True:
37 
38  for a in range(0,4):
39  aout = aout + 1
40  pi.i2c_write_byte_data(handle, 0x40 | ((a+1) & 0x03), aout&0xFF)
41  v = pi.i2c_read_byte(handle)
42  hashes = v / 4
43  spaces = 64 - hashes
44  stdscr.addstr(10+a*2, 12, str(v) + ' ')
45  stdscr.addstr(10+a*2, 16, '#' * hashes + ' ' * spaces )
46 
47  stdscr.refresh()
48  time.sleep(0.04)
49 
50  c = stdscr.getch()
51 
52  if c != curses.ERR:
53  break
54 
55 except:
56  pass
57 
58 curses.nocbreak()
59 curses.echo()
60 curses.endwin()
61 
62 pi.i2c_close(handle)
63 pi.stop()
64 


cob_hand_bridge
Author(s): Mathias Lüdtke
autogenerated on Tue Oct 20 2020 03:35:57