Cov txheej txheem:

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

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

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

TSL45315 yog lub teeb pom kev zoo ib puag ncig digital. Nws kwv yees tib neeg qhov muag teb raws ntau yam teeb pom kev zoo. Cov cuab yeej muaj peb lub sijhawm xaiv ua ke thiab muab ncaj qha 16-ntsis lux tso tawm ntawm I2C tsheb npav sib cuam tshuam. Cov cuab yeej muaj cov kab ntawv photodiode, kev sib xyaw ua ke sib piv-rau-digital hloov pauv (ADC), teeb liab ua cov kab hluav taws xob, cov lej xav txog qhov xav tau, thiab I2C cov lej sib cuam tshuam ntawm ib qho CMOS kev sib txuas ua ke los muab cov ntaub ntawv 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. TSL45315

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 kawg ntawm I2C cable rau TSL45315 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 TSL45315 tuaj yeem rub tawm los ntawm peb GitHub chaw cia khoom-Dcube khw.

Nov yog qhov txuas rau tib yam:

github.com/DcubeTechVentures/TSL45315…

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.

# TSL45315

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

ntshuam smbus

lub sij hawm ntshuam

# Tau I2C npav

npav = smbus. SMBus (1)

# TSL45315 chaw nyob, 0x29 (41)

# Xaiv Tswj kev tso npe, 0x00 (0), nrog rau npe sau npe, 0x80 (128)

# 0x03 (03) Kev ua haujlwm ib txwm muaj

bus.write_byte_data (0x29, 0x00 | 0x80, 0x03)

# TSL45315 chaw nyob, 0x29 (41)

# Xaiv Configuration register, 0x01 (1), nrog Command register, 0x80 (128)

# 0x00 (00) Multiplier 1x, Tint: 400ms

bus.write_byte_data (0x29, 0x01 | 0x80, 0x00)

sijhawm.s pw (0.5)

# TSL45315 chaw nyob, 0x29 (41)

# Nyeem cov ntaub ntawv rov qab los ntawm 0x04 (4), nrog rau npe sau npe, 0x80 (128)

# 2 bytes, LSB ua ntej

cov ntaub ntawv = bus.read_i2c_block_data (0x29, 0x04 | 0x80, 2)

# Hloov cov ntaub ntawv mus rau lux

luminance = cov ntaub ntawv [1] * 256 + cov ntaub ntawv [0]

# Cov ntaub ntawv tso tawm rau lub vijtsam

luam "Ambient Light Luminance: %d lux" %luminance

Kauj Ruam 4: Cov ntawv thov:

Qhov dav dav dav ntawm lub teeb pom kev ib puag ncig ua rau nws muaj txiaj ntsig tshwj xeeb hauv kev siv sab nraum zoov uas nws raug rau tshav ntuj ncaj qha. Cov cuab yeej siv tau zoo tshaj plaws rau kev siv tsis siv neeg kev teeb ntawm txoj kev thiab kev nyab xeeb, daim ntawv tshaj tawm, thiab teeb pom kev zoo hauv tsheb. TSL45315 cov cuab yeej kuj tseem tuaj yeem siv hauv lub xeev ruaj khov thiab teeb pom kev zoo rau kev tswj tsis siv neeg thiab kev sau hnub nruab hnub kom ua kom muaj kev txuag hluav taws xob ntau. Lwm daim ntawv thov suav nrog tso saib lub teeb pom kev zoo txhawm rau txuas lub roj teeb lub neej thiab ua kom pom kev zoo hauv xov tooj ntawm tes, ntsiav tshuaj, thiab phau ntawv sau.

Pom zoo: