MPU-6050 settaggio scala accelerometri

Ciao, sto iniziando ad usare l’integrato in oggetto e scopiazzando il programma qua e la sono riuscito a farlo funzionare e a capire il funzionamento.
Adesso vorrei modificare il fondo-scala dell’accelerometro e portarlo a ±16g.
Leggendo la scheda tecnica dell’integrato credo di aver capito che devo comunicare di impostare il valore del registro 1C a 3.
Ho provato a inserire le seguenti linee di codice nel programma ma non funziona.
Mi potete aiutare?

// MPU-6050 Short Example Sketch
#include<Wire.h>
const int MPU=0x68;  // I2C address of the MPU-6050
int16_t AcX,AcY,AcZ,Tmp,GyX,GyY,GyZ;
void setup(){
  Wire.begin();
  Wire.beginTransmission(MPU);
  Wire.write(0x6B);  // PWR_MGMT_1 register
  Wire.write(0);     // set to zero (wakes up the MPU-6050)
  Wire.endTransmission(true);        
  Wire.beginTransmission(MPU);     QUESTA
  Wire.write(0x1C);                      QUESTA
  Wire.write(3);                           QUESTA
  Wire.endTransmission();             QUESTA
  Serial.begin(9600);
  
}
void loop(){
  Wire.beginTransmission(MPU

Mi rispondo da solo, come si vede dall'immagine postata il mio parametro 1c è composto da 5bit, quindi i codici giusti sono:

void setup(){
  Wire.begin();
  Wire.beginTransmission(MPU);
  Wire.write(0x6B);  // PWR_MGMT_1 register
  Wire.write(0);     // set to zero (wakes up the MPU-6050)
  Wire.endTransmission(true);
  Wire.beginTransmission(MPU);
  Wire.write(0x1C);
  Wire.write(11103);
  Wire.endTransmission();
  Serial.begin(9600);
  
}
void loop(){

cosi facendo ho una lettura nel monitor seriale di:

Accelerometer: X = 2103 | Y = 971 | Z = -234
Accelerometer: X = 2110 | Y = 986 | Z = -375
Accelerometer: X = 2111 | Y = 995 | Z = -349
Accelerometer: X = 2130 | Y = 1016 | Z = -272
Accelerometer: X = 2104 | Y = 981 | Z = -359
Accelerometer: X = 2098 | Y = 991 | Z = -355
Accelerometer: X = 2106 | Y = 989 | Z = -356
Accelerometer: X = 2091 | Y = 996 | Z = -351

infatti a specifica ho 2048 LSB/g

questo è quello che uso io per settare i registri, non so se c’è un modo più corretto per farlo ma funziona

// MPU-6050 Short Example Sketch
// By Arduino User JohnChi
// August 17, 2014
// Public Domain
#include<Wire.h>
const int MPU=0x68;  // I2C address of the MPU-6050
int16_t Tmp,GyX,GyY,GyZ;
#define TEMPERATURA_OFF (0<<7)|(0<<6)|(0<<5)|(0<<4)|(1<<3)|(0<<2)|(0<<1)|(0<<0)
#define TEMPERATURA_ON (0<<7)|(0<<6)|(0<<5)|(0<<4)|(0<<3)|(0<<2)|(0<<1)|(0<<0)
#define SET_2G ((0<<7)|(0<<6)|(0<<5)|(0<<4)|(0<<3)|(0<<2)|(0<<1)|(0<<0))
#define SET_4G ((0<<7)|(0<<6)|(0<<5)|(0<<4)|(1<<3)|(0<<2)|(0<<1)|(0<<0))
#define SET_8G ((0<<7)|(0<<6)|(0<<5)|(1<<4)|(0<<3)|(0<<2)|(0<<1)|(0<<0))
#define SET_16G ((0<<7)|(0<<6)|(0<<5)|(1<<4)|(1<<3)|(0<<2)|(0<<1)|(0<<0))
#define scale_factor_2G 16384.00
#define scale_factor_4G 8192.00
#define scale_factor_8G 4096.00
#define scale_factor_16G 2048.00
int16_t AcX,AcY,AcZ;
//double AcY;
//double AcZ;
//float GX;
//float GY;
//float G

byte lettura;

void setup(){
  Wire.begin();
  Wire.beginTransmission(MPU);
  Wire.write(0x6B);  // PWR_MGMT_1 register
  Wire.write(TEMPERATURA_ON); // scrivere TEMPERATURA_ON per attivare il termometro, TEMPERATURA_OFF per spegnerlo
  Wire.endTransmission(true);  
  //******************************************************** 
  Wire.beginTransmission(MPU); 
  Wire.write(0x1C); //ACCEL_CONFIG register
  Wire.write(SET_8G);    // scrivere SET_2G SET_4G SET_8G SET_16G in base al fondoscala voluto
  Wire.endTransmission(true);
  Serial.begin(57600);
  

}
void loop(){
  Wire.beginTransmission(MPU); //Begin a transmission to the I2C slave device with the given address. Subsequently, queue bytes for transmission with the write() function and transmit them by calling endTransmission(). 
  Wire.write(0x3B);  // starting with register 0x3B (ACCEL_XOUT_H) /// Writes data from a slave device in response to a request from a master, or queues bytes for transmission from a master to slave device (in-between calls to beginTransmission() and endTransmission()). 
  Wire.endTransmission(false); //Ends a transmission to a slave device that was begun by beginTransmission() and transmits the bytes that were queued by write(). If true, endTransmission() sends a stop message after transmission, releasing the I2C bus.If false, endTransmission() sends a restart message after transmission. The bus will not be released, which prevents another master device from transmitting between messages. This allows one master device to send multiple transmissions while in control.The default value is true. 
  Wire.requestFrom(MPU,14,true);  // request a total of 14 registers // Used by the master to request bytes from a slave device. The bytes may then be retrieved with the available() and read() functions. 
  AcX=Wire.read()<<8|Wire.read();  // 0x3B (ACCEL_XOUT_H) & 0x3C (ACCEL_XOUT_L)     
  AcY=Wire.read()<<8|Wire.read();  // 0x3D (ACCEL_YOUT_H) & 0x3E (ACCEL_YOUT_L)
  AcZ=Wire.read()<<8|Wire.read();  // 0x3F (ACCEL_ZOUT_H) & 0x40 (ACCEL_ZOUT_L)
  Tmp=Wire.read()<<8|Wire.read();  // 0x41 (TEMP_OUT_H) & 0x42 (TEMP_OUT_L)
  GyX=Wire.read()<<8|Wire.read();  // 0x43 (GYRO_XOUT_H) & 0x44 (GYRO_XOUT_L)
  GyY=Wire.read()<<8|Wire.read();  // 0x45 (GYRO_YOUT_H) & 0x46 (GYRO_YOUT_L)
  GyZ=Wire.read()<<8|Wire.read();  // 0x47 (GYRO_ZOUT_H) & 0x48 (GYRO_ZOUT_L)
  
  Serial.print("AcX = ");  Serial.print(AcX); Serial.print(" "); Serial.print((AcX/scale_factor_8G),3);
  Serial.print(" | AcY = ");  Serial.print(AcY);  Serial.print(" "); Serial.print((AcY/scale_factor_8G),3);
  Serial.print(" | AcZ = "); Serial.print(AcZ);  Serial.print(" ");  Serial.print((AcZ/scale_factor_8G),3);
  Serial.print(" | Tmp = "); Serial.print(Tmp/340.00+36.53);  //equation for temperature in degrees C from datasheet
  Serial.print(" | GyX = "); Serial.print(GyX);
  Serial.print(" | GyY = "); Serial.print(GyY);
  Serial.print(" | GyZ = "); Serial.println(GyZ);
  delay(100);
  /*//***************************
  Wire.beginTransmission(MPU);
  Wire.write(0x75);
  Wire.endTransmission(false);
  Wire.requestFrom(MPU,1,true);
  lettura=Wire.read();
  Serial.print("Indirizzo accelerometro  ");
  Serial.print("0x"); Serial.println(lettura,HEX);
  //***************************
  delay(2000);*/
}

Grazie mille, dopo cena lo provo.

doppiozero:
questo è quello che uso io per settare i registri, non so se c’è un modo più corretto per farlo ma funziona

// MPU-6050 Short Example Sketch

// By Arduino User JohnChi
// August 17, 2014
// Public Domain
#include<Wire.h>
const int MPU=0x68;  // I2C address of the MPU-6050
int16_t Tmp,GyX,GyY,GyZ;
#define TEMPERATURA_OFF (0<<7)|(0<<6)|(0<<5)|(0<<4)|(1<<3)|(0<<2)|(0<<1)|(0<<0)
#define TEMPERATURA_ON (0<<7)|(0<<6)|(0<<5)|(0<<4)|(0<<3)|(0<<2)|(0<<1)|(0<<0)
#define SET_2G ((0<<7)|(0<<6)|(0<<5)|(0<<4)|(0<<3)|(0<<2)|(0<<1)|(0<<0))
#define SET_4G ((0<<7)|(0<<6)|(0<<5)|(0<<4)|(1<<3)|(0<<2)|(0<<1)|(0<<0))
#define SET_8G ((0<<7)|(0<<6)|(0<<5)|(1<<4)|(0<<3)|(0<<2)|(0<<1)|(0<<0))
#define SET_16G ((0<<7)|(0<<6)|(0<<5)|(1<<4)|(1<<3)|(0<<2)|(0<<1)|(0<<0))
#define scale_factor_2G 16384.00
#define scale_factor_4G 8192.00
#define scale_factor_8G 4096.00
#define scale_factor_16G 2048.00
int16_t AcX,AcY,AcZ;
//double AcY;
//double AcZ;
//float GX;
//float GY;
//float G

byte lettura;

void setup(){
 Wire.begin();
 Wire.beginTransmission(MPU);
 Wire.write(0x6B);  // PWR_MGMT_1 register
 Wire.write(TEMPERATURA_ON); // scrivere TEMPERATURA_ON per attivare il termometro, TEMPERATURA_OFF per spegnerlo
 Wire.endTransmission(true);  
 //********************************************************
 Wire.beginTransmission(MPU);
 Wire.write(0x1C); //ACCEL_CONFIG register
 Wire.write(SET_8G);    // scrivere SET_2G SET_4G SET_8G SET_16G in base al fondoscala voluto
 Wire.endTransmission(true);
 Serial.begin(57600);

}
void loop(){
 Wire.beginTransmission(MPU); //Begin a transmission to the I2C slave device with the given address. Subsequently, queue bytes for transmission with the write() function and transmit them by calling endTransmission().
 Wire.write(0x3B);  // starting with register 0x3B (ACCEL_XOUT_H) /// Writes data from a slave device in response to a request from a master, or queues bytes for transmission from a master to slave device (in-between calls to beginTransmission() and endTransmission()).
 Wire.endTransmission(false); //Ends a transmission to a slave device that was begun by beginTransmission() and transmits the bytes that were queued by write(). If true, endTransmission() sends a stop message after transmission, releasing the I2C bus.If false, endTransmission() sends a restart message after transmission. The bus will not be released, which prevents another master device from transmitting between messages. This allows one master device to send multiple transmissions while in control.The default value is true.
 Wire.requestFrom(MPU,14,true);  // request a total of 14 registers // Used by the master to request bytes from a slave device. The bytes may then be retrieved with the available() and read() functions.
 AcX=Wire.read()<<8|Wire.read();  // 0x3B (ACCEL_XOUT_H) & 0x3C (ACCEL_XOUT_L)    
 AcY=Wire.read()<<8|Wire.read();  // 0x3D (ACCEL_YOUT_H) & 0x3E (ACCEL_YOUT_L)
 AcZ=Wire.read()<<8|Wire.read();  // 0x3F (ACCEL_ZOUT_H) & 0x40 (ACCEL_ZOUT_L)
 Tmp=Wire.read()<<8|Wire.read();  // 0x41 (TEMP_OUT_H) & 0x42 (TEMP_OUT_L)
 GyX=Wire.read()<<8|Wire.read();  // 0x43 (GYRO_XOUT_H) & 0x44 (GYRO_XOUT_L)
 GyY=Wire.read()<<8|Wire.read();  // 0x45 (GYRO_YOUT_H) & 0x46 (GYRO_YOUT_L)
 GyZ=Wire.read()<<8|Wire.read();  // 0x47 (GYRO_ZOUT_H) & 0x48 (GYRO_ZOUT_L)
 
 Serial.print("AcX = “);  Serial.print(AcX); Serial.print(” “); Serial.print((AcX/scale_factor_8G),3);
 Serial.print(” | AcY = “);  Serial.print(AcY);  Serial.print(” “); Serial.print((AcY/scale_factor_8G),3);
 Serial.print(” | AcZ = “); Serial.print(AcZ);  Serial.print(” “);  Serial.print((AcZ/scale_factor_8G),3);
 Serial.print(” | Tmp = “); Serial.print(Tmp/340.00+36.53);  //equation for temperature in degrees C from datasheet
 Serial.print(” | GyX = “); Serial.print(GyX);
 Serial.print(” | GyY = “); Serial.print(GyY);
 Serial.print(” | GyZ = "); Serial.println(GyZ);
 delay(100);
 ///**************************
 Wire.beginTransmission(MPU);
 Wire.write(0x75);
 Wire.endTransmission(false);
 Wire.requestFrom(MPU,1,true);
 lettura=Wire.read();
 Serial.print("Indirizzo accelerometro  ");
 Serial.print(“0x”); Serial.println(lettura,HEX);
 //***************************
 delay(2000);*/
}

L’ho provato ieri sera…il tuo è sicuramente il piu corretto e completo, il mio l’ho gia messo in pensione.
Grazie ancora

Di niente :)