Pages: [1]   Go Down
Author Topic: Adxl345 help  (Read 1043 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 2
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I am using an accelerometer from FIRST(Here is the datasheet http://www.usfirst.org/sites/default/files/uploadedFiles/Robotics_Programs/FRC/Game_and_Season__Info/2012_Assets/Accelerometer-Gyro.pdf) and when I try to connect it, no matter what I try to do, it will always give me either -1,-1,-1 or 0,0,0 for the readings. I am using an Arduino Uno and I tried these tutorials:
http://bildr.org/2011/03/adxl345-arduino/# and http://www.sparkfun.com/tutorials/240  and the given libraries for each one.

Any help is gladly appreciated.
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 5
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I was having a problem like that with the ADXL345 and the adafruit datalogging shield.  What I did was set the ADXL's CS pin to high before initializing the SD card then I set the ADXL's CS pin to high again and initialized the accelerometer.

The problem was that the accelerometer was using the same pins as the datalogging shield and when I tried to extract data it wouldn't work because the pins were in use.  I called a File.flush() after I saved the data and the accelerometer readings were back to normal.
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 5
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Code:
void setup(){
  //Initiate an SPI communication instance.
  SPI.begin();

  //Create a serial connection to display the data on the terminal.
  Serial.begin(38400);
 
  // use debugging LEDs
  pinMode(redLEDpin, OUTPUT);
  pinMode(greenLEDpin, OUTPUT);
 
  // set the SD CS pin to output
  pinMode(SD_CS, OUTPUT); 
 
  //Set up the Chip Select pin to be an output from the Arduino.
  pinMode(ADXL_CS, OUTPUT);
  //Before communication starts, the Chip Select pin needs to be set high.
  //  must be set to high so the SD card won't talk at the same time
  digitalWrite(ADXL_CS, HIGH);
 
  // initialize the sd card
  if (!SD.begin(SD_CS) )
  {
    Serial.println("Couldn't Initialize SD Card");
    return;
  }
  else
    Serial.println("Done Initializing SD Card");
   
  //  create a new file that starts with logger00 and the next one will be logger01 if logger00 exists
  char filename[] = "LOGGER00.CSV";
  for (int i = 0; i < 100; i++)
  {
    filename[6] = i/10 + '0';
    filename[7] = i%10 + '0';
    if (! SD.exists(filename))
    {
      // only open a new file if it doesn't exist
      myFile = SD.open(filename, FILE_WRITE);
      break;  // leave the loop!
    }
  }
 
  // set up the file header
  myFile.println("x-axis,y-axis,z-axis,millis,free-fall");
 
  //Configure the SPI connection for the ADXL345.
  SPI.setDataMode(SPI_MODE3);
 
  // before communication starts the CS pin must be set to high
  digitalWrite(ADXL_CS,HIGH);
 
  //Put the ADXL345 into +/- 16G range by writing the value 0x01 to the DATA_FORMAT register.
  //writeRegister(DATA_FORMAT, 0x0F);
 
  /// set the accelerometer into full resolution mode and +/- 16G mode
  writeRegister( DATA_FORMAT, 0x08 | 0x0F);

  // enable free fall interrupt
  writeRegister(INT_MAP, 0x00);  // pass the interrupt to the first interrupt pin
  writeRegister(INT_ENABLE,0x04);  // enable the free fall function
 

  // Sets the THRESH_FF register which holds the threshold value, in an unsigned format, for
  // free-fall detection. The root-sum-square (RSS) value of all axes is calculated and
  // compared whith the value in THRESH_FF to determine if a free-fall event occured. The
  // scale factor is 62.5mg/LSB. A value of 0 may result in undesirable behavior if the free-fall
  // interrupt is enabled. The maximum value is 255
  writeRegister(THRESH_FF, 10);
 
  // Sets the TIME_FF register, which holds an unsigned time value representing the minimum
  // time that the RSS value of all axes must be less than THRESH_FF to generate a free-fall
  // interrupt. The scale factor is 5ms/LSB. A value of 0 may result in undesirable behavior if
  // the free-fall interrupt is enabled. The maximum value is 255.
  writeRegister(TIME_FF,1);
 
  //Put the ADXL345 into Measurement Mode by writing 0x08 to the POWER_CTL register.
  writeRegister(POWER_CTL, 0x08);  //Measurement mode 
  writeRegister(BW_RATE,0x0F);  // change sampling rate
 
}
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 2
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I am not using an sd card, just the accelerometer.
« Last Edit: April 21, 2012, 11:26:29 am by dombeef » Logged

0
Offline Offline
Shannon Member
****
Karma: 218
Posts: 12583
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I am using an accelerometer from FIRST(Here is the datasheet http://www.usfirst.org/sites/default/files/uploadedFiles/Robotics_Programs/FRC/Game_and_Season__Info/2012_Assets/Accelerometer-Gyro.pdf) and when I try to connect it, no matter what I try to do, it will always give me either -1,-1,-1 or 0,0,0 for the readings. I am using an Arduino Uno and I tried these tutorials:
http://bildr.org/2011/03/adxl345-arduino/# and http://www.sparkfun.com/tutorials/240  and the given libraries for each one.

Any help is gladly appreciated.

Please post your code and schematic.
Logged

[ I won't respond to messages, use the forum please ]

Pages: [1]   Go Up
Jump to: