Skip to content

Instantly share code, notes, and snippets.

@rajasiman
Created January 30, 2020 15:42
Show Gist options
  • Select an option

  • Save rajasiman/8e9dee796b8e3f47f1efecdcfa01b4d2 to your computer and use it in GitHub Desktop.

Select an option

Save rajasiman/8e9dee796b8e3f47f1efecdcfa01b4d2 to your computer and use it in GitHub Desktop.
import busio
import digitalio
import board
import time
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.CE0)
# create the mcp object
mcp = MCP.MCP3008(spi, cs)
# create an analog input channel on pin 0
chan = AnalogIn(mcp, MCP.P0)
while True:
print('Raw ADC Value: ', chan.value)
print('ADC Voltage: ' + str(chan.voltage) + 'V')
time.sleep(2)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment