Show Posts
Pages: 1 2 [3] 4
31  Using Arduino / Storage / Re: How to use SD library over SPI for logging SPI sensors? on: June 08, 2012, 01:42:27 am
Thanks for the quick reply, and your efforts put into the lib!

I downloaded the fat32 lib from google code but i can't find any examples doing this.

I thought of changing the datamode throughout the program (every time i want to write to SD i temporarily set datamode to 0) but no luck so far.

SO do i have to conclude that this comnination is at all not possible?

If so i would have to control my sensor through a multiplexer, that would be less efficient.Doable, but rather i would do it differently.

Thank you,

Jorrit
32  Using Arduino / Storage / How to use SD library over SPI for logging SPI sensors? on: June 07, 2012, 03:53:59 pm
Hi all,

i want to use the SD lib for logging the values coming from my ADXL345 accelerometer. The problem is that the SD lib uses SPI.setDataMode(SPI_MODE0) and the sensors requieres SPI_MODE3. Thus my sensors don't work when the SD library is connected.

Does anyone have experience on this topic? The tutorial by Jeremy is great but he uses analog sensors....

thanks in advacne !

my code:

Code:
//Add the SPI library so we can communicate with the ADXL345 sensor
#include <SPI.h>
#include <SD.h>

//Assign the Chip Select signal to pin 10.
int CS=10;
int chip_SD=3;

//This is a list of some of the registers available on the ADXL345.
//To learn more about these and the rest of the registers on the ADXL345, read the datasheet!
char POWER_CTL = 0x2D; //Power Control Register
char DATA_FORMAT = 0x31;
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 will hold values read from the ADXL345 registers.
unsigned char values[10];

//These variables will be used to hold the x,y and z axis accelerometer values.
int x,y,z;

float xg, yg, zg;

void setup(){
  //Initiate an SPI communication instance.
  SPI.begin();
  //Configure the SPI connection for the ADXL345.
  SPI.setDataMode(SPI_MODE3);
  //Create a serial connection to display the data on the terminal.
  Serial.begin(9600);

  //Set up the Chip Select pin to be an output from the Arduino.
  pinMode(CS, OUTPUT);
  //Before communication starts, the Chip Select pin needs to be set high.
  digitalWrite(CS, HIGH);

  //Put the ADXL345 into +/- 4G range by writing the value 0x01 to the DATA_FORMAT register.
  writeRegister(CS, DATA_FORMAT, 0x01);
  //Put the ADXL345 into Measurement Mode by writing 0x08 to the POWER_CTL register.
  writeRegister(CS, POWER_CTL, 0x08);  //Measurement mode

  Serial.print("Initializing SD card...");
  // make sure that the default chip select pin is set to
  // output, even if you don't use it:
  pinMode(53, OUTPUT);

  // see if the card is present and can be initialized:
  if (!SD.begin(chip_SD)) {
    Serial.println("Card failed, or not present");
    // don't do anything more:
    //return;
  }
  else{ 
    Serial.println("card initialized.");
  }


}

void loop(){
  //Reading 6 bytes of data starting at register DATAX0 will retrieve the x,y and z acceleration values from the ADXL345.
  //The results of the read operation will get stored to the values[] buffer.
  readRegister(CS, DATAX0, 6, values);


  //The ADXL345 gives 10-bit acceleration values, but they are stored as bytes (8-bits). To get the full value, two bytes must be combi
  //-ed for each axis.
    //The X value is stored in values[0] and values[1].
  x = ((int)values[1]<<8)|(int)values[0];
  //The Y value is stored in values[2] and values[3].
  y = ((int)values[3]<<8)|(int)values[2];
  //The Z value is stored in values[4] and values[5].
  z = ((int)values[5]<<8)|(int)values[4];

  xg = x * 0.0078;
  yg = y * 0.0078;
  zg = z * 0.0078;
  //Print the results to the terminal.

  Serial.print("acc 1,   G value (xyz): ");

  Serial.print(xg, 2);
  Serial.print("\t");
  Serial.print(yg, 2);
  Serial.print("\t");
  Serial.println(zg, 2);

  Serial.print("acc 1, raw value (xyz): ");
  Serial.print(x, DEC);
  Serial.print("\t");
  Serial.print(y, DEC);
  Serial.print("\t");
  Serial.println(z, DEC);

  Serial.println("");
 
  String str = "this is data";
  print_to_file(str);

  delay(2000);
}

//This function will write a value to a register on the ADXL345.
//Parameters:
//  char registerAddress - The register to write a value to
//  char value - The value to be written to the specified register.
void writeRegister(int pin, char registerAddress, char value){
  //Set Chip Select pin low to signal the beginning of an SPI packet.
  digitalWrite(pin, LOW);
  //Transfer the register address over SPI.
  SPI.transfer(registerAddress);
  //Transfer the desired register value over SPI.
  SPI.transfer(value);
  //Set the Chip Select pin high to signal the end of an SPI packet.
  digitalWrite(pin, HIGH);
}

//This function will read a certain number of registers starting from a specified address and store their values in a buffer.
//Parameters:
//  char registerAddress - The register addresse to start the read sequence from.
//  int numBytes - The number of registers that should be read.
//  char * values - A pointer to a buffer where the results of the operation should be stored.
void readRegister(int pin, char registerAddress, int numBytes,unsigned char * values){
  //Since we're performing a read operation, the most significant bit of the register address should be set.
  char address = 0x80 | registerAddress;
  //If we're doing a multi-byte read, bit 6 needs to be set as well.
  if(numBytes > 1)address = address | 0x40;
  //Set the Chip select pin low to start an SPI packet.
  digitalWrite(pin, LOW);
  //Transfer the starting register address that needs to be read.
  SPI.transfer(address);
  //Continue to read registers until we've read the number specified, storing the results to the input buffer.
  for(int i=0; i<numBytes; i++){
    values[i] = SPI.transfer(0x00);
  }
  //Set the Chips Select pin high to end the SPI packet.
  digitalWrite(pin, HIGH);
}

void print_to_file(String dataString){
  //open the file
  File dataFile = SD.open("datalog.txt", FILE_WRITE);

  // if the file is available, write to it:
  if (dataFile) {
    dataFile.println(dataString);
    dataFile.close();
    // print to the serial port too:
    Serial.println(dataString);
  } 
  // if the file isn't open, pop up an error:
  else {
    Serial.println("error opening datalog.txt");
  }
}
33  Using Arduino / Sensors / are these ADXL345 accelerometers broken or they just suck? on: June 07, 2012, 10:59:58 am
Hi all,

i recently bought 6 of these:

http://www.ebay.nl/itm/230743987142?ssPageName=STRK:MEWAX:IT&_trksid=p3984.m1423.l2649#ht_2539wt_1378

because they where cheap. Now i'm thinking that broken because i have hooked them up in SPI mode and in the same config, the readings are completely different:

All in horizontal position. According to the data sheet this should result in X = 0G Y = 0G  Z = 1G

This is what i get:

accelerometer 1:

Code:
acc 1,   G value (xyz): -0.24 -0.35 -0.34
acc 1, raw value (xyz): -31 -45 -43

acc 2:
Code:
acc 1,   G value (xyz): -0.71 12.11 0.87
acc 1, raw value (xyz): -91 1552 112

acc 1,   G value (xyz): -0.73 -0.12 0.75
acc 1, raw value (xyz): -94 -16 96

acc 1,   G value (xyz): -0.73 -0.12 -1.00
acc 1, raw value (xyz): -94 -16 -128

acc 1,   G value (xyz): -0.71 4.12 0.75
acc 1, raw value (xyz): -91 528 96



acc 3:

Code:
acc 1,   G value (xyz): 0.56 -1.17 -0.03
acc 1, raw value (xyz): 72 -150 -4

acc 1,   G value (xyz): 0.56 -1.17 -0.02
acc 1, raw value (xyz): 72 -150 -3

acc 1,   G value (xyz): 0.57 -1.17 -0.02
acc 1, raw value (xyz): 73 -150 -2

acc 1,   G value (xyz): 0.57 -1.17 -0.02
acc 1, raw value (xyz): 73 -150 -2



and the fourth:

Code:
acc 1,   G value (xyz): 0.07 -0.01 0.89
acc 1, raw value (xyz): 9 -1 114

acc 1,   G value (xyz): 0.07 -0.01 0.89
acc 1, raw value (xyz): 9 -1 114

acc 1,   G value (xyz): 0.07 -0.01 0.89
acc 1, raw value (xyz): 9 -1 114


and acc 5:

Code:
acc 1,   G value (xyz): -0.09 0.06 -0.84
acc 1, raw value (xyz): -12 8 -108


and 6th:

Code:
acc 1,   G value (xyz): -0.26 -0.18 -0.30
acc 1, raw value (xyz): -33 -23 -38



So some are not conistent, it looks like they are moving while being in rest. Others just give too high values.

is it normal that you would need to compenstate or recalculate the correct values? In the tutorial on sparkfun they do not mention any calibration:

http://www.sparkfun.com/tutorials/240

Do i need to calibrate?


34  Using Arduino / Sensors / Re: How to use multiple accelerometers on arduino MEGA through I2C on: June 07, 2012, 08:34:28 am
Ok according to http://www.avrfreaks.net/index.php?name=PNphpBB2&file=viewtopic&t=63921 you cant hookup more than four (of the same) sensors on I2C.

So went for SPI instead. Was a good learn though!
35  Using Arduino / Sensors / Re: How to use multiple accelerometers on arduino MEGA through I2C on: June 06, 2012, 08:48:55 am
Hi pylon,

I was being dumb.

the readings:

horizontal:
Code:
Raw 1: -63   -117   945   Scaled 1: -0.25G   -0.46G   3.69G
Raw 2: -338   -177   1213   Scaled 2: -1.32G   -0.69G   4.73G

and after switching the sensors:

Code:
Raw 1: -344   -154   1203   Scaled 1: -1.34G   -0.60G   4.69G
Raw 2: -73   -110   936   Scaled 2: -0.27G   -0.43G   3.65G

Which seem ok, the rows just changed their position.

but vertical:
Code:
Raw 1: -368   -85   727   Scaled 1: -1.44G   -0.33G   2.84G
Raw 2: 138   33   503       Scaled 2: 0.55G   0.12G   1.95G


and switched positions:
Code:
Raw 1: 139   21   479   Scaled 1: 0.55G   0.08G   1.88G
Raw 2: -377   -90   704   Scaled 2: -1.47G   -0.35G   2.75G

Ok these reading are OK too. Well at least its consistent and i know i got the wiring right. The values are not consitent though from accelerometer to accelerometer. But i got these from China, for 5$ per breakout so something had to be wrong somewhere i guess smiley-sad

About the multiplexer, would it requiere a library or is it just a matter of coding a loop in order to get all readings from all connected slaves?

OK thanks once more.

Jorrit
36  Using Arduino / Networking, Protocols, and Devices / Weird output from ADXL345 in master plus 2 slave setup. on: June 05, 2012, 03:29:08 pm
Hi all,

i have encountered strange behavior when trying to connect 2 ADXL345 to 1 I2C bus.

I think i put my question in the wrong forum, but please have a look a it (or move the topic if you're a moderator)

http://arduino.cc/forum/index.php/topic,108712.0.html

Thank you all.
37  Using Arduino / Sensors / Re: How to use multiple accelerometers on arduino MEGA through I2C on: June 05, 2012, 03:03:29 pm
I changed the resistors to 2k (placed 2 times 1k in serie) and directly connected the SDA and SCL from both slaves (the sensors) to each other. From this junction i connected to the 3.3V throuh a 2k pull up resistor.

hope this picture clarifies somewhat:



My output is still strange:

Code:
Raw 1: -110   12   814    Scaled 1: -0.43G   0.03G   3.00G
Raw 2: 1024   51   -13050    Scaled 2: 3.99G   0.20G   -50.90G
Raw 1: -104   8   815            Scaled 1: -0.41G   0.03G   3.18G
Raw 2: 1024   51   -13050    Scaled 2: 3.99G   0.20G   -50.90G

The readings from slave device 2 (left in the picture) are still way too large (especially the 50,90 G)

In single setup both the sensors work fine.

Can the wiring be the problem?

Thank you
38  Using Arduino / Sensors / How to use multiple accelerometers on arduino MEGA through I2C on: June 05, 2012, 07:43:54 am
Hi all,

I need to hook up 8 (but will start with 2) ADXL345 accelerometers. I thought of using the library by loveelectronics:

https://www.loveelectronics.co.uk/Tutorials/12/adxl345-accelerometer-arduino-tutorial

which works fine (after minor updates) for one accelerometer. The output of the sensor in flat position is:

Code:
Raw 1: 24   -4   247    Scaled 1: X: 0.09G   Y: -0.02G   Z: 0.96G
which is correct according to the datasheet.

 But i need to hook up some more sensors, so I tried instantiating another accelerometer in my code and pass it the alternate address as given in the datasheet on page 18:

http://www.analog.com/static/imported-files/data_sheets/ADXL345.pdf which is 0x53.

But now the output becomes (both sensors in flat position):

Code:
Raw 2: 1024   51   -13050    Scaled 2: 3.99G   0.20G   -7.98G
Raw 1: 18   4   40            Scaled 1: 0.07G   0.02G   0.16G
Raw 2: 1024   51   -13050    Scaled 2: 3.99G   0.20G   -7.98G
Raw 1: 18   2   40            Scaled 1: 0.06G   0.02G   0.16G
Raw 2: 1024   51   -13050    Scaled 2: 3.99G   0.20G   -50.90G
Raw 1: 18   4   42            Scaled 1: 0.07G   0.02G   0.16G
Raw 2: 1024   51   -13050    Scaled 2: 3.99G   0.20G   -50.91G

It seems that readings from one sensor are multiplied, subtracted or divided by the reading from the other sensor.

the wiring is like this:



i just connected the SDA and SDL pins from both sensors to pin 20 and 21 on the arduino. My guess is that i went wrong here.

Then the code for reference:

Code:
// Include the Wire library so we can start using I2C.
#include <Wire.h>
// Include the Love Electronics ADXL345 library so we can use the accelerometer.
#include <ADXL345.h>

// Declare a global instance of the accelerometer.
ADXL345 accel;
ADXL345 accel_2;

// Set up a pin we are going to use to indicate our status using an LED.
int statusPin = 2; // I'm using digital pin 2.

void setup()
{
  // Begin by setting up the Serial Port so we can output our results.
  Serial.begin(9600);
  // Start the I2C Wire library so we can use I2C to talk to the accelerometer.
  Wire.begin();

  // Ready an LED to indicate our status.
  pinMode(statusPin, OUTPUT);

  // Create an instance of the accelerometer on the default address (0x1D)
  accel = ADXL345();
  accel_2 = ADXL345(0x53);

  // Check that the accelerometer is infact connected.
  if(accel.EnsureConnected())
  {
    Serial.println("Connected to sensors.");
    digitalWrite(statusPin, HIGH); // If we are connected, light our status LED.
  }
  else
  {
    Serial.println("Could not connect to ADXL345.");
    digitalWrite(statusPin, LOW); // If we are not connected, turn our LED off.
  }

  // Set the range of the accelerometer to a maximum of 2G.
  accel.SetRange(4, true);
  accel_2.SetRange(4, true);
  // Tell the accelerometer to start taking measurements.
  accel.EnableMeasurements();
  accel_2.EnableMeasurements();
}

void loop() {
  if(accel.IsConnected) // If we are connected to the accelerometer.
  {
    // Read the raw data from the accelerometer.
    AccelerometerRaw raw = accel.ReadRawAxis();
    AccelerometerRaw raw_2 = accel_2.ReadRawAxis();

    AccelerometerScaled scaled = accel.ReadScaledAxis();
    AccelerometerScaled scaled_2 = accel_2.ReadScaledAxis();

    Output(raw, raw_2, scaled, scaled_2);
  }
}

void Output(AccelerometerRaw raw, AccelerometerRaw raw_2, AccelerometerScaled scaled, AccelerometerScaled scaled_2)
{
  // Tell us about the raw values coming from the accelerometer.
  Serial.print("Raw 1:\t");
  Serial.print(raw.XAxis);
  Serial.print("   ");   
  Serial.print(raw.YAxis);
  Serial.print("   ");   
  Serial.print(raw.ZAxis);

  // Tell us about the this data, but scale it into useful units (G).
  Serial.print("   \tScaled 1:\t");
  Serial.print(scaled.XAxis);
  Serial.print("G   ");   
  Serial.print(scaled.YAxis);
  Serial.print("G   ");   
  Serial.print(scaled.ZAxis);
  Serial.println("G");
 
    // Tell us about the raw values coming from the accelerometer.
  Serial.print("Raw 2:\t");
  Serial.print(raw_2.XAxis);
  Serial.print("   ");   
  Serial.print(raw_2.YAxis);
  Serial.print("   ");   
  Serial.print(raw_2.ZAxis);

  // Tell us about the this data, but scale it into useful units (G).
  Serial.print("   \tScaled 2:\t");
  Serial.print(scaled_2.XAxis);
  Serial.print("G   ");   
  Serial.print(scaled_2.YAxis);
  Serial.print("G   ");   
  Serial.print(scaled_2.ZAxis);
  Serial.println("G");

}




Any help on getting multiple I2C sensors working is appriciated!

Jorrit

39  Using Arduino / General Electronics / Re: Can an experienced solder person solder a tiny sensor? on: May 11, 2012, 09:09:58 am
Thanks to all,

I'll try and solder one, if i fail i thinks i have to get some sensors on a breakoutboard.
40  Using Arduino / General Electronics / Can an experienced solder person solder a tiny sensor? on: May 10, 2012, 06:56:32 pm
Hi all,

I just ordered 6 of these accelerometers http://www.bosch-sensortec.com/content/language1/downloads/BST-BMA150-DS000-07.pdf. But i just ordered the sensors themselves, not placed on a breakboard.

How would i connect a wire to them? there only 3 x 3 mm?

Excuse me f this rather obvious (and stupid).
41  Using Arduino / Sensors / Re: How to determine sensor is compatible with Arduino UNO? on: May 09, 2012, 01:57:32 pm
Ok thanks, you both helped me out a lot!
42  Using Arduino / Sensors / Re: How to determine sensor is compatible with Arduino UNO? on: May 09, 2012, 10:32:16 am
Thank you Chagrin, very informative.

Two questions though:

The 3.3V pin on the Uno is a 3.3V regulated, positive supply. You can use this to power your Bosch sensor or the ITG3200 safely. You still need to be aware that any digital output from the Uno to your sensor will be 5V and should have either a small transistor or at least a resistor voltage divider to knock that voltage down.
Ok soldering a resistor of transistor should not be too hard. There is no option of NOT connecting the ouput of the UNO to the sensor? This may sound stupid but i thought that, since i only need to READ values from the sensor it could work?
But if i'm not mistaken, since i use I2C, their is only one connection pin between UNO and sensor?

With respect to the Sparkfun ADXL345 board, they run the ATMega at 3V. While it's plugged in to a USB 5V port they never use the 5V power for anything other than the FTDI (USB to serial) chip. The ATMega will see the 5V TX/RX signals from the FTDI chip but the accelerometer never sees any 5V signals from the ATMega.
Can the UNO also be run at 3V? That would solve my problem at once i would say?

Thanks again.
43  Using Arduino / Sensors / Re: Interface Arduino with GPS, accelerometer, gyro, magnetometer, barometer on: May 09, 2012, 09:37:55 am

2) I have also found another solution. It's based on Arduino. Give a look, I think it's quite good, Only there aren't characteristics of IMU:
https://store.diydrones.com/Full_ArduPi ... apm-02.htm
What do you think about it? I can also take datas out from USB.

Thanks for your patience.
stiv

you posted a broken link, please edit!
44  Using Arduino / Sensors / Re: Interface Arduino with GPS, accelerometer, gyro, magnetometer, barometer on: May 09, 2012, 07:02:04 am
Dear krodal,

you state:

It's not hard. The only problem is that most sensors use 3.3V. But the Arduino has 3.3V onboard for those sensors.

The accelerometer i want to use in my project runs on 3V (http://www.bosch-sensortec.com/content/language1/downloads/BMA150_Flyer_Rev1.3_14JAN2008.pdf)

I was in the understanding that i could not use this sensor directly on the arduino UNO since the arduino runs on 5V (and it would fry the sensor). But if you look at the arduino picture:



You see that at the bottom there is indeed a pin which states 3.3V.  Does this mean that the board can run on 3.3v as well, or what is the pin for?

in the tutorial on arduino.cc (http://www.arduino.cc/en/Tutorial/ADXL3xx) it says that the example uses the breakoutboard from sparkfun. http://www.sparkfun.com/products/9814 But it seems that even that board requieres 3.3V. How can they manage?

Thank you,

Jorrit
(i've also put this question in the topic list)
 
45  Using Arduino / Sensors / Re: How to determine sensor is compatible with Arduino UNO? on: May 09, 2012, 01:34:38 am
Thanks for the reply. one more question though:

How can i determine, *in general terms*, which sensors i can use without any converters? The datasheets overwhelm me somewhat since i'm not very technical. But a hint on what i should look for is very much appriciated!

 
Pages: 1 2 [3] 4