で、i2cdetect -y 1 とかやると
Error: Could not open file `/dev/i2c-1' or `/dev/i2c/1': No such file or directory
となります。i2cをイネーブルにしなければなりません。
NanoPi設定のために RaspberryPiのraspi-config の代わりに
npi-config
root@NanoPi-NEO:/root/devel# i2cdetect -y 0
0 1 2 3 4 5 6 7 8 9 a b c d e f
00: -- -- -- -- -- -- -- -- -- -- -- -- --
10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
40: 40 -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
50: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
60: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
70: -- -- -- -- -- -- -- --
apt install python-smbus
# HDC1000 read from RaspberryPi
# Distributed with a free-will license.
# Use it any way you want, profit or free, provided it fits in the licenses of its associated works.
# HDC1000
# This code is designed to work with the HDC1000_I2CS I2C Mini Module available from ControlEverything.com.
# https://www.controleverything.com/content/Temperature?sku=HDC1000_I2CS#tabs-0-product_tabset-2
import smbus
import time
import datetime
# Get I2C bus NanoPi NEO = 0
bus = smbus.SMBus(0)
# HDC1000 address, 0x40(64)
# Select configuration register, 0x02(02)
# 0x30(48) Temperature, Humidity enabled, Resolultion = 14-bits, Heater on
bus.write_byte_data(0x40, 0x02, 0x30)
# HDC1000 address, 0x40(64)
# Send temp measurement command, 0x00(00)
bus.write_byte(0x40, 0x00)
time.sleep(0.5)
# HDC1000 address, 0x40(64)
# Read data back, 2 bytes
# temp MSB, temp LSB
data0 = bus.read_byte(0x40)
data1 = bus.read_byte(0x40)
# Convert the data
temp = (data0 * 256) + data1
cTemp = (temp / 65536.0) * 165.0 - 40 -4
fTemp = cTemp * 1.8 + 32
# HDC1000 address, 0x40(64)
# Send humidity measurement command, 0x01(01)
bus.write_byte(0x40, 0x01)
time.sleep(0.5)
# HDC1000 address, 0x40(64)
# Read data back, 2 bytes
# humidity MSB, humidity LSB
data0 = bus.read_byte(0x40)
data1 = bus.read_byte(0x40)
# Convert the data
humidity = (data0 * 256) + data1
humidity = (humidity / 65536.0) * 100.0
today = datetime.datetime.today()
# Output data to screen
print today.strftime("%Y/%m/%d %H:%M:%S")
print "Temperature : %.2f C" %cTemp
print " Humidity : %.2f %%" %humidity
#print "Temperature in Fahrenheit : %.2f F" %fTemp
pythonで実行しますと温湿度が取れます。
root@NanoPi-NEO:/root/devel# python hdc1000.py
2017/10/13 23:50:23
Temperature : 29.12 C
Humidity : 49.02 %