Hello,
I have posted the sketch below to see if someone can spot what I can’t. when uploaded the sketch does not try to connect to wifi, (login data was confirmed to be right as well as network was up.)
So I’m not sure if the serial write command is the issue or if the wifi related code is the issue. Can anyone see anything?
Jim
#define BLYNK_PRINT Serial
#include <Wire.h>
#include <SPI.h>
#include <WiFiNINA.h>
#include <BlynkSimpleWiFiNINA.h>
#include <Adafruit_MCP9808.h>
#include <Adafruit_Si7021.h>
#include "HX711.h"
// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = "cShY4GW_GMJCO0Q8BGYqviAHJt09I5_D";
// Set password to "" for open networks.
char ssid[] = "Skynet van 213";
char pass[] = "quickbanana462";
// How often (in milliseconds) should we take the readings
int reading_frequency = 5000;
#define calibration_factor -4800.0
#define DOUT 2 //#define scale DT (2)
#define CLK 3 //#define scale CL (3)
HX711 scale;
#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;
float weight;
long int loadcell;
long int tare;
// Initialise the Blynk timer object
BlynkTimer timer;
void tcaselect(uint8_t i)
{
if (i > 7) return;
Wire.beginTransmission(TCAADDR);
Wire.write(1 << i);
Wire.endTransmission();
}
void initialise_temp_sensors()
{
// This function is called from void setup and initialises your temperature and weight 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:
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);
scale.begin(DOUT, CLK);
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
}
void take_readings()
{
// This function is called by a timer and takes reading from each sensor nad prints them, as well as sending them to Blynk
// Take temp1 readings...
tcaselect(7);
temperature1 = temp1.readTempF();
Serial.print("temperature1 = ");
Serial.println(temperature1);
Serial.println();
Blynk.virtualWrite(V7, temperature1);
Blynk.run();
// Take temp2 readings...
tcaselect(6);
temperature2 = temp2.readTempF();
Serial.print("temperature2 = ");
Serial.println(temperature2);
Serial.println();
Blynk.virtualWrite(V6, temperature2);
Blynk.run();
// Take temp3 readings...
tcaselect(5);
temperature3 = temp3.readTempF();
Serial.print("temperature3 = ");
Serial.println(temperature3);
Serial.println();
Blynk.virtualWrite(V5, temperature3);
Blynk.run();
// Take hum1 readings...
tcaselect(4);
humidity1 = hum1.readHumidity();
Serial.print("humidity1 = ");
Serial.println(humidity1);
Serial.println();
Blynk.virtualWrite(V4, humidity1);
Blynk.run();
// Take hum2 readings...
tcaselect(3);
humidity2 = hum2.readHumidity();
Serial.print("humidity2 = ");
Serial.println(humidity2);
Serial.println();
Blynk.virtualWrite(V3, humidity2);
// Take weight readings...
weight = scale.get_units();
Serial.print("Scale reading: ");
Serial.print(weight, 1); //scale.get_units() returns a float
Serial.println(" lbs"); //You can change this to kg but you'll need to refactor the calibration_factor
Serial.println();
Blynk.virtualWrite(V2, weight);
}
// standard Arduino setup()
void setup()
{
Wire.begin();
Serial.begin(9600);
initialise_temp_sensors();
Blynk.begin(auth, ssid, pass);
timer.setInterval(reading_frequency, take_readings);
}
void loop()
{
Blynk.run();
timer.run();
}