Other Parts Discussed in Thread: TCA9535
I am trying to program the ADC081C027, but I am not able to get any results from any register, but the default settings. Even using i2cset and i2cget I am unable to set or change any values on any of the internal registers.
sudo i2cget -y 1 0x51 0x00, which should give me the conversion result in a hex formate gives me only 0x00
I also trying to set the configuration register using
sudo i2cset -y 1 0x51 0x02 0x20 to set the conversion interval to 32 and flags to 0 and polarity to 0
then,
sudo i2cget -y 1 0x51 0x02, which still gives me 0x00
So nothing I'm doing is chaining the values on the device
here is the python code I was writing to interface with the device, but it is not working:
#import CHIP_IO.GPIO as GPIO import time import smbus #I2C Address ADC081C027_ADDRESS= (0x51)#is U1 and 0x51 is U9 #Internal Registers ADC081C027_CONVERSION_RESULT = (0x00) ADC081C027_ALERT_STATUS = (0x01) ADC081C027_CONFIG = (0x02) ADC081C027_LOW_LIMIT = (0x03) ADC081C027_HIGH_LIMIT = (0x04) ADC081C027_HYSTERESIS = (0x05) ADC081C027_LOWEST_CONVERSION = (0x06) ADC081C027_HIGHEST_CONVERSION = (0x07) class ADC081C027: def __init__(self, twi=1, addr=ADC081C027_ADDRESS): self._bus = smbus.SMBus(twi) self._addr = addr self._bus.write_byte_data(ADC081C027_ADDRESS,ADC081C027_CONFIG,0x20)#set Converstion Interval to 32, set flags to 0, set polarity to 0 def rawvoltage(self): volt=self._bus.read_i2c_block_data(ADC081C027_ADDRESS,ADC081C027_CONVERSION_RESULT)#Read from conversion result return whole string, only getting 0x00 return volt def typeofTrip(self): flag=self._bus.read_i2c_block_data(ADC081C027_ADDRESS,ADC081C027_ALERT_STATUS)#Return type of trip either 01 or 10 return flag def setLowVolt(self, lim): self._bus.write_byte_data(ADC081C027_ADDRESS,ADC081C027_LOW_LIMIT, lim)#Set low voltage for flag on conversion register def getLowVolt(self): result=self._bus.read_i2c_block_data(ADC081C027_ADDRESS,ADC081C027_LOW_LIMIT)#Get low voltage set before return result def setHighVolt(self, lim): self._bus.write_byte_data(ADC081C027_ADDRESS,ADC081C027_HIGH_LIMIT, lim)#Set High voltage for flag on conversion register def getHighVolt(self): result=self._bus.read_i2c_block_data(ADC081C027_ADDRESS,ADC081C027_HIGH_LIMIT)#get high voltage set before return result def setHysteresis(self,hyst): self._bus.write_byte_data(ADC081C027_ADDRESS,ADC081C027_HYSTERESIS, hyst)#set hyst on conversion register def getHysteresis(self): result=self._bus.read_i2c_block_data(ADC081C027_ADDRESS,ADC081C027_HYSTERESIS)#get hyst set before return result def getLowestConverstion(self): result=self._bus.read_i2c_block_data(ADC081C027_ADDRESS,ADC081C027_LOWEST_CONVERSION)#get lowest conversion return result def getHigestConverstion(self): result=self._bus.read_i2c_block_data(ADC081C027_ADDRESS,ADC081C027_HIGHEST_CONVERSION)#get highest conversion return result
and the code to run it:
import voltcheck import relay import time zonelist=[1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]#change any of 16 values to turn on or off zone tca9535 = relay.TCA9535() tca9535.byzone(zonelist) #This is to enable a relay and create an closed circuit to get the voltage from upperLim=0x05 lowerLim=0x01 hysteresis=0x00 adc081C027 = voltcheck.ADC081C027() print "test for voltage on relays, load limits and wait for it to be met" adc081C027.setLowVolt(lowerLim) print "lower set to " + str(lowerLim) time.sleep(.1) adc081C027.setHighVolt(upperLim) print "upper set to " + str(upperLim) time.sleep(.1) adc081C027.setHysteresis(hysteresis) print "hysteresis set to " + str(hysteresis) time.sleep(.1) print "raw volatage" + str(adc081C027.rawvoltage()) print "low range was " + str(adc081C027.getLowVolt()) print "high range was " + str(adc081C027.getHighVolt()) print "hysteresis was " + str(adc081C027.getHysteresis()) print "lowest conversion on record is " + str(adc081C027.getLowestConverstion()) print "highest conversion on record is " + str(adc081C027.getHigestConverstion())
Thanks for any help,
Vijit Singh