Cov txheej txheem:

Kev Ntsuas Kev Siv H3LIS331DL thiab Raspberry Pi: 4 Kauj Ruam
Kev Ntsuas Kev Siv H3LIS331DL thiab Raspberry Pi: 4 Kauj Ruam

Video: Kev Ntsuas Kev Siv H3LIS331DL thiab Raspberry Pi: 4 Kauj Ruam

Video: Kev Ntsuas Kev Siv H3LIS331DL thiab Raspberry Pi: 4 Kauj Ruam
Video: Saib Mis paub Poj niam (hluas nkauj) tus yam ntxwv lub siab 2024, Hlis ntuj nqeg
Anonim
Image
Image

H3LIS331DL, yog lub zog qis ua tau zoo 3-axis linear accelerometer koom nrog "nano" tsev neeg, nrog digital I²C cov lej sib txuas. H3LIS331DL muaj cov neeg siv xaiv tau cov nplai ntawm g 100g/± 200g/± 400g thiab nws muaj peev xwm ntsuas qhov nrawm nrog cov ntaub ntawv tso tawm tus nqi los ntawm 0.5 Hz txog 1 kHz. H3LIS331DL tau lees tias ua haujlwm dhau qhov ntsuas kub ntev los ntawm -40 ° C txog +85 ° C.

Hauv qhov kev qhia no peb yuav los qhia txog kev cuam tshuam ntawm H3LIS331DL nrog Raspberry Pi, siv nab hab sej ua cov lus programming.

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. H3LIS331DL

2. Raspberry Pi

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:

H3LIS331DL 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: Python Code rau Kev Ntsuas Kev Ntsuas:

Python Code rau Kev Ntsuas Kev Ntsuas
Python Code rau Kev Ntsuas Kev Ntsuas

nws qhov txiaj ntsig ntawm kev siv raspberry pi yog, uas yog muab rau koj qhov kev hloov pauv ntawm cov lus programming uas koj xav kom ua haujlwm rau lub rooj tsav xwm 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 H3LIS331DL tuaj yeem rub tawm los ntawm peb lub zej zog github uas yog DCUBE Store.

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)

# H3LIS331DL chaw nyob, 0x18 (24)

# Xaiv tswj npe 1, 0x20 (32)

# 0x27 (39) Hwj chim ON hom, Cov ntaub ntawv tawm tus nqi = 50 Hz# X, Y, Z-Axis qhib

bus.write_byte_data (0x18, 0x20, 0x27)

# H3LIS331DL chaw nyob, 0x18 (24)# Xaiv tswj npe 4, 0x23 (35)

# 0x00 (00) Hloov kho tas li, Kev ntsuas tag nrho = +/- 100g

bus.write_byte_data (0x18, 0x23, 0x00)

sijhawm.s pw (0.5)

# H3LIS331DL chaw nyob, 0x18 (24)

# Nyeem cov ntaub ntawv rov qab los ntawm 0x28 (40), 2 bytes

# X-Axis LSB, X-Axis MSB

data0 = npav.read_byte_data (0x18, 0x28)

data1 = npav.read_byte_data (0x18, 0x29)

# Hloov cov dataxAccl = data1 * 256 + data0

Yog tias xAccl> 32767:

xAccl -= 65536

# H3LIS331DL chaw nyob, 0x18 (24)

# Nyeem cov ntaub ntawv rov qab los ntawm 0x2A (42), 2 bytes

# Y-Axis LSB, Y-Axis MSB

data0 = npav.read_byte_data (0x18, 0x2A)

data1 = bus.read_byte_data (0x18, 0x2B)

# Hloov cov ntaub ntawv

yAccl = data1 * 256 + data0

Yog tias yAccl> 32767:

yAccl -= 65536

# H3LIS331DL chaw nyob, 0x18 (24)

# Nyeem cov ntaub ntawv rov qab los ntawm 0x2C (44), 2 bytes

# Z-Axis LSB, Z-Axis MSB

data0 = bus.read_byte_data (0x18, 0x2C)

data1 = bus.read_byte_data (0x18, 0x2D)

# Hloov cov ntaub ntawv

zAccl = data1 * 256 + data0

yog zAccl> 32767:

zAccl -= 65536

# Cov ntaub ntawv tso tawm rau lub vijtsam

luam "Kev nrawm hauv X-Axis: %d" %xAccl

luam "Kev nrawm hauv Y-Axis: %d" %yAccl

luam "Kev nrawm hauv Z-Axis: %d" %zAccl

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

$> nab hab sej H3LIS331DL.py gt; nab hab sej H3LIS331DL.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

Accelerometers zoo li H3LIS331DL feem ntau pom nws daim ntawv thov hauv kev ua si thiab tso saib qhov hloov pauv profile. Qhov ntsuas qhov ntsuas no tseem ua haujlwm hauv kev tswj hwm lub zog zoo rau kev siv mobile. H3LIS331DL yog triaxial digital acceleration sensor uas tau suav nrog lub ntse ntawm-nti cov lus tsa suab cuam tshuam kev tswj hwm.

Pom zoo: