#include <Wire.h>
#include <Adafruit_Sensor.h>
#include <Adafruit_MPU6050.h>
#define SDA_1 26
#define SCL_1 27
// 22 scl
// 21 sda
Adafruit_MPU6050 mpu1;
Adafruit_MPU6050 mpu2;
//https://lastminuteengineers.com/fsr-arduino-tutorial/
#define fsrPin A0 // the FSR and 10K pulldown are connected to a0
int fsrReading; // the analog reading from the FSR resistor divider
int fsrVoltage; // the analog reading converted to voltage
unsigned long fsrResistance; // The voltage converted to resistance
unsigned long fsrConductance;
long fsrForce; // Finally, the resistance converted to force
void setup() {
Serial.begin(115200); // We'll send debugging information via the Serial monitor
Serial.println("mpu1x:, mpu1y:, mpu1z:, mpu2x:, mpu2y:, mpu2z:, fsr:");
Serial.println(F("MPU6050 test"));
Wire.begin();
Wire1.begin(SDA_1, SCL_1);
bool status1 = mpu1.begin(0x68);
if(!status1){
Serial.println("Could not find a valid MPU6050_1 sensor, check wiring!");
while(1);
}
bool status2 = mpu2.begin(0x68, &Wire1);
if(!status2){
Serial.println("Could not find a valid MPU6050_2 sensor, check wiring!");
while(1);
}
Serial.println("MPU6050 Found!");
mpu1.setGyroRange(MPU6050_RANGE_500_DEG);
Serial.print("Gyro range set to: ");
switch(mpu1.getGyroRange()){
case MPU6050_RANGE_250_DEG:
Serial.println("+- 250 deg/s");
break;
case MPU6050_RANGE_500_DEG:
Serial.println("+- 500 deg/s");
break;
case MPU6050_RANGE_1000_DEG:
Serial.println("+- 1000 deg/s");
break;
case MPU6050_RANGE_2000_DEG:
Serial.println("+- 2000 deg/s");
break;
}
mpu2.setGyroRange(MPU6050_RANGE_500_DEG);
Serial.print("Gyro range set to: ");
switch(mpu2.getGyroRange()){
case MPU6050_RANGE_250_DEG:
Serial.println("+- 250 deg/s");
break;
case MPU6050_RANGE_500_DEG:
Serial.println("+- 500 deg/s");
break;
case MPU6050_RANGE_1000_DEG:
Serial.println("+- 1000 deg/s");
break;
case MPU6050_RANGE_2000_DEG:
Serial.println("+- 2000 deg/s");
break;
}
Serial.println("");
delay(100);
}
void loop() {
sensors_event_t g1,g2;
mpu1.getGyroSensor()->getEvent(&g1);
mpu2.getGyroSensor()->getEvent(&g2);
Serial.print("MPU1 X: ");
Serial.print(g1.gyro.x);
Serial.print(", MPU2 X: ");
Serial.print(g2.gyro.x);
Serial.println("");
Serial.print("MPU1 Y: ");
Serial.print(g1.gyro.y);
Serial.print(", MPU2 Y: ");
Serial.print(g2.gyro.y);
Serial.println("");
Serial.print("MPU1 Z: ");
Serial.print(g1.gyro.z);
Serial.print(", MPU2 Z: ");
Serial.print(g2.gyro.z);
Serial.println(" rad/s ");
// // Send the data to the Serial Plotter
Serial.print(g1.gyro.x);
Serial.print(",");
Serial.print(g1.gyro.y);
Serial.print(",");
Serial.print(g1.gyro.z);
Serial.print(",");
Serial.print(g2.gyro.x);
Serial.print(",");
Serial.print(g2.gyro.y);
Serial.print(",");
Serial.println(g2.gyro.z);
delay(1000);
Serial.println("--------------------");
readFSR();
Serial.println("--------------------");
Serial.println("--------------------");
delay(1000);
}
void readFSR(){
fsrReading = analogRead(fsrPin);
Serial.print("Analog reading = ");
Serial.println(fsrReading);
// analog voltage reading ranges from about 0 to 4095 which maps to 0V to 3.3V (= 3300mV)
fsrVoltage = map(fsrReading, 0, 4095, 0, 3300);
Serial.print("Voltage reading in mV = ");
Serial.println(fsrVoltage);
if (fsrVoltage == 0)
{
Serial.println("No pressure");
}
else
{
//The voltage = Vcc * R / (R + FSR) where R = 10K and Vcc = 3.3V
//so FSR = ((Vcc - V) * R) / V yay math!
fsrResistance = 3300 - fsrVoltage; // fsrVoltage is in millivolts so 5V = 5000mV
fsrResistance *= 10000; // 10K resistor
if (fsrVoltage != 0)
{
fsrResistance /= fsrVoltage;
}
else
{
fsrResistance = 0; // Set resistance to 0 if fsrVoltage is 0
}
Serial.print("FSR resistance in ohms = ");
Serial.println(fsrResistance);
fsrConductance = 1000000; // we measure in micromhos so
fsrConductance /= fsrResistance;
Serial.print("Conductance in microMhos: ");
Serial.println(fsrConductance);
// Use the two FSR guide graphs to approximate the force
if (fsrConductance <= 1000)
{
fsrForce = fsrConductance / 80;
Serial.print("Force in Newtons: ");
Serial.println(fsrForce);
} else
{
fsrForce = fsrConductance - 1000;
fsrForce /= 30;
Serial.print("Force in Newtons: ");
Serial.println(fsrForce);
}
}
}
the serial monitor show the right value but how to modified my coding so that the serial plotter will show the graph properly because for this coding, it shows two graph only? i want to plot the graph for all imu sensors and fsr sensor