Hi all, I am very new to this.
I have written some code basically by trial and error and have got it to work and send data to my phone app, however it disconnects on a regular basis and I know its my poor coding.
I learn quicker by seeing how something is done / written.
Would it be possible for someone to show me how my code should be written rather than the way I have written it?
#include "DHT.h"
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
#include <SimpleTimer.h>
#include <OLEDDisplay.h>
#include <OLEDDisplayFonts.h>
#include <OLEDDisplayUi.h>
#include <SH1106.h>
#include <SH1106Wire.h>
#include <SSD1306.h>
#include <SSD1306Spi.h>
#include <SSD1306Wire.h>
#include "HX711.h"
#define DOUT D6
#define CLK D5
#define BLYNK_PRINT Serial
#define DHTPIN D4 // what pin we're connected to
#define DHTTYPE DHT11 // DHT 11
DHT dht(DHTPIN, DHTTYPE);
SimpleTimer timer;
int tempSet;
int tempHigh;
int tempValue;
int humidValue;
int readTemp;
//int checkTemp;
int readHumid;
// Display Settings
const int I2C_DISPLAY_ADDRESS = 0x3c;
const int SDA_PIN = D2;
const int SDC_PIN = D3;
HX711 scale(DOUT, CLK);
float calibration_factor = 104050;
// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = "";
// Your WiFi credentials.
// Set password to "" for open networks.
char ssid[] = "Linksys00772";
char pass[] = "";
SSD1306Wire display(I2C_DISPLAY_ADDRESS, SDA_PIN, SDC_PIN);
void setup()
{
Serial.begin(9600);
Blynk.begin(auth, ssid, pass, "blynk-cloud.com", 8442);
display.init();
display.flipScreenVertically();
// Setup a function to be called every second
// timer.setInterval(1000L, sendUptime);
scale.set_scale();
scale.tare(); //Reset the scale to 0
long zero_factor = scale.read_average(); //Get a baseline reading
//BLYNK_WRITE(V8){
// int pinData = param.asInt(); //pinData variable will store value that came via Bridge
//}
}
void loop()
{
scale.set_scale(calibration_factor); //Adjust to this calibration factor
readHumid = (dht.readHumidity()+ 30);
readTemp = (dht.readTemperature()- 12);
Blynk.virtualWrite(2, readTemp);
Blynk.virtualWrite(3, readHumid);
// Blynk.run();
int c = (char)233;
float kegRead = scale.get_units();
String kegDisplay;
kegDisplay = String(kegRead);
float tempRead = readTemp;
String tempDisplay;
tempDisplay = String(tempRead);
Blynk.virtualWrite(6, kegDisplay);
display.setFont(ArialMT_Plain_24);
display.setTextAlignment(TEXT_ALIGN_LEFT);
display.clear();
display.drawString(0, 0, "Temp:");
display.drawString(70, 0, tempDisplay);
display.drawString(50, 35, kegDisplay);
display.drawString(110, 35, "L");
display.drawString(0, 35, "Keg:");
Serial.print("Reading: ");
Serial.print(scale.get_units(),0);
Serial.print(" KG");
Serial.println();
display.display();
Blynk.run();
delay(1000);
}