I'm trying to acquire, simultaneously, some data from a load cell (using the HX711 module) and the change of angle using a MPU6050, using an arduino uno (clone).
When I have both modules powered from arduino (5V), the values obtained from the gyroscope start to change and go forward (like it's counting milliseconds); while the values obtaine from the load cell are correct and not affected at all.
I've tried to achieve a stability to obtain both data simultaneously:
- supply 5v from an external source to both the module (same errors, of angles increasing) [no combination is working]
What is "sort of working badly" is that I'm powering MPU6050 with 3.3V from arduino and the load cell with 5V. I've also changed the DOUT and CLK pin for the HX711 from (5,3) to (13,5) of the arduino.
When I connect both with this connections the X angle (what I need as a data) from MPU6050 (in a flat surface) needs few seconds to converge to a number that is not zero (it usually stops at value 6).
Here's my code:
#include <Wire.h>
#include <MPU6050_light.h>
#include "HX711.h"
HX711 scale(13, 5); //HX711 scale(DOUT,CLK);
float calibration_factor = 5100; // this calibration factor is adjusted according to my load cell //verso il basso "aumenta il peso"..
float units;
float ounces;
//Gyro:
float X_angle;
float Y_angle;
float Z_angle;
MPU6050 mpu(Wire);
unsigned long timer = 0;
//Insert Integer
const byte numChars = 32;
char receivedChars[numChars]; // an array to store the received data
boolean newData = false;
int num2;
int oldnum2;
void setup()
{
Serial.begin(115200);
Wire.begin();
mpu.begin();
scale.set_scale();
scale.tare(); //Reset the scale to 0
long zero_factor = scale.read_average(); //Get a baseline reading
}
void loop() {
//Load Cell Part
scale.set_scale(calibration_factor); //Adjust to this calibration factor
units = scale.get_units(), 10;
if (units < 0)
{
units = 0.00;
}
ounces = units * 0.035274;
//Gyroscope part
mpu.update();
X_angle = mpu.getAngleX()+2.5; //corrections +2.5
Y_angle = mpu.getAngleY();
Z_angle = mpu.getAngleZ();
if((millis()-timer)>10) // print data every 10ms
{
Serial.print("P: ");
Serial.print(X_angle);
Serial.print("; R: ");
Serial.print(Y_angle);
Serial.print("; Y: ");
Serial.print(Z_angle);
Serial.print("; bilancino: ");
Serial.println(units);
timer = millis();
}
}
I have no idea how to solve this. What can I do to acquire these data correctly? Thanks