Vibration Data logger with ADXL345
hello everyone!
i trying build vibration datalogger recording vibrations on machine. consist of 4 arduino uno adxl345 sensors , raspberry pi database.
the raspberry pi read data coming arduinos , insert them mysql table. @ moment planning use usb ports communication (max distance raspberry pi arduino less 3 meters).
the required resolution 4g , data rate approximately 1000hz (thus selected 800hz).
at moment saving readings file on raspberry pi, , main problem getting 70-80 readings per second. not coding expert , have started adxl345 basic code can found everywhere , done little modifications.
could can me find problem data rate?
regards
i trying build vibration datalogger recording vibrations on machine. consist of 4 arduino uno adxl345 sensors , raspberry pi database.
the raspberry pi read data coming arduinos , insert them mysql table. @ moment planning use usb ports communication (max distance raspberry pi arduino less 3 meters).
the required resolution 4g , data rate approximately 1000hz (thus selected 800hz).
at moment saving readings file on raspberry pi, , main problem getting 70-80 readings per second. not coding expert , have started adxl345 basic code can found everywhere , done little modifications.
could can me find problem data rate?
code: [select]
//add spi library can communicate adxl345 sensor
#include <spi.h>
//assign chip select signal pin 10.
int cs=10;
char power_ctl = 0x2d;
char data_format = 0x31;
char bw_rate = 0x2c;
char datax0 = 0x32; //x-axis data 0
char datax1 = 0x33; //x-axis data 1
char datay0 = 0x34; //y-axis data 0
char datay1 = 0x35; //y-axis data 1
char dataz0 = 0x36; //z-axis data 0
char dataz1 = 0x37; //z-axis data 1
//this buffer hold values read adxl345 registers.
char values[10];
//these variables used hold x,y , z axis accelerometer values.
int x,y,z;
void setup(){
//initiate spi communication instance.
spi.begin();
//configure spi connection adxl345.
spi.setdatamode(spi_mode3);
//set chip select pin output arduino.
pinmode(cs, output);
//before communication starts, chip select pin needs set high.
digitalwrite(cs, high);
writeregister(data_format, 0x01);
writeregister(power_ctl, 0x08);
writeregister(bw_rate, 0x0e);
//create serial connection display data on terminal.
serial.begin(9600);
}
void loop(){
//reading 6 bytes of data starting @ register datax0 retrieve x,y , z acceleration values adxl345.
//the results of read operation stored values[] buffer.
readregister(datax0, 6, values);
//the adxl345 gives 10-bit acceleration values, stored bytes (8-bits). full value, 2 bytes must combined each axis.
x = ((int)values[1]<<8)|(int)values[0];
y = ((int)values[3]<<8)|(int)values[2];
z = ((int)values[5]<<8)|(int)values[4];
serial.print(x);
serial.print(",");
serial.print(y);
serial.print(",");
serial.println(z);
}
//this function write value register on adxl345.
//parameters:
// char registeraddress - register write value to
// char value - value written specified register.
void writeregister(char registeraddress, char value){
//set chip select pin low signal beginning of spi packet.
digitalwrite(cs, low);
//transfer register address on spi.
spi.transfer(registeraddress);
//transfer desired register value on spi.
spi.transfer(value);
//set chip select pin high signal end of spi packet.
digitalwrite(cs, high);
}
//this function read number of registers starting specified address , store values in buffer.
//parameters:
// char registeraddress - register addresse start read sequence from.
// int numbytes - number of registers should read.
// char * values - pointer buffer results of operation should stored.
void readregister(char registeraddress, int numbytes, char * values){
//since we're performing read operation, significant bit of register address should set.
char address = 0x80 | registeraddress;
//if we're doing multi-byte read, bit 6 needs set well.
if(numbytes > 1)address = address | 0x40;
//set chip select pin low start spi packet.
digitalwrite(cs, low);
//transfer starting register address needs read.
spi.transfer(address);
//continue read registers until we've read number specified, storing results input buffer.
for(int i=0; i<numbytes; i++){
values[i] = spi.transfer(0x00);
}
//set chips select pin high end spi packet.
digitalwrite(cs, high);
}
regards
quote
serial.begin(9600);9600 baud 960 ascii characters per second, . printing values, every character byte. while integer value 2 bytes in memory, converted characters print on serial.
increase baud rate high can without rpi choking.
it still cannot serial bandwidth fast need, consider creating struct hold data , copying struct elements rpi... there few examples of technique around forum... radio control stuff. struct data, can move data protocol.
ray
Arduino Forum > Using Arduino > Project Guidance > Vibration Data logger with ADXL345
arduino
Comments
Post a Comment