Raspberry Pi, Python & i2c Analogue to Digital Converter (ADC)

A quick little post for my future reference really.  Wanted to get an i2C Analogue to Digital Converter (ADC) working on a Raspberry Pi.  No real application as yet, but sure to be one in the future.

Raspberry Pi, Python & i2c Analogue to Digital Converter (ADC)

Most of the information to make this work was taken from posts by Grumpy Mike on the Raspberry Pi forums.  Got a couple of PCF8591s nice & cheep from

Below is the very basic and non-defensive Python code to simply read the voltage provided by the pot to ADC channel 0 and print a proportional value between 0 & 255:

Raspberry Pi, Python & i2c Analogue to Digital Converter (ADC) schematic#Read a value from analogue input 0

#in A/D in the PCF8591P @ address 0x48
fromsmbus importSMBus
bus =SMBus(0)
print("Read the A/D")
print("Ctrl C to stop")
bus.write_byte(0x48, 0) # set control register to read channel 0
last_reading =-1
while(0==0): # do forever
    reading =bus.read_byte(0x48) # read A/D
    if(abs(last_reading -reading) > 2):
        print(reading)
        last_reading =reading

About The Author

Ibrar Ayyub

I am an experienced technical writer holding a Master's degree in computer science from BZU Multan, Pakistan University. With a background spanning various industries, particularly in home automation and engineering, I have honed my skills in crafting clear and concise content. Proficient in leveraging infographics and diagrams, I strive to simplify complex concepts for readers. My strength lies in thorough research and presenting information in a structured and logical format.

Follow Us:
LinkedinTwitter

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top