Cov txheej txheem:

Kev Ntsuas Kub Siv STS21 thiab Raspberry Pi: 4 Kauj Ruam
Kev Ntsuas Kub Siv STS21 thiab Raspberry Pi: 4 Kauj Ruam

Video: Kev Ntsuas Kub Siv STS21 thiab Raspberry Pi: 4 Kauj Ruam

Video: Kev Ntsuas Kub Siv STS21 thiab Raspberry Pi: 4 Kauj Ruam
Video: Saib Mis paub Poj niam (hluas nkauj) tus yam ntxwv lub siab 2024, Kaum ib hlis
Anonim
Image
Image

STS21 Digital Kub Sensor muab qhov ua tau zoo tshaj plaws thiab txuag chaw hneev taw. Nws muab kev ntsuas ntsuas, kab cim qhia tawm hauv digital, hom I2C. Kev tsim cov ntsuas no yog ua raws CMOSens thev naus laus zis, uas yog tus yam ntxwv zoo rau kev ua tau zoo thiab ntseeg tau ntawm STS21. Kev daws teeb meem ntawm STS21 tuaj yeem hloov pauv los ntawm kev hais kom ua, roj teeb qis tuaj yeem kuaj pom thiab daim tshev nyiaj pab txhim kho kev sib txuas lus ntseeg tau.

Hauv qhov kev qhia no kev cuam tshuam ntawm STS21 sensor module nrog raspberry pi tau pom thiab nws txoj haujlwm siv cov lus nab nab kuj tau piav qhia. Txhawm rau nyeem qhov ntsuas kub, peb tau siv raspberry pi nrog I2c adapter Qhov no I2C adapter ua rau kev txuas mus rau lub ntsuas qhov ntsuas tau yooj yim thiab ntseeg tau ntau dua.

Kauj Ruam 1: Yuav Tsum Kho Vajtse:

Yuav tsum tau kho vajtse
Yuav tsum tau kho vajtse
Yuav tsum tau kho vajtse
Yuav tsum tau kho vajtse
Yuav tsum tau kho vajtse
Yuav tsum tau kho vajtse

Cov ntaub ntawv uas peb xav tau kom ua tiav peb lub hom phiaj suav nrog cov khoom siv hauv qab no:

1. STS21

2. Raspberry pib

3. I2C Cable

4. I2C Shield rau raspberry pi

5. Ethernet Cable

Kauj ruam 2: Khoos phis tawj sib txuas:

Kho vajtse Hookup
Kho vajtse Hookup
Kho vajtse Hookup
Kho vajtse Hookup

Tshooj khoos phis tawj sib txuas ntu piav qhia qhov txuas txuas uas xav tau ntawm lub ntsuas cua thiab raspberry pi. Ua kom muaj kev sib txuas raug yog qhov tseem ceeb xav tau thaum ua haujlwm ntawm ib qho system rau qhov xav tau cov zis. Yog li, qhov xav tau kev sib txuas yog raws li hauv qab no:

STS21 yuav ua haujlwm dhau I2C. Nov yog qhov piv txwv kab hluav taws xob daim duab, qhia txog yuav ua li cas xaim txhua lub interface ntawm lub sensor.

Tawm-ntawm-lub thawv, lub rooj tsavxwm tau teeb tsa rau I2C interface, zoo li peb pom zoo siv qhov kev sib txuas no yog tias koj tsis ntseeg lwm yam. Txhua yam koj xav tau yog plaub lub xov hlau!

Tsuas yog plaub qhov kev sib txuas xav tau Vcc, Gnd, SCL thiab SDA tus pin thiab cov no txuas nrog kev pab ntawm I2C cable.

Cov kev sib txuas no tau qhia hauv cov duab saum toj no.

Kauj Ruam 3: Txoj Cai Rau Kev Ntsuas Kub:

Code rau Kev Ntsuas Kub
Code rau Kev Ntsuas Kub

Qhov zoo ntawm kev siv raspberry pi yog, uas yog muab rau koj qhov kev hloov pauv ntawm cov lus programming uas koj xav tau los teeb tsa lub rooj tsav xwm txhawm rau txhawm rau cuam tshuam lub sensor nrog nws. Kev siv cov txiaj ntsig zoo ntawm pawg thawj coj no, peb tab tom qhia ntawm no nws cov phiaj xwm hauv nab hab sej. Nab hab sej yog ib qho ntawm cov lus yooj yim programming nrog cov lus yooj yim tshaj plaws. Tus nab npawb nab npawb rau STS21 tuaj yeem rub tawm los ntawm peb cov zej zog github uas yog DCUBE Store Community.

Ntxiv rau qhov yooj yim ntawm cov neeg siv, peb tab tom piav qhia cov cai ntawm no thiab:

Raws li thawj kauj ruam ntawm kev sau koj yuav tsum rub lub SMBus lub tsev qiv ntawv thaum muaj nab nab, vim tias lub tsev qiv ntawv no txhawb nqa cov haujlwm uas siv hauv txoj cai. Yog li, txhawm rau rub lub tsev qiv ntawv koj tuaj yeem mus ntsib qhov txuas hauv qab no:

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

Koj tuaj yeem luam cov cai ua haujlwm los ntawm no kuj:

ntshuam smbus

lub sij hawm ntshuam

# Tau I2C busbus = smbus. SMBus (1)

# STS21 chaw nyob, 0x4A (74)

# Xaiv Command

# 0xF3 (243) Kev ntsuas kub hauv tsis muaj hom

bus.write_byte (0x4A, 0xF3)

sijhawm.s pw (0.5)

# STS21 chaw nyob, 0x4A (74)

# Nyeem cov ntaub ntawv rov qab, 2 bytes, MSB ua ntej

data0 = bus.read_byte (0x4A)

data1 = bus.read_byte (0x4A)

# Hloov cov ntaub ntawv

temp = (data0 * 256 + data1) & 0xFFFC

cTemp = -46.85 + (175.72 * temp / 65536.0)

fTemp = cTemp * 1.8 + 32

# Cov ntaub ntawv tso tawm rau lub vijtsam

luam tawm "Kub hauv Celsius yog: %.2f C" %cTemp

luam tawm "Kub hauv Fahrenheit yog: %.2f F" %fTemp

Txoj cai tau ua tiav siv cov lus txib hauv qab no:

$> nab nab STS21.py gt; nab hab sej STS21.py

Cov zis ntawm lub ntsuas tau pom hauv daim duab saum toj no rau kev siv ntawm tus neeg siv.

Kauj Ruam 4: Cov ntawv thov:

Cov ntawv thov
Cov ntawv thov

STS21 Digital Kub Sensor tuaj yeem ua haujlwm hauv cov kab ke uas xav tau qhov ntsuas kub kom raug. Nws tuaj yeem suav nrog hauv ntau lub tshuab computer, cov cuab yeej siv kho mob thiab kev tswj hwm kev lag luam nrog qhov xav tau ntawm kev ntsuas kub nrog qhov ua tau zoo.

Pom zoo: