Building a device to read Analog to Digital Voltages using PCF8591 Analog to Digital Converter (ADC).
The ADC connects via i2c and successfully provides HEX values that correspond to values between 0 and 255 for various input voltages when connected via terminal:
pi@raspberrypi:~ $ sudo i2cget -y 0 0x48
0x38
pi@raspberrypi:~ $ sudo i2cget -y 0 0x48
0x3a
pi@raspberrypi:~ $ sudo i2cget -y 0 0x48
0x44
pi@raspberrypi:~ $ sudo i2cget -y 0 0x48
0x3d
0x38 = 56 ; 0x3a = 58 .. etc.
When running the same application through Python, I obtain an error.
Below is my source Code:
import time
import smbus
i2c_ch = 0 #channel we're running on with i2c
#address on the I2C bus of the ADC
i2c_address = 0x48
bus = smbus.SMBus(i2c_ch)
# Print out temperature every second
while True:
temperature = bus.read_i2c_block_data(i2c_address, 0)
print(temperature)
time.sleep(1)
This is the Ouput:
[0, 0, 16, 12, 9, 7, 4, 3, 2, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
[0, 0, 5, 3, 3, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
[0, 0, 5, 3, 3, 2, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
[0, 0, 12, 8, 6, 5, 3, 3, 2, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
[0, 0, 12, 9, 7, 5, 3, 3, 2, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
[0, 0, 6, 4, 3, 2, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
[0, 0, 5, 3, 3, 2, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
[0, 0, 9, 7, 6, 4, 3, 3, 2, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
What are these errors, what do they mean and how can I update my Python script to correctly read the Analog to Digital Converter over I2C?