#!/usr/bin/python3 import time import busio import digitalio import board import adafruit_mcp3xxx.mcp3008 as MCP from adafruit_mcp3xxx.analog_in import AnalogIn # create the spi bus spi = busio.SPI(clock=board.SCK, MISO=board.MISO, MOSI=board.MOSI) # create the cs (chip select) cs = digitalio.DigitalInOut(board.D5) # create the mcp object mcp = MCP.MCP3008(spi, cs) print('Reading MCP3008 values, press Ctrl-C to quit...') # Print nice channel column headers. print('| {0:>4} | {1:>4} | {2:>4} | {3:>4} | {4:>4} | {5:>4} | {6:>4} | {7:>4} |'.format(*range(8))) print('-' * 57) # Main program loop. while True: # Read all the ADC channel values in a list. values = [0]*8 #for i in range(8): # The read_adc function will get the value of the specified channel (0-7). channel = AnalogIn(mcp, MCP.P0) values[0] = channel.value #print (values[0]) channel =AnalogIn(mcp, MCP.P1) values[1] = channel.value channel = AnalogIn(mcp, MCP.P2) values[2] = channel.value channel = AnalogIn(mcp, MCP.P3) values[3] = channel.value channel = AnalogIn(mcp, MCP.P4) values[4] = channel.value channel = AnalogIn(mcp, MCP.P5) values[5] = channel.value channel = AnalogIn(mcp, MCP.P6) values[6] = channel.value channel = AnalogIn(mcp, MCP.P7) values[7] = channel.value # Print the ADC values. print('| {0:>4} | {1:>4} | {2:>4} | {3:>4} | {4:>4} | {5:>4} | {6:>4} | {7:>4} |'.format(*values)) # Pause for half a second. time.sleep(0.5)