Cov txheej txheem:

Raspberry Pi - BH1715 Digital Ambient Light Sensor Python Qhia: 4 Kauj Ruam
Raspberry Pi - BH1715 Digital Ambient Light Sensor Python Qhia: 4 Kauj Ruam

Video: Raspberry Pi - BH1715 Digital Ambient Light Sensor Python Qhia: 4 Kauj Ruam

Video: Raspberry Pi - BH1715 Digital Ambient Light Sensor Python Qhia: 4 Kauj Ruam
Video: Raspberry Pi BH1715 Digital Ambient Light Sensor Python Tutorial 2024, Kaum ib hlis
Anonim
Image
Image

BH1715 yog digital Ambient Light Sensor nrog I²C tsheb npav sib cuam tshuam. BH1715 feem ntau yog siv kom tau txais cov ntaub ntawv teeb pom kev zoo los kho LCD thiab Keypad lub teeb pom kev zoo rau lub xov tooj ntawm tes. Cov cuab yeej no muaj 16-ntsis kev daws teeb meem thiab ntsuas ntsuas tau ntau, tso cai kuaj pom los ntawm.23 txog 100, 000 lux. Nov yog nws qhov ua piv txwv nrog raspberry pi siv tus lej nab npawb.

Kauj Ruam 1: Yam Koj Xav Tau..

Yam Koj Xav Tau.. !!
Yam Koj Xav Tau.. !!

1. Raspberry Pi

2. HLB 1715

3. I²C Cable

4. I²C Shield rau Raspberry Pi

5. Ethernet Cable

Kauj Ruam 2: Kev Sib Txuas:

Kev Sib Txuas
Kev Sib Txuas
Kev Sib Txuas
Kev Sib Txuas
Kev Sib Txuas
Kev Sib Txuas
Kev Sib Txuas
Kev Sib Txuas

Siv daim I2C daim thaiv rau raspberry pi thiab maj mam thawb nws hla gpio pins ntawm raspberry pi.

Tom qab ntawd txuas ib qho kawg ntawm I2C cable rau BH1715 sensor thiab lwm qhov kawg rau I2C daim ntaub thaiv.

Kuj txuas Ethernet cable rau pi lossis koj tuaj yeem siv WiFi module.

Kev sib txuas tau qhia hauv daim duab saum toj no.

Kauj ruam 3: Code:

Txoj Cai
Txoj Cai

Tus nab npawb nab npawb rau BH1715 tuaj yeem rub tawm los ntawm peb GitHub chaw cia khoom- Dcube Store.

Nov yog qhov txuas rau tib yam:

github.com/DcubeTechVentures/BH1715…

Peb tau siv SMBus lub tsev qiv ntawv rau sej code, cov kauj ruam rau nruab SMBus ntawm raspberry pi tau piav qhia ntawm no:

pypi.python.org/pypi/smbus-cffi/0.5.1

Koj tseem tuaj yeem luam cov cai los ntawm no, nws tau muab raws li hauv qab no:

# Faib nrog daim ntawv tso cai yuav dawb.

# Siv nws txhua txoj hauv kev uas koj xav tau, muaj txiaj ntsig lossis pub dawb, muab nws haum rau hauv daim ntawv tso cai ntawm nws cov haujlwm sib txuam.

# HLB 1715

# Txoj cai no yog tsim los ua haujlwm nrog BH1715_I2CS I2C Mini Module muaj nyob hauv Dcube Store.

ntshuam smbus

lub sij hawm ntshuam

# Tau I2C npav

npav = smbus. SMBus (1)

# BH1715 chaw nyob, 0x23 (35)

# Xa lub zog ntawm kev hais kom ua

# 0x01 (01) Hwj chim On

npav.write_byte (0x23, 0x01)

# BH1715 chaw nyob, 0x23 (35)

# Xa cov lus ntsuas ntsuas mus tas li

# 0x10 (16) Teeb hom kev daws teeb meem tsis tu ncua, 1 lux daws teeb meem, Sijhawm = 120ms

npav.write_byte (0x23, 0x10)

sijhawm.s pw (0.5)

# BH1715 chaw nyob, 0x23 (35)

# Nyeem cov ntaub ntawv rov qab, 2 bytes siv Kev Hu Xov Tooj

# luminance MSB, luminance LSB

cov ntaub ntawv = bus.read_i2c_block_data (0x23, 2)

# Hloov cov ntaub ntawv

luminance = (cov ntaub ntawv [0] * 256 + cov ntaub ntawv [1]) / 1.2

# Cov ntaub ntawv tso tawm rau lub vijtsam

luam "Ambient Light luminance: %.2f lux" %luminance

Kauj Ruam 4: Cov ntawv thov:

BH1715 yog lub teeb pom kev ib puag ncig lub teeb pom kev zoo uas tuaj yeem suav nrog hauv xov tooj ntawm tes, LCD TV, NCEJ PC thiab lwm yam. siv lub teeb pom kev zoo.

Pom zoo: