Created
January 30, 2020 15:42
-
-
Save rajasiman/8e9dee796b8e3f47f1efecdcfa01b4d2 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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