Tal O
Published © GPL3+

Analog Input on Raspberry Pi with MCP3008

How to get analog input on Raspberry Pi using CircuitPython.

BeginnerFull instructions provided8,910
Analog Input on Raspberry Pi with MCP3008

Things used in this project

Story

Read more

Schematics

wiring

Code

Example

Python
import busio
import digitalio
import board
import adafruit_mcp3xxx.mcp3008 as MCP
from adafruit_mcp3xxx.analog_in import AnalogIn
import time

# 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)
 
# 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(1)

Credits

Tal O

Tal O

20 projects • 55 followers
Maker @ heart

Comments