Cov txheej txheem:

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

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

Video: Raspberry Pi - ADXL345 3 -Axis Accelerometer Java Qhia: 4 Kauj Ruam
Video: Input Shaper with a Pi Pico - Klipper Tips 2024, Hlis ntuj nqeg
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 °. Nov yog nws ua qauv qhia nrog raspberry pi siv java code.

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

Java code 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 pi4j tsev qiv ntawv rau java code, cov kauj ruam rau nruab pi4j ntawm raspberry pi tau piav qhia ntawm no:

pi4j.com/install.html

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 ua haujlwm.

// ADXL345

// Cov cai no tau tsim los ua haujlwm nrog ADXL345_I2CS I2C Mini Module muaj nyob hauv Dcube Store.

ntshuam com.pi4j.io.i2c. I2CBus;

ntshuam com.pi4j.io.i2c. I2CDevice;

ntshuam com.pi4j.io.i2c. I2CFactory;

ntshuam java.io. IOException;

pej xeem chav ADXL345

{

pej xeem zoo li qub tsis muaj dab tsi tseem ceeb (Txoj hlua args ) cuam tshuam zam

{

// Tsim I2C npav

I2CBus Bus = I2CFactory.getInstance (I2CBus. BUS_1);

// Tau txais I2C ntaus ntawv, ntaus ntawv I2C chaw nyob yog 0x53 (83)

I2CDevice ntaus ntawv = Bus.getDevice (0x53);

// Xaiv Bandwidth tus nqi sau npe

// Hom qub, Cov ntaub ntawv tawm tus nqi = 100 Hz

device.write (0x2C, (byte) 0x0A);

// Xaiv lub hwj chim tswj npe

// Auto-sleep lov tes taw

ntaus ntawv.write (0x2D, (byte) 0x08);

// Xaiv cov ntaub ntawv sau npe

// Kev ntsuas tus kheej xiam oob qhab, 4-xaim interface, Kev daws teeb meem tag nrho, thaj tsam = +/- 2g

device.write (0x31, (byte) 0x08);

Xov.sleep (500);

// Nyeem 6 bytes ntawm cov ntaub ntawv

// xAccl lsb, xAccl msb, yAccl lsb, yAccl msb, zAccl lsb, zAccl msb

byte cov ntaub ntawv = tshiab byte [6];

cov ntaub ntawv [0] = (byte) device.read (0x32);

cov ntaub ntawv [1] = (byte) device.read (0x33);

cov ntaub ntawv [2] = (byte) device.read (0x34);

cov ntaub ntawv [3] = (byte) device.read (0x35);

cov ntaub ntawv [4] = (byte) device.read (0x36);

cov ntaub ntawv [5] = (byte) device.read (0x37);

// Hloov cov ntaub ntawv mus rau 10-ntsis

int xAccl = ((data [1] & 0x03) * 256 + (data [0] & 0xFF));

yog (xAccl> 511)

{

xAccl -= 1024;

}

int yAccl = ((cov ntaub ntawv [3] & 0x03) * 256 + (data [2] & 0xFF));

yog (yAccl> 511)

{

yAccl -= 1024;

}

int zAccl = ((cov ntaub ntawv [5] & 0x03) * 256 + (data [4] & 0xFF));

yog (zAccl> 511)

{

zAccl -= 1024;

}

// Cov ntaub ntawv tso tawm rau lub vijtsam

System.out.printf ("Kev nrawm hauv X-Axis: %d %n", xAccl);

System.out.printf ("Kev nrawm hauv Y-Axis: %d %n", yAccl);

System.out.printf ("Acceleration in Z-Axis: %d %n", 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: