12345678910111213141516171819202122232425 |
- 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 )
|