olkal / HX711_ADC

Arduino library for the HX711 24-bit ADC for weight scales
MIT License
236 stars 125 forks source link

HX711 with Blynk #78

Closed papaduane closed 3 years ago

papaduane commented 3 years ago

When I add //HX711 constructor (dout pin, sck pin) HX711_ADC LoadCell_1(HX711_dout_1, HX711_sck_1); //HX711 1 HX711_ADC LoadCell_2(HX711_dout_2, HX711_sck_2); //HX711 2 HX711_ADC LoadCell_3(HX711_dout_3, HX711_sck_1); //HX711 1 HX711_ADC LoadCell_4(HX711_dout_4, HX711_sck_2); //HX711 2

Blynk fails to start correctly


With out it

start ing v print1 blynk start 2 [19]


/ )/ / _ / /_ / / / // / \/ '/ ///_, /////_\ /___/ v1.0.0 on Arduino Nano

[626] Connecting to House [3813] AT version:1.1.0.0(May 11 2016 18:09:56) SDK version:1.5.4(baaeaebb) compile time:May 20 2016 15:08:19 OK [9097] +CIFSR:STAIP,"192.168.4.116" +CIFSR:STAMAC,"c4:5b:be:4d:55:c1" [9105] Connected to WiFi [19538] Ready (ping: 38ms). blynk end 2 BOOT_MESSAGE Blynkstart blynk end Blynkstart blynk end


with it in

start ing v print1 blynk start 2 [19]


/ )/ / _ / /_ / / / // / \/ '/ ///_, /////_\ /___/ v1.0.0 on Arduino Nano

[626] Connecting to House [3813] AT version:1.1.0.0(May 11 2016 18:09:56) SDK version:1.5.4(baaeaebb) compile time:May 20 2016 15:08:19 OK [4891] Failed to enable MUX [14089] +CIFSR:STAIP,"192.168.4.116" +CIFSR:STAMAC,"c4:5b:be:4d:55:c1" [14098] Connected to WiFi [24506] Ready (ping: 25ms). [50309] Ready (ping: 23ms). [76317] Ready (ping: 24ms). [102120] Ready (ping: 26ms). [127938] Ready (ping: 26ms). [153801] Ready (ping: 36ms). [179592] Ready (ping: 25ms). [205393] Ready (ping: 24ms).

// added

// Comment this out to disable prints and save space

define BLYNK_PRINT Serial

// Fill-in your Template ID (only if using Blynk.Cloud) //#define BLYNK_TEMPLATE_ID "YourTemplateID"

include

include

include

include

// #include

include

//#include

// You should get Auth Token in the Blynk App. // Go to the Project Settings (nut icon). char auth[] = "QiFv3yCxMWkTIABGLMEnC-zIwQScPRdZ";

// Your WiFi credentials. // Set password to "" for open networks. char ssid[] = "House"; char pass[] = "5072886248";

// Hardware Serial on Mega, Leonardo, Micro... // #define EspSerial Serial1

// or Software Serial on Uno, Nano...

include

SoftwareSerial EspSerial(2, 3); // RX, TX

// Your ESP8266 baud rate:

define ESP8266_BAUD 9600

ESP8266 wifi(&EspSerial);

WidgetTerminal terminal(V3);

// HX711_ADC scale_1; // HX711_ADC scale_2; // HX711_ADC scale_3; // HX711_ADC scale_4;

// ------------------------------------

// HX711 circuit wiring const int LOADCELL_DOUT_PIN_1 = 4; const int LOADCELL_SCK_PIN_1 = 5; const int LOADCELL_DOUT_PIN_2 = 6; const int LOADCELL_SCK_PIN_2 = 7; const int LOADCELL_DOUT_PIN_3 = 8; const int LOADCELL_SCK_PIN_3 = 9; const int LOADCELL_DOUT_PIN_4 = 10; const int LOADCELL_SCK_PIN_4 = 11;

const int HX711_dout_1 = 4; //mcu > HX711 no 1 dout pin const int HX711_sck_1 = 5; //mcu > HX711 no 1 sck pin const int HX711_dout_2 = 6; //mcu > HX711 no 2 dout pin const int HX711_sck_2 = 7; //mcu > HX711 no 2 sck pin const int HX711_dout_3 = 8; //mcu > HX711 no 1 dout pin const int HX711_sck_3 = 9; //mcu > HX711 no 1 sck pin const int HX711_dout_4 = 10; //mcu > HX711 no 2 dout pin const int HX711_sck_4 = 11; //mcu > HX711 no 2 sck pin

/*

//HX711 constructor (dout pin, sck pin) HX711_ADC LoadCell_1(HX711_dout_1, HX711_sck_1); //HX711 1 HX711_ADC LoadCell_2(HX711_dout_2, HX711_sck_2); //HX711 2 HX711_ADC LoadCell_3(HX711_dout_3, HX711_sck_1); //HX711 1 HX711_ADC LoadCell_4(HX711_dout_4, HX711_sck_2); //HX711 2 */

/* const int calVal_eepromAdress = 0; unsigned long t = 0;

define lcdAddress 0x3f // LCD I2C Address

int count = 0; // Variable to hold current count value

// LiquidCrystal_I2C lcd( lcdAddress ); // Create instance of LiquidCrystal_I2C and set the LCD I2C address

*/

void setup() {

// Debug console Serial.begin(9600); Serial.println("start ing v print1"); delay(10);

// Set ESP8266 baud rate EspSerial.begin(ESP8266_BAUD); delay(10); Serial.println("blynk start 2"); Blynk.begin(auth, wifi, ssid, pass); Serial.println("blynk end 2");

/*

scale_1.begin(LOADCELL_DOUT_PIN_1, LOADCELL_SCK_PIN_1); scale_2.begin(LOADCELL_DOUT_PIN_2, LOADCELL_SCK_PIN_2); scale_3.begin(LOADCELL_DOUT_PIN_3, LOADCELL_SCK_PIN_3); scale_4.begin(LOADCELL_DOUT_PIN_4, LOADCELL_SCK_PIN_4); */

float calibrationValue_1; // calibration value load cell 1 float calibrationValue_2; // calibration value load cell 2 float calibrationValue_3; // calibration value load cell 3 float calibrationValue_4; // calibration value load cell 4

float offsetValue_1; // offset value load cell 1 float offsetValue_2; // offset value load cell 2 float offsetValue_3; // offset value load cell 3 float offsetValue_4; // offset value load cell 4

calibrationValue_1 = 9600.31; // uncomment this if you want to set this value in the sketch calibrationValue_2 = 9294; // uncomment this if you want to set this value in the sketch calibrationValue_3 = 8586.75; // uncomment this if you want to set this value in the sketch calibrationValue_4 = 9446.01; // uncomment this if you want to set this value in the sketch

offsetValue_1 = 8491529; // offset value load cell 1 offsetValue_2 = 8400255; // offset value load cell 2 offsetValue_3 = 8772830; // offset value load cell 3 offsetValue_4 = 8719916; // offset value load cell 4

/*

// LoadCell_1.set_offset(0); //zero out offset // LoadCell_2.set_offset(0); //zero out offset // LoadCell_3.set_offset(0); //zero out offset // LoadCell_4.set_offset(0); //zero out offset

scale_1.set_scale(calibrationValue_1); scale_2.set_scale(calibrationValue_2); scale_3.set_scale(calibrationValue_3); scale_4.set_scale(calibrationValue_4);

LoadCell_1.setCalFactor(calibrationValue_1); // user set calibration value (float) LoadCell_2.setCalFactor(calibrationValue_2); // user set calibration value (float) LoadCell_1.setCalFactor(calibrationValue_3); // user set calibration value (float) LoadCell_2.setCalFactor(calibrationValue_4); // user set calibration value (float)

/*scale_1.tare(0); scale_2.tare(0); scale_3.tare(0); scale_4.tare(0);

LoadCell_1.setTareOffset(offsetValue_1); //set offset LoadCell_2.setTareOffset(offsetValue_2); //set offset LoadCell_3.setTareOffset(offsetValue_3); //set offset LoadCell_4.setTareOffset(offsetValue_4); //set offset

/* { // Serial.begin(9600); delay(10); // Serial.println(); // Serial.println("Starting...");

//================= LoadCell.begin(); float calibrationValue; // calibration value (see example file "Calibration.ino") calibrationValue = 696.0; // uncomment this if you want to set the calibration value in the sketch

if defined(ESP8266)|| defined(ESP32)

//EEPROM.begin(512); // uncomment this if you use ESP8266/ESP32 and want to fetch the calibration value from eeprom

endif

//EEPROM.get(calVal_eepromAdress, calibrationValue); // uncomment this if you want to fetch the calibration value from eeprom

unsigned long stabilizingtime = 2000; // preciscion right after power-up can be improved by adding a few seconds of stabilizing time boolean _tare = true; //set this to false if you don't want tare to be performed in the next step LoadCell.start(stabilizingtime, _tare); if (LoadCell.getTareTimeoutFlag()) { Serial.println("Timeout, check MCU>HX711 wiring and pin designations"); while (1); } else { LoadCell.setCalFactor(calibrationValue); // set calibration value (float) Serial.println("Startup is complete");

}*/

Serial.begin(9600); Serial.println("BOOT_MESSAGE"); Serial.flush(); pinMode(11,OUTPUT);

// tare();

} /* void tare() { //===========================================

bool tareSuccessful = false;

unsigned long tareStartTime = millis(); while (!tareSuccessful && millis()<(tareStartTime+TARE_TIMEOUT_SECONDS*1000)) { tareSuccessful = scales.tare(20,10000); //reject 'tare' if still ringing } }

void sendRawData() { scales.read(results); for (int i=0; i<scales.get_count(); ++i) {; Serial.print( -results[i]);
Serial.print( (i!=scales.get_count()-1)?"\t":"\n"); }
delay(1000); }

*/

void loop() {

// Blynk.run();

// Blynk.virtualWrite(V5, "hello world"); // terminal.println("jjjj");

/*

static boolean newDataReady = 0; const int serialPrintInterval = 0; //increase value to slow down serial print activity

// check for new data/start next conversion: //if (LoadCell.update()) newDataReady = true;

// get smoothed value from the dataset: // if (newDataReady) { if (millis() > t + serialPrintInterval)
{ // float i = LoadCell.getData(); Serial.print("Load_cell output val: "); // Serial.println(i); newDataReady = 0; t = millis(); } */ // --------------------added Serial.println("Blynkstart");

Blynk.run(); Serial.println("blynk end");

delay(2000); } /*

Serial.print("one reading:\t"); Serial.print(LoadCell_1.getData(), 1); Serial.print("\t| average:\t"); // Serial.println(scale_1.get_units(10), 1);

Serial.print("one reading:\t"); Serial.print(scale_2.get_units(), 1); Serial.print("\t| average:\t"); //Serial.println(scale_2.get_units(10), 1);

Serial.print("one reading:\t"); Serial.print(scale_3.get_units(), 1); Serial.print("\t| average:\t"); //Serial.println(scale_3.get_units(10), 1);

Serial.print("one reading:\t"); Serial.print(scale_4.get_units(), 1); Serial.print("\t| average:\t"); //Serial.println(scale_4.get_units(10), 1);

//get smoothed value from data set if ((newDataReady)) { if (millis() > t + serialPrintInterval) { float Hive_1 = LoadCell_1.getData(); float Hive_2 = LoadCell_2.getData(); float Hive_3 = LoadCell_3.getData(); float Hive_4 = LoadCell_4.getData();

float offsetValue_1; offsetValue_1 = 8491529; Serial.println(Hive_1); Serial.println(Hive_2); terminal.println(offsetValue_1);

 Blynk.virtualWrite(V5,Hive_1);

// Blynk.virtualWrite(V5,scale_2.get_scale());

// }

// } // terminal.println("Scale 1"); // terminal.println(a);

// Serial.println("starting v print12"); // Serial.println(a);

// Blynk.virtualWrite(V5, "hello world");

// Blynk.virtualWrite(V5,a);

terminal.println("iii");

// terminal.println(LoadCell.getData());

terminal.println("jjjj");

terminal.println("DOUT2"); Blynk.virtualWrite(V6, "DOUT2"); terminal.println("DOUT3"); Blynk.virtualWrite(V7," DOUT3");

Serial.println("starting v print c");

delay(1000);

} */

Sorry for all the extra lines

olkal commented 3 years ago

Hi! First a tip on posting code; if you insert the code using the <> button it's easier to read. Then your issue: You can't use pin number 6-11 on the ESP8266, these are already in use by the SPI Flash memory. It looks like you don't have enough available pins for your project with the ESP8266, you might be better off using the ESP32 .

papaduane commented 3 years ago

Will do. I am using the ardunio nano with a esp 01 with the “at” code

Sent from my iPhone

On Jul 20, 2021, at 11:35 AM, Olav Kallhovd @.***> wrote:

 Hi! First a tip on posting code; if you insert the code using the <> button it's easier to read. Then your issue: You can't use pin number 6-11 on the ESP8266, these are already in use by the SPI Flash memory. It looks like you don't have enough available pins for your project with the ESP8266, you might be better off using the ESP32 .

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub, or unsubscribe.

olkal commented 3 years ago

Oh, I didn't get that you are running the code on a Nano, sorry. The error code that you get seems to be wifi related, but I'm not familar with Blynk or running the ESP8266 via AT code tough. However, I can't see any reason why including the HX711 constructors in it self should cause this, it's different pins and there are no interrupts involved. You have used the same SCK pins (1 & 2) for HX711 no 1, 2, 3 and 4, but again, this will not make any errors on the ESP8266 side.

olkal commented 3 years ago

I’m closing this issue because it has been inactive for some time. Please reopen if you still encounter this issue with the latest version. Thank you!