Ver código fonte

new file: adctest.py

yoneda 1 ano atrás
pai
commit
d08250c5b8
1 arquivos alterados com 25 adições e 0 exclusões
  1. 25 0
      adctest.py

+ 25 - 0
adctest.py

@@ -0,0 +1,25 @@
+from smbus2 import SMBus
+import time
+
+# 定数
+ADRS2040_ADDR=0x41
+ADRS2040_CMD_INVALID      = 0
+ADRS2040_CMD_ADC_START    = 1
+ADRS2040_CMD_ADC_STOP     = 2
+ADRS2040_CMD_SET_RATE     = 3
+ADRS2040_CMD_GET_COUNT    = 4
+ADRS2040_CMD_GET_VALUE    = 5
+
+with SMBus(1) as i2c:
+    # 1000Hzにセット
+    i2c.write_word_data(ADRS2040_ADDR, ADRS2040_CMD_SET_RATE, 100)
+    i2c.write_byte(ADRS2040_ADDR, ADRS2040_CMD_ADC_START)
+    while True:
+        counter = 0
+        counter = i2c.read_word_data(ADRS2040_ADDR,ADRS2040_CMD_GET_COUNT )
+        print(counter)
+        for i in range(counter):
+            value = i2c.read_word_data(ADRS2040_ADDR,ADRS2040_CMD_GET_VALUE)
+            print( value )
+
+