Simple test¶
Ensure your device works with this simple test.
1# SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries
2# SPDX-License-Identifier: MIT
3
4import busio
5import digitalio
6import board
7import adafruit_mcp3xxx.mcp3008 as MCP
8from adafruit_mcp3xxx.analog_in import AnalogIn
9
10# create the spi bus
11spi = busio.SPI(clock=board.SCK, MISO=board.MISO, MOSI=board.MOSI)
12
13# create the cs (chip select)
14cs = digitalio.DigitalInOut(board.D5)
15
16# create the mcp object
17mcp = MCP.MCP3008(spi, cs)
18
19# create an analog input channel on pin 0
20chan = AnalogIn(mcp, MCP.P0)
21
22print("Raw ADC Value: ", chan.value)
23print("ADC Voltage: " + str(chan.voltage) + "V")
1# SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries
2# SPDX-License-Identifier: MIT
3
4import busio
5import digitalio
6import board
7import adafruit_mcp3xxx.mcp3004 as MCP
8from adafruit_mcp3xxx.analog_in import AnalogIn
9
10# create the spi bus
11spi = busio.SPI(clock=board.SCK, MISO=board.MISO, MOSI=board.MOSI)
12
13# create the cs (chip select)
14cs = digitalio.DigitalInOut(board.D5)
15
16# create the mcp object
17mcp = MCP.MCP3004(spi, cs)
18
19# create an analog input channel on pin 0
20chan = AnalogIn(mcp, MCP.P0)
21
22print("Raw ADC Value: ", chan.value)
23print("ADC Voltage: " + str(chan.voltage) + "V")
1# SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries
2# SPDX-License-Identifier: MIT
3
4import busio
5import digitalio
6import board
7import adafruit_mcp3xxx.mcp3002 as MCP
8from adafruit_mcp3xxx.analog_in import AnalogIn
9
10# create the spi bus
11spi = busio.SPI(clock=board.SCK, MISO=board.MISO, MOSI=board.MOSI)
12
13# create the cs (chip select)
14cs = digitalio.DigitalInOut(board.D5)
15
16# create the mcp object
17mcp = MCP.MCP3002(spi, cs)
18
19# create an analog input channel on pin 0
20chan = AnalogIn(mcp, MCP.P0)
21
22print("Raw ADC Value: ", chan.value)
23print("ADC Voltage: " + str(chan.voltage) + "V")
1# SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries
2# SPDX-License-Identifier: MIT
3
4import busio
5import digitalio
6import board
7import adafruit_mcp3xxx.mcp3008 as MCP
8from adafruit_mcp3xxx.analog_in import AnalogIn
9
10# create the spi bus
11spi = busio.SPI(clock=board.SCK, MISO=board.MISO, MOSI=board.MOSI)
12
13# create the cs (chip select)
14cs = digitalio.DigitalInOut(board.D5)
15
16# create the mcp object
17mcp = MCP.MCP3008(spi, cs)
18
19# create a differential ADC channel between Pin 0 and Pin 1
20chan = AnalogIn(mcp, MCP.P0, MCP.P1)
21
22print("Differential ADC Value: ", chan.value)
23print("Differential ADC Voltage: " + str(chan.voltage) + "V")
1# SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries
2# SPDX-License-Identifier: MIT
3
4import busio
5import digitalio
6import board
7import adafruit_mcp3xxx.mcp3004 as MCP
8from adafruit_mcp3xxx.analog_in import AnalogIn
9
10# create the spi bus
11spi = busio.SPI(clock=board.SCK, MISO=board.MISO, MOSI=board.MOSI)
12
13# create the cs (chip select)
14cs = digitalio.DigitalInOut(board.D5)
15
16# create the mcp object
17mcp = MCP.MCP3004(spi, cs)
18
19# create a differential ADC channel between Pin 0 and Pin 1
20chan = AnalogIn(mcp, MCP.P0, MCP.P1)
21
22print("Differential ADC Value: ", chan.value)
23print("Differential ADC Voltage: " + str(chan.voltage) + "V")
1# SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries
2# SPDX-License-Identifier: MIT
3
4import busio
5import digitalio
6import board
7import adafruit_mcp3xxx.mcp3002 as MCP
8from adafruit_mcp3xxx.analog_in import AnalogIn
9
10# create the spi bus
11spi = busio.SPI(clock=board.SCK, MISO=board.MISO, MOSI=board.MOSI)
12
13# create the cs (chip select)
14cs = digitalio.DigitalInOut(board.D5)
15
16# create the mcp object
17mcp = MCP.MCP3002(spi, cs)
18
19# create a differential ADC channel between Pin 0 and Pin 1
20chan = AnalogIn(mcp, MCP.P0, MCP.P1)
21
22print("Differential ADC Value: ", chan.value)
23print("Differential ADC Voltage: " + str(chan.voltage) + "V")