mcp23017_input.py
# ! /usr/bin/python3
# -*- coding: utf-8 -*-
#
# mcp23017_input.py
#
# May/29/2017
#
# ----------------------------------------------------------------
import sys
import time
#
from subprocess import Popen,PIPE
#
# ----------------------------------------------------------------
# [4]:
def i2c_set_proc (command):
try:
p1 = Popen(command,shell=True,stdout=PIPE,stderr=PIPE)
stdout_data, stderr_data = p1.communicate()
except Exception as ee:
sys.stderr.write("*** error *** in i2c_set_proc ***\n")
sys.stderr.write(str (ee) + '\n')
#
# ----------------------------------------------------------------
# [6]:
def i2c_get_proc (command):
rvalue = ""
try:
p1 = Popen(command,shell=True,stdout=PIPE,stderr=PIPE)
stdout_data, stderr_data = p1.communicate()
rvalue = stdout_data.decode('utf-8')
except Exception as ee:
sys.stderr.write("*** error *** in i2c_get_proc ***\n")
sys.stderr.write(str (ee) + '\n')
#
return rvalue
# ----------------------------------------------------------------
sys.stderr.write("*** start ***\n")
command = "i2cset -y 1 0x20 0x01 0xFF"
i2c_set_proc(command)
#
command = "i2cset -y 1 0x20 0x0D 0xFF"
i2c_set_proc(command)
#
command = "i2cget -y 1 0x20 0x13"
value=i2c_get_proc(command)
sys.stderr.write("value = " + value + "\n")
#
sys.stderr.write("*** end ***\n")
# ----------------------------------------------------------------