cy-30在raspberry pi上的调试

使用raspi-config打开i2c接口。
安装i2c工具,
apt-get install i2c-tools

接线如图add管脚悬空。

使用
/dev/i2c-1

执行命令得到cy-30编号为23。
# i2cdetect -y 1
0 1 2 3 4 5 6 7 8 9 a b c d e f
00: — — — — — — — — — — — — —
10: — — — — — — — — — — — — — — — —
20: — — — 23 — — — — — — — — — — — —
30: — — — — — — — — — — — — — — — —
40: — — — — — — — — — — — — — — — —
50: — — — — — — — — — — — — — — — —
60: — — — — — — — — — — — — — — — —
70: — — — — — — — —

#!/bin/env python
# -*- coding:utf-8 -*-
# Revision:
# Author:      simonzhang
# Email:       simon-zzm@163.com
# Web:         www.simonzhang.net
# -------------------------------
# http://atceiling.blogspot.co.uk/2017/03/raspberry-pi-gy30.html
import smbus
import RPi.GPIO as GPIO
import time

bus = smbus.SMBus(1)
ONE_TIME_HIGH_RES_MODE_2 = 0x21

def convertToNumber(data):
    return ((data[1] + (256 * data[0])) / 1.2)

def readLight(addr):
    bus = smbus.SMBus(1)
    data = bus.read_i2c_block_data(addr,ONE_TIME_HIGH_RES_MODE_2)
    return convertToNumber(data)

def CY30Data():
    GPIO.setmode(GPIO.BOARD)
    # 初始化
    DEVICE     = 0x23 # Default device I2C address
    num = round(readLight(DEVICE), 2)
    # 输出
    print "%s lx" % num

def main():
    CY30Data()
 
if __name__ == '__main__':  
    main()

cy-30源码

匿名进行回复 取消回复

电子邮件地址不会被公开。 必填项已用*标注