Cov txheej txheem:

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

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

Video: Kev Ntsuas Kev Ntsuas Siv BMA250 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

BMA250 yog qhov me me, nyias, lub zog loj, 3-axis accelerometer nrog kev ntsuas siab (13-ntsis) ntsuas txog li g 16 g. Cov ntaub ntawv tso tawm digital yog ua raws li 16-ntsis twos ua tiav thiab siv tau los ntawm I2C digital interface. Nws ntsuas qhov kev nrawm nrawm ntawm lub ntiajteb txawj nqus hauv kev thov qaij-nkag siab, nrog rau kev nrawm nrawm los ntawm kev txav lossis poob siab. Nws qhov kev daws teeb meem siab (3.9 mg/LSB) ua rau ntsuas ntsuas qhov xav tau hloov qis dua 1.0 °.

Hauv qhov kev qhia no peb yuav ntsuas qhov nrawm hauv txhua peb peb txoj kab uas hla uas siv BMA250 thiab Raspberry Pi. Lub sensor tau teeb tsa ua lus nab.

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

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:

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

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 BMA250 tuaj yeem rub tawm los ntawm peb cov 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 npe, koj yuav tsum rub tawm SMBus lub tsev qiv ntawv thaum muaj nab nab vim tias lub tsev qiv ntawv no txhawb nqa cov haujlwm 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)

# BMA250 qhov chaw nyob, 0x18 (24)

# Xaiv cov npe xaiv xaiv, 0x0F (15)

# 0x03 (03) Teeb tsa = +/- 2gbus.write_byte_data (0x18, 0x0F, 0x03)

# BMA250 chaw nyob, 0x18 (24)# Xaiv bandwidth rau npe, 0x10 (16)

# 0x08 (08) Bandwidth = 7.81 Hzbus.write_byte_data (0x18, 0x10, 0x08)

sijhawm.s pw (0.5)

# BMA250 qhov chaw nyob, 0x18 (24)

# Nyeem cov ntaub ntawv rov qab los ntawm 0x02 (02), 6 bytes

# X-Axis LSB, X-Axis MSB, Y-Axis LSB, Y-Axis MSB, Z-Axis LSB, Z-Axis MSB

cov ntaub ntawv = bus.read_i2c_block_data (0x18, 0x02, 6)

# Hloov cov ntaub ntawv mus rau 10 khoom

xAccl = (data [1] * 256 + (data [0] & 0xC0)) / 64

Yog tias xAccl> 511:

xAccl -= 1024

yAccl = (data [3] * 256 + (data [2] & 0xC0)) / 64

Yog tias yAccl> 511:

yAccl -= 1024

zAccl = (data [5] * 256 + (data [4] & 0xC0)) / 64

yog zAccl> 511:

zAccl -= 1024

# 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 se BMA250.py gt; nab hab sej BMA250.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 BMA250 feem ntau pom nws daim ntawv thov hauv kev ua si thiab tso saib cov ntaub ntawv hloov pauv. Qhov ntsuas qhov ntsuas no tseem ua haujlwm hauv kev tswj hwm lub zog zoo rau kev siv mobile. BMA250 yog lub triaxial digital acceleration sensor uas tau koom nrog nrog kev txawj ntse ntawm-nti cov lus tsa suab cuam tshuam kev tswj hwm.

Pom zoo: