Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import iio
- iio_context = iio.Context()
- class Am335xAdc:
- def __init__( self, vrefp=1.8, vrefm=0.0 ):
- self.vrefp = vrefp
- self.vrefm = vrefm
- self._device = iio_context.find_device('TI-am335x-adc.0.auto')
- self._channels = []
- self._raw = []
- for i in range(8):
- ch = self._device.find_channel( f'voltage{i}' )
- self._channels.append( ch )
- if ch is not None:
- ch = ch.attrs['raw']
- self._raw.append( ch )
- # output range 0 .. 4095
- def raw( self, ch ):
- return int( self._raw[ ch ].value )
- # output range 0.0 .. 1.0
- def value( self, ch ):
- return self.raw( ch ) / 4095
- # output range vrefm .. vrefp
- def voltage( self, ch ):
- return self.value( ch ) * ( self.vrefp - self.vrefm ) + self.vrefm
- adc = Am335xAdc()
- def vdd_3v3():
- return adc.voltage(7) * 2
- for i in range(3):
- print( f'{vdd_3v3():.3f}V' )
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement