Sooooo close but no joy with my load cell

So I am about done with this project, had some help on some stuff got the bulk of it my self but can’t solve this bit. I’m running 3 temp sensors and 2 humidity sensors thru a multiplexer and my MKR1010. All runs great, the issue I have is that the load cell is not. I know the cell is good as is the amp as I could do the calibration and run a simple load cell sample sketch. However back to my sketch i have no data running to my phone. I would greatly appreciate if someone could see if something jumps out at you.

Jim

#define BLYNK_PRINT Serial
#include <Wire.h>


#include <SPI.h>
#include <WiFiNINA.h>
#include <BlynkSimpleWiFiNINA.h>


//#include <BlynkSimpleWiFiShield101.h>
#include <Adafruit_MCP9808.h>
#include <Adafruit_Si7021.h>
#include <Q2HX711.h>


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

// Set password to "" for open networks.
char ssid[] = "Skynet";
char pass[] = "*****************";

#define calibration_factor -3750.0 

//#define scale DT (3)
//#define scale CL (2)

#define SCALE_DATA_PIN  3
#define SCALE_CLOCK_PIN  2

Q2HX711 scale(SCALE_DATA_PIN,SCALE_CLOCK_PIN);






#define TCAADDR 0x70

#define TCAADDR       0x70
#define TEMP1_ADDR    0x18
#define TEMP2_ADDR    0x18
#define TEMP3_ADDR    0x18
#define HUM1_ADDR     0x40
#define HUM2_ADDR     0x40


// Assign unique ID to each sensor
Adafruit_MCP9808 temp1 = Adafruit_MCP9808();
Adafruit_MCP9808 temp2 = Adafruit_MCP9808();
Adafruit_MCP9808 temp3 = Adafruit_MCP9808();
Adafruit_Si7021 hum1 = Adafruit_Si7021();
Adafruit_Si7021 hum2 = Adafruit_Si7021();
//HS711 scale1 = HS711(6)

float temperature1;
float temperature2;
float temperature3;

float humidity1;
float humidity2;

long int loadcell;
long int tare;

void tcaselect(uint8_t i) {
  if (i > 7) return;

  Wire.beginTransmission(TCAADDR);
  Wire.write(1 << i);
  Wire.endTransmission();
}

// standard Arduino setup()
void setup()
{
  Wire.begin();
  Serial.begin(9600);

  Blynk.begin(auth, ssid, pass);
  // You can also specify server:
  //Blynk.begin(auth, ssid, pass, "blynk-cloud.com", 80);
  //Blynk.begin(auth, ssid, pass, IPAddress(192,168,1,100), 8080);


  //these functions do not exist. you need to implement in firmware.
  //scale.set_scale(calibration_factor); //This value is obtained by using the SparkFun_HX711_Calibration sketch
  //scale.tare(); //Assuming there is no weight on the scale at start up, reset the scale to 0

  /////

//setup temp sensors:
tcaselect(7);
  if (!temp1.begin(0x18)) {
    Serial.println("Couldn't find Temp1! Check your connections and verify the address is correct.");
    while (1);
  }

   Serial.println("Found MCP9808, Sensor 1!");

  temp1.setResolution(0); // sets the resolution mode of reading, the modes are defined in the table bellow:
  // Mode Resolution SampleTime
  //  0    0.5°C       30 ms
  //  1    0.25°C      65 ms
  //  2    0.125°C     130 ms
  //  3    0.0625°C    250 ms

tcaselect(6);
  if (!temp2.begin(0x18)) {
    Serial.println("Couldn't find Temp2! Check your connections and verify the address is correct.");
    while (1);
  }

   Serial.println("Found MCP9808, Sensor 2!");

  temp2.setResolution(0); 


tcaselect(5);
  if (!temp3.begin(0x18)) {
    Serial.println("Couldn't find Temp3! Check your connections and verify the address is correct.");
    while (1);
  }

     Serial.println("Found MCP9808, Sensor 2!");

  temp3.setResolution(0); 


}

void loop(void) 
{
  
  tcaselect(7);
  //temp1.getEvent(&event);
  temperature1=temp1.readTempF();
  //Display the results
  Blynk.virtualWrite(V7,temperature1); 

  tcaselect(6);
  //temp2.getEvent(&event);
  temperature2=temp2.readTempF();
  Blynk.virtualWrite(V6,temperature2); 

  tcaselect(5);
  //temp3.getEvent(&event);
  temperature3=temp3.readTempF();
  Blynk.virtualWrite(V5,temperature3);

  tcaselect(4);
  //hum4.getEvent(&event);
  humidity1=hum1.readHumidity();
  Blynk.virtualWrite(V4,humidity1);

  tcaselect(3);
  //hum5.getEvent(&event);
  humidity2=hum2.readHumidity();
  Blynk.virtualWrite(V3,humidity2);

  Blynk.virtualWrite(V2, 3);

      Blynk.run();   


    }

All those Blynk.virtualWrite() commands in the void loop scream… “NOOOO!!, Too Much Too Fast” (that and everything else - calling a function from the main loop is the same as running all the commands IN the main loop)

http://help.blynk.cc/en/articles/2091699-keep-your-void-loop-clean

PS, I don’t see any (active) load cell commands/processing in your code??

GTT,

I appreciate the feedback… What is the down side to the Blynk.virtualWrite() commands? The sensors are running fine right now have been for the last 5 days with no issues. Can you be more specific as to why this is bad? Also I thought I had all the required load cell stuff, what did I miss? Can you point me to a good sample sketch that might help?

Jim

It is all in that link I provided above.

Normally the void loop() runs thousands of times a second (really… who needs to see the temp update that fast :stuck_out_tongue: )

What is actually happening in your case is that in order to prevent automatic disconnections from flooding the server, Blynk is initiating an anti-flooding… err… “feature” that (in my tests) drastically slows down the void loop()… to the detriment of any real code that needs it to run fast.

There is a “bypass” command, for use on Local Servers (follow the green link above)… but the end result of your code is the same, bad programming procedures for Blynk usage.

You set up all these variables… but then never use them in any active code that I noticed.

So what you are saying is that because my sensor code is sending so much data the “system” is not letting the load cell data through?

Basically I was saying you have a ways to go for a proper Blynk based sketch… but most of that info is available in the link I provided.

As for the load cell, well I suggest you look over your code again, perhaps I missed something as I was just glancing by.

@Gunner is correct. Your code defines the “scale” object, but you have no code to read the values from the scale.

You need to read, and more importantly, understand the “keep your void loop clean” document. You then need to set-up a timer to take readings from your sensors, including the scale, at a sensible frequency.

Pete.

Ok Pete,

Can you point me to a example sketch that has timer in it so I can see one. I learn this stuff better that way

Jim

What’s wrong with the example in the “keep your void loop clean” link that @Gunner shared?

Pete.

I’m just looking for help here, I’m new to this. Coding is not something that come natural to me. I think I’m asking clear concise questions but if I’m not the flippant responses such as “what’s wrong with the” does ne no good. I have tried over and over in this forum to get guidance but mostly just get told how poorly I program. I guess I am just looking for help in the wrong location.

If you look back over this topic you’ll see that you were pointed in the direction of the extremely informative “keep your void loop clean” article in post number 2. But, at no point have you acknowledged the content of that article or asked any questions about its content.
In fact, all of your comments point to you not actually having read (or at least understood) it’s content - go back and re-read them if you disagree.

I could have pointed you to other examples, but this would merely have muddied the waters, as it would have given examples of how timers are used for different purposes and would have made it more difficult for you to grasp and execute the basic concept of moving your code out of the void loop and into a function which is called with a timer.

The answer from me is exactly the same as I said before - read and understand the article and use the information contained in it to amend your code structure.
If you don’t understand some aspects of the article then ask specific questions about what it means, and post your ‘best shot’ at modifying your code.

Pete.

1 Like