Hi all
I’ve been trying to adapt some sketches to use Blynk stubbornly for may sleepless nights.
I’ve read a lot and found most of the answers (that lead to more reading and a lot more questions) but this has me totally stumped.
Using my nodeMCU if I upload the Blynk example “Hello World” everything works perfect. If I add an input pinmode the serial monitor (9600baud) just displays garbled symbols (?)5⸮1⸮D⸮) while the on board led flashes ever 5s or so or if it manages to bootup it disconnects every 10s.
here is the sketch
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
char auth[] = "xxxxxxxxxxxxxxx";
char ssid[] = "xxxxxxxxxx";
char pass[] = "xxxxxxxxxxxxx";
// Your WiFi credentials.
// Set password to "" for open networks.
WidgetLCD lcd(V1);
#define beta 4090 // from your thermistor's datasheet
#define resistance 33
int ledPin = 15;
int relayPin = 16;
int aPin = 8;
int bPin = 7;
int buttonPin = 6;
int analogPin = 0;
void setup()
{
pinMode(ledPin, OUTPUT);
pinMode(relayPin, OUTPUT);
pinMode(aPin, INPUT);
pinMode(bPin, INPUT);
pinMode(buttonPin, INPUT);
// Debug console
Serial.begin(9600);
Blynk.begin(auth, ssid, pass);
lcd.clear(); //Use it to clear the LCD Widget
lcd.print(0, 0, "Hello"); // use: (position X: 0-15, position Y: 0-1, "Message you want to print")
lcd.print(12, 0, "World");
}
void loop()
{
Blynk.run();
}
void loop()
If I comment out the
{
pinMode(ledPin, OUTPUT);
pinMode(relayPin, OUTPUT);
//pinMode(aPin, INPUT);
//pinMode(bPin, INPUT);
//pinMode(buttonPin, INPUT);
// Debug console
Serial.begin(9600);
Blynk.begin(auth, ssid, pass);
It works??
Im trying to create a virtual Blynk version of this sketch, I was going to gut the hardware code so I may not need the pinMode(xxx, INPUT); section but it would be better if I could just mirror the hardware in Blynk. I read that I would need to move everything out of the void loop() for it to work with blynk, this sounds like a deal breaker for my coding experience.
#include <LiquidCrystal.h>
#define beta 4090 // from your thermistor's datasheet
#define resistance 33
// LiquidCrystal display with:
// rs on pin 12
// rw on pin 11
// enable on pin 10
// d4-7 on pins 5-2
LiquidCrystal lcd(12, 11, 10, 5, 4, 3, 2);
int ledPin = 15;
int relayPin = 16;
int aPin = 8;
int bPin = 7;
int buttonPin = 6;
int analogPin = 0;
float setTemp = 20.0;
float measuredTemp;
char mode = 'C';
boolean override = false;
float hysteresis = 0.25;
void setup()
{
lcd.begin(2, 20);
pinMode(ledPin, OUTPUT);
pinMode(relayPin, OUTPUT);
pinMode(aPin, INPUT);
pinMode(bPin, INPUT);
pinMode(buttonPin, INPUT);
lcd.clear();
}
void loop()
{
static int count = 0;
measuredTemp = readTemp();
if (digitalRead(buttonPin))
{
override = ! override;
updateDisplay();
delay(500); // debounce
}
int change = getEncoderTurn();
setTemp = setTemp + change * 0.1;
if (count == 1000)
{
updateDisplay();
updateOutputs();
count = 0;
}
count ++;
}
int getEncoderTurn()
{
// return -1, 0, or +1
static int oldA = LOW;
static int oldB = LOW;
int result = 0;
int newA = digitalRead(aPin);
int newB = digitalRead(bPin);
if (newA != oldA || newB != oldB)
{
// something has changed
if (oldA == LOW && newA == HIGH)
{
result = -(oldB * 2 - 1);
}
}
oldA = newA;
oldB = newB;
return result;
}
float readTemp()
{
long a = analogRead(analogPin);
float temp = beta / (log(((1025.0 * resistance / a) - 33.0) / 33.0) +
(beta / 298.0)) - 273.0;
return temp;
}
void updateOutputs()
{
if (override || measuredTemp < setTemp - hysteresis)
{
digitalWrite(ledPin, HIGH);
digitalWrite(relayPin, HIGH);
}
else if (!override && measuredTemp > setTemp + hysteresis)
{
digitalWrite(ledPin, LOW);
digitalWrite(relayPin, LOW);
}
}
void updateDisplay()
{
lcd.setCursor(0,0);
lcd.print("Actual: ");
lcd.print(adjustUnits(measuredTemp));
lcd.print(" o");
lcd.print(mode);
lcd.print(" ");
lcd.setCursor(0,1);
if (override)
{
lcd.print(" OVERRIDE ON ");
}
else
{
lcd.print("Set: ");
lcd.print(adjustUnits(setTemp));
lcd.print(" o");
lcd.print(mode);
lcd.print(" ");
}
}
float adjustUnits(float temp)
{
if (mode == 'C')
{
return temp;
}
else
{
return (temp * 9) / 5 + 32;
}
}
Any help would save at least some of my hair.