Placa pentru Analog Device ADXL345. ADXL345 este un accelerometru mic, subtire, cu un consum redus de energie, pe 3 axe cu masuratoare de rezolutie mare (13 biti) pana la 16 g. Datele de iesire digitale sunt formatate in complement fata de doi si sunt accesibile prin fie un SPI (cu 3 sau 4 fire) sau o interfata digitala I2C. ADXL345 este foarte potrivit pentru masuratori ale acceleratiei statice a gravitatiei in aplicatii care sesizeaza bascularea, ca si acceleratia dinamica rezultand din miscare sau socuri. Rezolutia sa mare (4 mg LSB) permite masurarea schimbarilor de inclinatie mai mici de 1,0 . Mai multe functii de sesizare speciale sunt furnizate. Sesizarea activitatii si inactivitatii depisteaza prezenta sau lipsa miscarii si daca acceleratia pe oricare axa excede un nivel setat de catre utilizator. Sesizarea batailor usoare depisteaza bataile simple sau duble. Sesizarea caderii libere depisteaza daca aparatul este in cadere. Aceste functii pot fi mapate pe unul din doi pini de iesire de intrerupere. Un buffer first in, first out (FIFO) cu 32 de nivele integrat, in curs de patentare, poate fi folosit pentru a stoca datele pentru a minimiza interventia procesorului gazda. Modurile cu consum redus permit administrarea energiei inteligenta, bazata pe miscare, cu sesizare de praguri si masuratori active de acceleratie cu disipare de energie extrem de scazuta. Cod Sursa include wire.h include adxl345.h ADXL345 adxl; variable adxl is an instance of the ADXL345 library void setup(){ Serial.begin(9600); adxl.powerOn(); set activity inactivity thresholds (0-255) adxl.setActivityThreshold(75); 62.5mg per increment adxl.setInactivityThreshold(75); 62.5mg per increment adxl.setTimeInactivity(10); how many seconds of no activity is inactive? look of activity movement on this axes – 1 on; 0 off adxl.setActivityX(1); adxl.setActivityY(1); adxl.setActivityZ(1); look of inactivity movement on this axes – 1 on; 0 off adxl.setInactivityX(1); adxl.setInactivityY(1); adxl.setInactivityZ(1); look of tap movement on this axes – 1 on; 0 off adxl.setTapDetectionOnX(0); adxl.setTapDetectionOnY(0); adxl.setTapDetectionOnZ(1); set values for what is a tap, and what is a double tap (0-255) adxl.setTapThreshold(50); 62.5mg per increment adxl.setTapDuration(15); 625 s per increment adxl.setDoubleTapLatency(80); 1.25ms per increment adxl.setDoubleTapWindow(200); 1.25ms per increment set values for what is considered freefall (0-255) adxl.setFreeFallThreshold(7); (5 – 9) recommended – 62.5mg per increment adxl.setFreeFallDuration(45); (20 – 70) recommended – 5ms per increment setting all interupts to take place on int pin 1 I had issues with int pin 2, was unable to reset it adxl.setInterruptMapping( ADXL345_INT_SINGLE_TAP_BIT, ADXL345_INT1_PIN ); adxl.setInterruptMapping( ADXL345_INT_DOUBLE_TAP_BIT, ADXL345_INT1_PIN ); adxl.setInterruptMapping( ADXL345_INT_FREE_FALL_BIT, ADXL345_INT1_PIN ); adxl.setInterruptMapping( ADXL345_INT_ACTIVITY_BIT, ADXL345_INT1_PIN ); adxl.setInterruptMapping( ADXL345_INT_INACTIVITY_BIT, ADXL345_INT1_PIN ); register interupt actions – 1 on; 0 off adxl.setInterrupt( ADXL345_INT_SINGLE_TAP_BIT, 1); adxl.setInterrupt( ADXL345_INT_DOUBLE_TAP_BIT, 1); adxl.setInterrupt( ADXL345_INT_FREE_FALL_BIT, 1); adxl.setInterrupt( ADXL345_INT_ACTIVITY_BIT, 1); adxl.setInterrupt( ADXL345_INT_INACTIVITY_BIT, 1); } void loop(){ int x,y,z; adxl.readAccel(x, y, z); read the accelerometer values and store them in variables x,y,z Output x,y,z values – Commented out Serial.print( X: ); Serial.print(x); Serial.print( Y: ); Serial.print(y); Serial.print( Z: ); Serial.println(z); } Raspberry PI Daca nu iti este clar ce este un accelerometru si care sunt aplicatiile lui practice, aici gasesti un document in limba romana care iti explica mai multe – http: robofun.ro forum viewtopic.php?f 16t 158 (microcontroller-ul folosit este Arduino, vezi mai jos pentru un tutorial pentru conectarea cu Raspberry PI) Cod Sursa gcc -o read_adxl readings_general.c include stdio.h include stdlib.h include fcntl.h include unistd.h include string.h include include include include define SRF02_I2C_ADDR 0x70 define ADXL345_I2C_ADDR 0x53 void selectDevice(int fd, int addr, char name) { if (ioctl(fd, I2C_SLAVE, addr) 0) { fprintf(stderr, %s not presentn , name); exit(1); } } void writeToDevice(int fd, int reg, int val) { char buf[2]; buf[0] reg; buf[1] val; if (write(fd, buf, 2) ! 2) { fprintf(stderr, Can 39;t write to ADXL345n ); exit(1); } } int main(int argc, char argv) { unsigned int range; int count, b; short x, y, z; float xa, ya, za; int fd; unsigned char buf[16]; char str[80] {}; char system_str[256] {}; if ((fd open( dev i2c-1 , O_RDWR)) 0) { Open port for reading and writing fprintf(stderr, Failed to open i2c busn ); exit(1); } initialise ADXL345 selectDevice(fd, ADXL345_I2C_ADDR, ADXL345 ); writeToDevice(fd, 0x2d, 0); writeToDevice(fd, 0x2d, 16); writeToDevice(fd, 0x2d, 8); writeToDevice(fd, 0x31, 0); writeToDevice(fd, 0x31, 11); while (1) { select ADXL345 selectDevice(fd, ADXL345_I2C_ADDR, ADXL345 ); buf[0] 0x32; if ((write(fd, buf, 1)) ! 1) { Send the register to read from fprintf(stderr, Error writing to i2c slaven ); exit(1); } if (read(fd, buf, 6) ! 6) { X, Y, Z accelerations fprintf(stderr, Unable to read from ADXL345n ); exit(1); } else { x buf[1] 8 buf[0]; y buf[3] 8 buf[2]; z buf[5] 8 buf[4]; xa (90.0 256.0) (float) x; ya (90.0 256.0) (float) y; za (90.0 256.0) (float) z; printf( X: %4.0f Y: %4.0f Z: %4.0fn , xa, ya, za); } usleep(9000); } return 0; } Descarca tutorial conectare Raspberry PI (PDF) Specificatii: 2,0-3,6V CC voltaj de alimentare energie ultra scazuta: 40uA in modul masuratoare, 0,1uA in mod standby la 2,5V detectie de bataie bataie dubla detectie de cadere libera interfete SPI si I2C Linkuri: Schema Datasheet Exemplu de control I2C (ATmega328) Cod exemplu (ATmega328) Exemplu mbed Exemplu Bildr Proiect Pedometru IoT !– !–