Go Down

Topic: Giroscópio SD740 comunicação SPI não funciona (Read 1 time) previous topic - next topic

junior001

Estou precisando comunicar através de SPI esse sensor giroscópio SD740 com o arduino, através do código do fabricante ele da um erro de leitura, já verifiquei as pinagens e o código não entendi muito alguém poderia me ajudar?

Link sensor: http://www.dfrobot.com/index.php?route=product/product&path=36_59&product_id=517#.UD1bQMGPXfI
Link programação e ligação: http://www.dfrobot.com/wiki/index.php?title=Tri-Axis_Gyro_Breakout-SD740_(SKU:_SEN0095)

esse código não apresenta nenhum erro quando verificado, já o código do I2C apresenta vários erros.

alguem poderia me dar um HELP.... =x
Code: [Select]
/*
Gyroscope SD740 SPI connection

Version 1.0  Lauren <Lauran.pan@gmail.com> 

Pin connection to the Arduino board:

CSN         ->   digital pin 10(D10)
MOSI/SDA    ->   digital pin 11(D11)
MISO/ADDR   ->   digital pin 12(D12)
SCL         ->   digital pin 13(D13)

Operating Supply Voltage           V    2.6 - 5% - 3.3 + 5%
Full Scale Range (digital output) °/s  1024
Sensitivity Accuracy               %    ± 5
Sensitivity Error Over Temperature %    ± 5
Signal Update Rate                 KHz  10
SPI Communication Speed            MHz  40

Full scale range is factory defined. Please contact SensorDynamics for setting different ranges. Maximum full scale
factor is 4096°/s
Bandwidth is factory defined. Please contact SensorDynamics for setting different ranges. Maximum bandwidth is
150Hz

*/


#include <SPI.h>

#define DataRegister 0x00
#define CS_Pin 10            //chip selection pin

char receiveData[128];        //data array
int x,y,z;
float xg,yg,zg;
float absHeading = 0;         // calculate the absolute heading
unsigned long iTime = 0;     

void setup(){

  Serial.begin(57600);

  SPI.begin();
  SPI.setDataMode(SPI_MODE0);

  pinMode(CS_Pin, OUTPUT);// init the chip selection pin
  digitalWrite(CS_Pin, HIGH);

  checkGyroStatus();
 
}

void checkGyroStatus(){

  readRegister(20,1,receiveData);
  Serial.print("check lock state:\t");
  Serial.println(receiveData[0],BIN);//bin; 110 means works well
 
  if(bitRead(receiveData[0],1) == 0 || bitRead(receiveData[0],2) == 0){
    Serial.println("Chip start error! You could reset the arduino board");
    while(1){
    }
  }

  readRegister(70,1,receiveData);
  Serial.print("check standby bit:\t");
  Serial.println(receiveData[0],BIN);//check bit0 0->normal 1->standby
 
}

void loop(){
 
  readRegister(DataRegister, 6, receiveData);

  x = ((int)receiveData[0]<<8)|(int)receiveData[1];
  y = ((int)receiveData[2]<<8)|(int)receiveData[3];
  z = ((int)receiveData[4]<<8)|(int)receiveData[5];

  float scale = 0.03125;// scale: 1024 / 2^15

  xg = x * scale;
  yg = y * scale;
  zg = z * scale;
  float pastTime = float(micros() - iTime) / float(1000000);
  absHeading += zg * pastTime;
  iTime = micros();

  /*
  Serial.print(x, DEC);
  Serial.print(',');
  Serial.print(y, DEC);
  Serial.print(',');
  Serial.println(z, DEC);
  Serial.print((float)xg,2);
  Serial.print("\t");
  Serial.print((float)yg,2);
  Serial.print("\t");
  Serial.print((float)zg,2);
  Serial.println(" °/s");
  */
  Serial.print("Heading:");
  Serial.println(absHeading);//Axis Z absolute heading
 

  delay(10);

}

void writeRegister(char registerAddress, char value){

  digitalWrite(CS_Pin, LOW);
  SPI.transfer(registerAddress);
  SPI.transfer(value);
  digitalWrite(CS_Pin, HIGH);

}


void readRegister(char registerAddress, int numBytes, char * values){

  char address = 0x80 | registerAddress;
  digitalWrite(CS_Pin, LOW);
  SPI.transfer(address);
  for(int i=0; i<numBytes; i++){
    values[i] = SPI.transfer(0x00);
  }
  digitalWrite(CS_Pin, HIGH);

}



bubulindo

Code: [Select]

  Serial.println(receiveData[0],BIN);//bin; 110 means works well

if(bitRead(receiveData[0],1) == 0 || bitRead(receiveData[0],2) == 0){
    Serial.println("Chip start error! You could reset the arduino board");
    while(1){
    }
  }


Estes dois testes, não batem certo...
This... is a hobby.

junior001

Já descobri esse problema, era o arduino que era diferente, estou utilizando o mega, agora o problema é que a leitura do sensor está doida, está crescente... =X

Go Up
 


Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

Arduino
via Egeo 16
Torino, 10131
Italy