PCF8591.py
Go to the documentation of this file.
00001 #!/usr/bin/env python
00002 
00003 # 2014-08-26 PCF8591.py
00004 
00005 import time
00006 import curses
00007 
00008 import pigpio
00009 
00010 # sudo pigpiod
00011 # ./PCF8591.py
00012 
00013 # Connect Pi 3V3 - VCC, Ground - Ground, SDA - SDA, SCL - SCL.
00014 
00015 YL_40=0x48
00016 
00017 pi = pigpio.pi() # Connect to local Pi.
00018 
00019 handle = pi.i2c_open(1, YL_40, 0)
00020  
00021 stdscr = curses.initscr()
00022 
00023 curses.noecho()
00024 curses.cbreak()
00025 
00026 aout = 0
00027 
00028 stdscr.addstr(10, 0, "Brightness")
00029 stdscr.addstr(12, 0, "Temperature")
00030 stdscr.addstr(14, 0, "AOUT->AIN2")
00031 stdscr.addstr(16, 0, "Resistor")
00032 
00033 stdscr.nodelay(1)
00034 
00035 try:
00036    while True:
00037 
00038       for a in range(0,4):
00039          aout = aout + 1
00040          pi.i2c_write_byte_data(handle, 0x40 | ((a+1) & 0x03), aout&0xFF)
00041          v = pi.i2c_read_byte(handle)
00042          hashes = v / 4
00043          spaces = 64 - hashes
00044          stdscr.addstr(10+a*2, 12, str(v) + ' ')
00045          stdscr.addstr(10+a*2, 16, '#' * hashes + ' ' * spaces )
00046 
00047       stdscr.refresh()
00048       time.sleep(0.04)
00049 
00050       c = stdscr.getch()
00051 
00052       if c != curses.ERR:
00053          break
00054 
00055 except:
00056    pass
00057 
00058 curses.nocbreak()
00059 curses.echo()
00060 curses.endwin()
00061 
00062 pi.i2c_close(handle)
00063 pi.stop()
00064 


cob_hand_bridge
Author(s): Mathias Lüdtke
autogenerated on Thu Jun 6 2019 20:43:57