Cov txheej txheem:

Raspberry Pi - ADXL345 3 -Axis Accelerometer Python Qhia: 4 Kauj Ruam
Raspberry Pi - ADXL345 3 -Axis Accelerometer Python Qhia: 4 Kauj Ruam

Video: Raspberry Pi - ADXL345 3 -Axis Accelerometer Python Qhia: 4 Kauj Ruam

Video: Raspberry Pi - ADXL345 3 -Axis Accelerometer Python Qhia: 4 Kauj Ruam
Video: Input Shaper with a Pi Pico - Klipper Tips 2024, Hlis ntuj nqeg
Anonim

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 °. Nov yog nws ua qauv qhia nrog raspberry pi siv tus lej nab npawb.

Kauj Ruam 1: Yam Koj Xav Tau..

Yam Koj Xav Tau.. !!
Yam Koj Xav Tau.. !!
Yam Koj Xav Tau.. !!
Yam Koj Xav Tau.. !!

1. Raspberry Pi

2. ADXL345

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 ADXL345 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 ADXL345 tuaj yeem rub tawm los ntawm peb GitHub chaw cia khoom- Dcube Store

Nov yog qhov txuas rau tib yam:

github.com/DcubeTechVentures/ADXL345..

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.

# ADXL345

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

ntshuam smbus

lub sij hawm ntshuam

# Tau I2C npav

npav = smbus. SMBus (1)

# ADXL345 chaw nyob, 0x53 (83)

# Xaiv tus lej bandwidth rau npe, 0x2C (44)# 0x0A (10) Hom ib txwm, 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

Kauj Ruam 4: 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: