Monitor Analog Inputs
Analog Inputs
The four analog inputs are converted from analog to digital using an I2C device, MAX11601. This is an 8-bit A/D converter meaning that the analog input can be represented by a number from 0 to 255. The maximum signal of 16V is scaled down to a level that the A/D can read. So 16V should read 255. When converting from analog to digital, there are various errors that are introduced. Please refer to the datasheet for descriptions on possible errors.
Python Test Program
import smbus
import time
from os import system
bus=smbus.SMBus(1)
***** Analog Input Defines
MAX11600_ADDRESS = 0x64 #shifted left
MAX11600_CHANNEL0 = 0x00
MAX11600_CHANNEL1 = 0x02
MAX11600_CHANNEL2 = 0x04
MAX11600_CHANNEL3 = 0x06
MAX11600_SINGLE = 0x01
MAX11600_SCAN_SINGLE =0x60
MAX11600_SETUP = 0x80
MAX11600_REF = 0x50
MAX11600_RST = 0x02
*** Function to initialize the MAX11601
def MAX11600_init():
out = MAX11600_SETUP+MAX11600_REF+MAX11600_RST
print "MAX11600 Setup:",hex(out)
bus.write_byte(MAX11600_ADDRESS,out)
*** Function to read a channel
def MAX11600_read(channel):
out = MAX11600_SCAN_SINGLE+channel+MAX11600_SINGLE
# print "MAX11600-Conf:",hex(out)
bus.write_byte(MAX11600_ADDRESS,out)
return bus.read_byte(MAX11600_ADDRESS)
***** Initialize the devices
MAX11600_init()
while True:
print ("Analog1:" MAX11600_read(MAX11600_CHANNEL0)
time.sleep(1)
print "Analog2",MAX11600_read(MAX11600_CHANNEL1)
time.sleep(1)
print "Analog3",MAX11600_read(MAX11600_CHANNEL2)
time.sleep(1)
print "Analog4",MAX11600_read(MAX11600_CHANNEL3)
#_ = system('clear')
time.sleep(1)