Cov txheej txheem:

Kev Ntsuas Kev Siv Sijhawm Siv ADXL345 thiab Raspberry Pi: 4 Cov Kauj Ruam
Kev Ntsuas Kev Siv Sijhawm Siv ADXL345 thiab Raspberry Pi: 4 Cov Kauj Ruam

Video: Kev Ntsuas Kev Siv Sijhawm Siv ADXL345 thiab Raspberry Pi: 4 Cov Kauj Ruam

Video: Kev Ntsuas Kev Siv Sijhawm Siv ADXL345 thiab Raspberry Pi: 4 Cov Kauj Ruam
Video: Siv ntsev ntsuas paub tias muaj me nyuam 2024, Kaum ib hlis
Anonim
Image
Image

ADXL345 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 I2 C 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 kev cuam tshuam ntawm ADXL345 sensor module nrog raspberry pi tau pom thiab nws cov phiaj xwm siv cov lus nab nab kuj tau piav qhia. Txhawm rau nyeem qhov tseem ceeb ntawm kev nrawm ntawm txhua 3-axis, peb tau siv raspberry pi nrog I2C adapter. Qhov I2C adapter ua rau kev txuas mus rau lub sensor module yooj yim dua thiab ntseeg tau 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. ADXL345

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:

ADXL345 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 Kev Ceev:

Txoj Cai Rau Kev Ntsuas Kev Ceev
Txoj Cai Rau Kev Ntsuas Kev Ceev

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. Tus nab npawb nab npawb rau ADXL345 tuaj yeem rub tawm los ntawm peb lub zej zog github uas yog Tswj Txhua Lub Zej Zog.

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 tsev qiv ntawv smbus 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 tus nab npawb nab npawb ua haujlwm rau lub ntsuas no los ntawm no kuj:

ntshuam smbus

lub sij hawm ntshuam

# Tau I2C busbus = smbus. SMBus (1)

# ADXL345 chaw nyob, 0x53 (83)

# Xaiv tus lej tso npe tus lej bandwidth, 0x2C (44)

# 0x0A (10) Hom qub, Cov ntaub ntawv tawm tus nqi = 100 Hz

bus.write_byte_data (0x53, 0x2C, 0x0A)

# ADXL345 chaw nyob, 0x53 (83)

# Xaiv lub zog tswj npe, 0x2D (45)

# 0x08 (08) Pib Pw tsaug zog

bus.write_byte_data (0x53, 0x2D, 0x08)

# ADXL345 chaw nyob, 0x53 (83)

# Xaiv cov ntaub ntawv sau npe, 0x31 (49)

# 0x08 (08) Kev sim tus kheej tsis taus, 4-xaim interface

# Kev daws teeb meem tag nrho, Range = +/- 2g

bus.write_byte_data (0x53, 0x31, 0x08)

sijhawm.s pw (0.5)

# ADXL345 chaw nyob, 0x53 (83)

# Nyeem cov ntaub ntawv rov qab los ntawm 0x32 (50), 2 bytes

# X-Axis LSB, X-Axis MSB

data0 = npav.read_byte_data (0x53, 0x32)

data1 = npav.read_byte_data (0x53, 0x33)

# Hloov cov ntaub ntawv mus rau 10-ntsis

xAccl = ((data1 & 0x03) * 256) + data0

Yog tias xAccl> 511:

xAccl -= 1024

# ADXL345 chaw nyob, 0x53 (83)

# Nyeem cov ntaub ntawv rov qab los ntawm 0x34 (52), 2 bytes

# Y-Axis LSB, Y-Axis MSB

data0 = npav.read_byte_data (0x53, 0x34)

data1 = npav.read_byte_data (0x53, 0x35)

# Hloov cov ntaub ntawv mus rau 10-ntsis

yAccl = ((data1 & 0x03) * 256) + data0

Yog tias yAccl> 511:

yAccl -= 1024

# ADXL345 chaw nyob, 0x53 (83)

# Nyeem cov ntaub ntawv rov qab los ntawm 0x36 (54), 2 bytes

# Z-Axis LSB, Z-Axis MSB

data0 = npav.read_byte_data (0x53, 0x36)

data1 = npav.read_byte_data (0x53, 0x37)

# Hloov cov ntaub ntawv mus rau 10-ntsis

zAccl = ((data1 & 0x03) * 256) + data0

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

Ib feem ntawm cov cai hais hauv qab no suav nrog cov tsev qiv ntawv xav tau los ua kom raug ntawm cov nab npawb nab npawb.

ntshuam smbusimport lub sijhawm

Txoj cai tuaj yeem ua tiav los ntawm kev ntaus cov lus hais hauv qab no hauv kab hais kom ua.

$> nab hab sej ADXL345.py

Cov zis ntawm lub ntsuas kuj tseem muaj nyob 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

ADXL345 yog qhov me me, nyias, lub zog loj, 3-axis accelerometer uas tuaj yeem ua haujlwm hauv Tes, Cov cuab yeej siv kho mob thiab lwm yam.

Pom zoo: