I try tu set up 3 load cells and accelerometer and if I use command wire.begin() and then try to get measurement from scale2 the arduino crashes end stops doing anything. I'm using arduino leonardo and if I coment wire.begin() everything works normaly. Can someone help me please
#include <Wire.h>
#include <SparkFun_KX13X.h> // Click here to get the library: http://librarymanager/All#SparkFun_KX13X
#include <string.h>
#include <HX711.h>
#include <LiquidCrystal.h>
const int buttonPin = 6;
int buttonState = 0;
const int rs = 8, en = 13, d4 = 9, d5 = 10, d6 = 11, d7 = 12;
#define calibration_factor -199000.00
#define dout1 0
#define clk1 1
#define dout2 2
#define clk2 3
#define dout3 4
#define clk3 5
//SparkFun_KX132 kxAccel;
SparkFun_KX134 kxAccel; // For the KX134, uncomment this and comment line above
outputData myData; // Struct for the accelerometer's data
HX711 scale1(dout1,clk1);
HX711 scale2(dout2,clk2);
HX711 scale3(dout3,clk3);
LiquidCrystal lcd(rs, en, d4, d5, d6, d7);
void setup() {
//set up belek tensometrycznych
Serial.begin(9600);
// Wait for the Serial monitor to be opened.
while (!Serial)
delay(50);
lcd.begin(16, 2);
Serial.println("test wag");
scale1.set_scale(calibration_factor);
scale1.tare();
scale2.set_scale(calibration_factor);
scale2.tare();
scale3.set_scale(calibration_factor);
scale3.tare();
//Serial.println("reading");
if(scale1.is_ready()){
Serial.println("scale1 good");
}
if(scale2.is_ready()){
Serial.println("scale2 good");
}
if(scale3.is_ready()){
Serial.println("scale3 good");
}
//Serial.println(scale1.is_ready());
//set up akcelerometrow
pinMode(buttonPin,INPUT);
delay(1000);
Wire.begin();
while (!Serial)
delay(50);
if (!kxAccel.begin())
{
Serial.println("Could not communicate with the the KX13X. Freezing.");
while (1)
;
}
Serial.println("Ready.");
if (kxAccel.softwareReset())
Serial.println("Reset.");
// Give some time for the accelerometer to reset.
// It needs two, but give it five for good measure.
delay(5);
kxAccel.enableAccel(false);
kxAccel.setRange(SFE_KX132_RANGE16G); // 16g Range
// kxAccel.setRange(SFE_KX134_RANGE16G); // 16g for the KX134
kxAccel.enableDataEngine(); // Enables the bit that indicates data is ready.
// kxAccel.setOutputDataRate(); // Default is 50Hz
kxAccel.enableAccel();
}
void loop() {
//Serial.println("hujuhujuujuh");
//pomiar masy i srodka ciezkosc wykonuje sie do czasu kiedy nie kliknie sie przycisku
float masa=0.0;
bool t=false;
buttonState=0;
//Serial.println("aalala");
while (!t) {
//Serial.println("skdfjh");
lcd.setCursor(0, 0);
float masa1;
masa1=scale1.get_units();
Serial.println("scale1good");
float masa2;
masa2=scale2.get_units();
Serial.println("scale2good");
float masa3;
masa3=scale3.get_units();
Serial.println("scale3good");