Skip to content

Commit 1ec6c11

Browse files
authored
Create 2.1.1_DAC_mcp4922.py
1 parent 1843b47 commit 1ec6c11

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed
+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import spidev
2+
print (1)
3+
spi = spidev.SpiDev()
4+
spi.open(0,0)
5+
spi.max_speed_hz=1000000
6+
first = '0011'
7+
second = '1011'
8+
9+
Voltage_A=4.5
10+
Voltage_B=3
11+
12+
def dac (channel, voltage):
13+
#voltage = 900 #
14+
voltage1=bin((voltage))
15+
voltage2=voltage1[2:]
16+
17+
s = channel + (voltage2).zfill(12)
18+
part_1, part_2=s[:8],s[8:]
19+
byte1=int (part_1,2)
20+
byte2=int (part_2,2)
21+
to_send = [byte1, byte2]
22+
spi.xfer2(to_send)
23+
24+
25+
while 1:
26+
dac (first, int (Voltage_A*819))
27+
dac (second, int (Voltage_B*819))

0 commit comments

Comments
 (0)