Simple MCP4801 test¶
Ensure your MCP4801 works with this simple test.
examples/mcp48x01_simpletest.py¶
1# SPDX-FileCopyrightText: 2017 Scott Shawcroft, written for Adafruit Industries
2# SPDX-FileCopyrightText: Copyright (c) 2024 Steffen Kreutz
3#
4# SPDX-License-Identifier: Unlicense
5
6import board
7import busio
8from digitalio import DigitalInOut
9import mcp48xx
10
11# Initialize SPI bus.
12spi = busio.SPI(board.GP6, board.GP7)
13cs = DigitalInOut(board.GP5)
14
15# Initialize MCP4801.
16dac = mcp48xx.MCP4801(spi, cs)
17
18# There are a three ways to set the DAC output, you can use any of these:
19dac.value = 65535 # Use the value property with a 16-bit number just like
20# the AnalogOut class. Note the MCP4801 is only an 8-bit
21# DAC so quantization errors will occur. The range of
22# values is 0 (minimum/ground) to 65535 (maximum/Vout).
23
24dac.raw_value = 255 # Use the raw_value property to directly read and write
25# the 8-bit DAC value. The range of values is
26# 0 (minimum/ground) to 255 (maximum/Vout).
27
28dac.normalized_value = 1.0 # Use the normalized_value property to set the
29# output with a floating point value in the range
30# 0 to 1.0 where 0 is minimum/ground and 1.0 is
31# maximum/Vout.
32
33# Main loop will go up and down through the range of DAC values forever.
34while True:
35 # Go up the 8-bit raw range.
36 print("Going up 0-2.048V...")
37 for i in range(255):
38 dac.raw_value = i
39 # Go back down the 8-bit raw range.
40 print("Going down 2.048-0V...")
41 for i in range(255, -1, -1):
42 dac.raw_value = i
Simple MCP4812 test¶
Ensure your MCP4812 works with this simple test.
examples/mcp48x01_simpletest.py¶
1# SPDX-FileCopyrightText: 2017 Scott Shawcroft, written for Adafruit Industries
2# SPDX-FileCopyrightText: Copyright (c) 2024 Steffen Kreutz
3#
4# SPDX-License-Identifier: Unlicense
5
6import board
7import busio
8from digitalio import DigitalInOut
9import mcp48xx
10
11# Initialize SPI bus.
12spi = busio.SPI(board.GP6, board.GP7)
13cs = DigitalInOut(board.GP5)
14
15# Initialize MCP4812.
16dac = mcp48xx.MCP4812(spi, cs)
17
18# There are two channels which can be updated independently
19dac.channel_a.value = 65535
20dac.channel_b.value = 65535
21
22# There are a three ways to set the DAC output, you can use any of these:
23dac.channel_a.value = 65535 # Use the value property with a 16-bit number just like
24# the AnalogOut class. Note the MCP4812 is only a 10-bit
25# DAC so quantization errors will occur. The range of
26# values is 0 (minimum/ground) to 65535 (maximum/Vout).
27
28dac.channel_a.raw_value = 1023 # Use the raw_value property to directly read and write
29# the 10-bit DAC value. The range of values is
30# 0 (minimum/ground) to 1023 (maximum/Vout).
31
32dac.channel_a.normalized_value = 1.0 # Use the normalized_value property to set the
33# output with a floating point value in the range
34# 0 to 1.0 where 0 is minimum/ground and 1.0 is
35# maximum/Vout.
36
37# Main loop will go up and down through the range of DAC values forever.
38while True:
39 # Go up the 10-bit raw range.
40 print("Going up 0-2.048V...")
41 for i in range(1023):
42 dac.channel_a.raw_value = i
43 dac.channel_b.raw_value = i
44 # Go back down the 10-bit raw range.
45 print("Going down 2.048-0V...")
46 for i in range(1023, -1, -1):
47 dac.channel_a.raw_value = i
48 dac.channel_b.raw_value = i
Simple MCP4821 test¶
Ensure your MCP4821 works with this simple test.
examples/mcp48x01_simpletest.py¶
1# SPDX-FileCopyrightText: 2017 Scott Shawcroft, written for Adafruit Industries
2# SPDX-FileCopyrightText: Copyright (c) 2024 Steffen Kreutz
3#
4# SPDX-License-Identifier: Unlicense
5
6import board
7import busio
8from digitalio import DigitalInOut
9import mcp48xx
10
11# Initialize SPI bus.
12spi = busio.SPI(board.GP6, board.GP7)
13cs = DigitalInOut(board.GP5)
14
15# Initialize MCP4822.
16dac = mcp48xx.MCP4821(spi, cs)
17
18# There are a three ways to set the DAC output, you can use any of these:
19dac.value = 65535 # Use the value property with a 16-bit number just like
20# the AnalogOut class. Note the MCP4821 is only a 12-bit
21# DAC so quantization errors will occur. The range of
22# values is 0 (minimum/ground) to 65535 (maximum/Vout).
23
24dac.raw_value = 4095 # Use the raw_value property to directly read and write
25# the 12-bit DAC value. The range of values is
26# 0 (minimum/ground) to 4095 (maximum/Vout).
27
28dac.normalized_value = 1.0 # Use the normalized_value property to set the
29# output with a floating point value in the range
30# 0 to 1.0 where 0 is minimum/ground and 1.0 is
31# maximum/Vout.
32
33# Main loop will go up and down through the range of DAC values forever.
34while True:
35 # Go up the 12-bit raw range.
36 print("Going up 0-2.048V...")
37 for i in range(4095):
38 dac.raw_value = i
39 # Go back down the 12-bit raw range.
40 print("Going down 2.048-0V...")
41 for i in range(4095, -1, -1):
42 dac.raw_value = i
Simple MCP4802 test¶
Ensure your MCP4802 works with this simple test.
examples/mcp48x01_simpletest.py¶
1# SPDX-FileCopyrightText: 2017 Scott Shawcroft, written for Adafruit Industries
2# SPDX-FileCopyrightText: Copyright (c) 2024 Steffen Kreutz
3#
4# SPDX-License-Identifier: Unlicense
5
6import board
7import busio
8from digitalio import DigitalInOut
9import mcp48xx
10
11# Initialize SPI bus.
12spi = busio.SPI(board.GP6, board.GP7)
13cs = DigitalInOut(board.GP5)
14
15# Initialize MCP4802.
16dac = mcp48xx.MCP4802(spi, cs)
17
18# There are two channels which can be updated independently
19dac.channel_a.value = 65535
20dac.channel_b.value = 65535
21
22# There are a three ways to set the DAC output, you can use any of these:
23dac.channel_a.value = 65535 # Use the value property with a 16-bit number just like
24# the AnalogOut class. Note the MCP4802 is only an 8-bit
25# DAC so quantization errors will occur. The range of
26# values is 0 (minimum/ground) to 65535 (maximum/Vout).
27
28dac.channel_a.raw_value = 255 # Use the raw_value property to directly read and write
29# the 8-bit DAC value. The range of values is
30# 0 (minimum/ground) to 255 (maximum/Vout).
31
32dac.channel_a.normalized_value = 1.0 # Use the normalized_value property to set the
33# output with a floating point value in the range
34# 0 to 1.0 where 0 is minimum/ground and 1.0 is
35# maximum/Vout.
36
37# Main loop will go up and down through the range of DAC values forever.
38while True:
39 # Go up the 8-bit raw range.
40 print("Going up 0-2.048V...")
41 for i in range(255):
42 dac.channel_a.raw_value = i
43 dac.channel_b.raw_value = i
44 # Go back down the 8-bit raw range.
45 print("Going down 2.048-0V...")
46 for i in range(255, -1, -1):
47 dac.channel_a.raw_value = i
48 dac.channel_b.raw_value = i
Simple MCP4812 test¶
Ensure your MCP4812 works with this simple test.
examples/mcp48x01_simpletest.py¶
1# SPDX-FileCopyrightText: 2017 Scott Shawcroft, written for Adafruit Industries
2# SPDX-FileCopyrightText: Copyright (c) 2024 Steffen Kreutz
3#
4# SPDX-License-Identifier: Unlicense
5
6import board
7import busio
8from digitalio import DigitalInOut
9import mcp48xx
10
11# Initialize SPI bus.
12spi = busio.SPI(board.GP6, board.GP7)
13cs = DigitalInOut(board.GP5)
14
15# Initialize MCP4812.
16dac = mcp48xx.MCP4812(spi, cs)
17
18# There are two channels which can be updated independently
19dac.channel_a.value = 65535
20dac.channel_b.value = 65535
21
22# There are a three ways to set the DAC output, you can use any of these:
23dac.channel_a.value = 65535 # Use the value property with a 16-bit number just like
24# the AnalogOut class. Note the MCP4812 is only a 10-bit
25# DAC so quantization errors will occur. The range of
26# values is 0 (minimum/ground) to 65535 (maximum/Vout).
27
28dac.channel_a.raw_value = 1023 # Use the raw_value property to directly read and write
29# the 10-bit DAC value. The range of values is
30# 0 (minimum/ground) to 1023 (maximum/Vout).
31
32dac.channel_a.normalized_value = 1.0 # Use the normalized_value property to set the
33# output with a floating point value in the range
34# 0 to 1.0 where 0 is minimum/ground and 1.0 is
35# maximum/Vout.
36
37# Main loop will go up and down through the range of DAC values forever.
38while True:
39 # Go up the 10-bit raw range.
40 print("Going up 0-2.048V...")
41 for i in range(1023):
42 dac.channel_a.raw_value = i
43 dac.channel_b.raw_value = i
44 # Go back down the 10-bit raw range.
45 print("Going down 2.048-0V...")
46 for i in range(1023, -1, -1):
47 dac.channel_a.raw_value = i
48 dac.channel_b.raw_value = i
Simple MCP4822 test¶
Ensure your MCP4822 works with this simple test.
examples/mcp48x01_simpletest.py¶
1# SPDX-FileCopyrightText: 2017 Scott Shawcroft, written for Adafruit Industries
2# SPDX-FileCopyrightText: Copyright (c) 2024 Steffen Kreutz
3#
4# SPDX-License-Identifier: Unlicense
5
6import board
7import busio
8from digitalio import DigitalInOut
9import mcp48xx
10
11# Initialize SPI bus.
12spi = busio.SPI(board.GP6, board.GP7)
13cs = DigitalInOut(board.GP5)
14
15# Initialize MCP4822.
16dac = mcp48xx.MCP4822(spi, cs)
17
18# There are two channels which can be updated independently
19dac.channel_a.value = 65535
20dac.channel_b.value = 65535
21
22# There are a three ways to set the DAC output, you can use any of these:
23dac.channel_a.value = 65535 # Use the value property with a 16-bit number just like
24# the AnalogOut class. Note the MCP4822 is only a 12-bit
25# DAC so quantization errors will occur. The range of
26# values is 0 (minimum/ground) to 65535 (maximum/Vout).
27
28dac.channel_a.raw_value = 4095 # Use the raw_value property to directly read and write
29# the 12-bit DAC value. The range of values is
30# 0 (minimum/ground) to 4095 (maximum/Vout).
31
32dac.channel_a.normalized_value = 1.0 # Use the normalized_value property to set the
33# output with a floating point value in the range
34# 0 to 1.0 where 0 is minimum/ground and 1.0 is
35# maximum/Vout.
36
37# Main loop will go up and down through the range of DAC values forever.
38while True:
39 # Go up the 12-bit raw range.
40 print("Going up 0-2.048V...")
41 for i in range(4095):
42 dac.channel_a.raw_value = i
43 dac.channel_b.raw_value = i
44 # Go back down the 12-bit raw range.
45 print("Going down 2.048-0V...")
46 for i in range(4095, -1, -1):
47 dac.channel_a.raw_value = i
48 dac.channel_b.raw_value = i