I have a shield sensor v5 controlling 4 servos on digital ports 4, 5, 6 and 7 and a bluetooth HC-05 on SD Card Interface using VCC, GND, D10 and D1.
/*
*
* Author: Lulu's blog (www.lucidar.me). Adaptado por
*
*
*/
#include <Wire.h>
#include <TimerOne.h>
#define MPU9250_ADDRESS 0x68
#define GYRO_FULL_SCALE_250_DPS 0x00
#define GYRO_FULL_SCALE_500_DPS 0x08
#define GYRO_FULL_SCALE_1000_DPS 0x10
#define GYRO_FULL_SCALE_2000_DPS 0x18
#define ACC_FULL_SCALE_2_G 0x00
#define ACC_FULL_SCALE_4_G 0x08
#define ACC_FULL_SCALE_8_G 0x10
#define ACC_FULL_SCALE_16_G 0x18
const int iLED = 13;
int16_t GAxes[6] = {0, 0, 0, 0, 0, 0};
/* :: Funcoes basicas :: */
// This function read Nbytes bytes from I2C device at address Address.
// Put read bytes starting at register Register in the Data array.
void I2Cread(uint8_t Address, uint8_t Register, uint8_t Nbytes, uint8_t* Data) {
// Set register address
Wire.beginTransmission(Address);
Wire.write(Register);
Wire.endTransmission();
// Read Nbytes
Wire.requestFrom(Address, Nbytes);
uint8_t index=0;
while (Wire.available())
Data[index++]=Wire.read();
}
// Write a byte (Data) in device (Address) at register (Register)
void I2CwriteByte(uint8_t Address, uint8_t Register, uint8_t Data) {
// Set register address
Wire.beginTransmission(Address);
Wire.write(Register);
Wire.write(Data);
Wire.endTransmission();
}
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
Wire.begin();
// Set accelerometers low pass filter at 5Hz
I2CwriteByte(MPU9250_ADDRESS,29,0x06);
// Set gyroscope low pass filter at 5Hz
I2CwriteByte(MPU9250_ADDRESS,26,0x06);
// Configure gyroscope range
I2CwriteByte(MPU9250_ADDRESS,27,GYRO_FULL_SCALE_1000_DPS);
// Configure accelerometers range
I2CwriteByte(MPU9250_ADDRESS,28,ACC_FULL_SCALE_4_G);
}
// ____________________________________
// ::: accelerometer and gyroscope :::
// Read accelerometer and gyroscope
void loop() {
uint8_t Buf[14];
I2Cread(MPU9250_ADDRESS,0x3B,A4,Buf);
// Create 16 bits values from 8 bits data
/*
// Accelerometer
int16_t ax=-(Buf[0]<<8 | Buf[1]);
int16_t ay=-(Buf[2]<<8 | Buf[3]);
int16_t az=Buf[4]<<8 | Buf[5];
*/
// Gyroscope
int16_t gx = -(Buf[8]<<8 | Buf[9]);
int16_t gy = -(Buf[10]<<8 | Buf[11]);
int16_t gz = Buf[12]<<8 | Buf[13];
// Display values
/*
// Accelerometer
Serial.print (ax,DEC);
Serial.print ("Ax\t");
Serial.print (ay,DEC);
Serial.print ("Ay\t");
Serial.print (az,DEC);
Serial.print ("Az\t");
*/
// Gyroscope
Serial.print (gx,DEC);
Serial.print ("Gx\t");
Serial.print (gy,DEC);
Serial.print ("Gy\t");
Serial.print (gz,DEC);
Serial.print ("Gz\t");
// End of line
Serial.println("");
delay(100);
}
The servos usually respond via bluetooth.
Using the MPU9250 module directly on the Arduino board I get the values of the sensors normally.
Now connecting the Sensor Shield, without the 9250 module and nothing connected to the serial analog ports returns me a static value.
Is there any way to compensate for the use of A4 and A5?