Can anyone point me in the direction of virtual pins and how to include in code?
I have just started out and struggling to get to grips with the code.
I have a blynk widget ( gauge) got it all to work by reading A1 ) but I need to scale the reading so I guess I need to read a v pin?
I have looked at multiple examples but as soon as I try to include it wont compile , spent 2 days on this and retrieved the uno out the bin! So not just jumped on here! Guess it needs a virual write somehow.
Truly stuck with a melted head thought I was getting somewhere but now lost the plot.
Can any one give me some pointers?
Thanks in advance
Max
#define BLYNK_USE_DIRECT_CONNECT
// You could use a spare Hardware Serial on boards that have it (like Mega)
#include <SoftwareSerial.h>
SoftwareSerial DebugSerial(2, 3); // RX, TX
#define BLYNK_PRINT Serial
#include <BlynkSimpleSerialBLE.h>
// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = "NX3G-fEjF8pz_YMzwCvq9XOKMlC2Lgj7";
void setup()
{
// Debug console
DebugSerial.begin(9600);
DebugSerial.println("Waiting for connections...");
// Blynk will work through Serial
// Do not read or write this serial manually in your sketch
Serial.begin(9600);
Blynk.begin(Serial, auth);
}
void loop()
{
Have you looked at the Blynk examples such as VirtualPinRead ?
#define BLYNK_PRINT Serial
#include <SPI.h>
#include <Ethernet.h>
#include <BlynkSimpleEthernet.h>
// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = "YourAuthToken";
// This function will be called every time Slider Widget
// in Blynk app writes values to the Virtual Pin V1
BLYNK_WRITE(V1)
{
int pinValue = param.asInt(); // assigning incoming value from pin V1 to a variable
// process received value
}
void setup()
{
// Debug console
Serial.begin(9600);
Blynk.begin(auth);
}
void loop()
{
Blynk.run();
}
Please bear with me this is quite alien to me, last time I did anything like this it was on my zx spectrum!
Thanks for the heads up ive been looking at Paul Mrwhotters vids.
Used code builder for the HM10 didnt think to look for virtual pins.
I have done a script loaded slider onto phone but doesnt work.
At the bottom of my code I have added Serial.Print(Serial.Print"pinValue");
But doesnt print this is because I am already using the Serial for bluetooth?
Uno has only one port.
Am I correct in my thinking?
Thanks for being patient with me
Max
#define BLYNK_USE_DIRECT_CONNECT
// You could use a spare Hardware Serial on boards that have it (like Mega)
#include <SoftwareSerial.h>
SoftwareSerial DebugSerial(2, 3); // RX, TX
#define BLYNK_PRINT DebugSerial
#include <BlynkSimpleSerialBLE.h>
// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = "NX3G-fEjF8pz_YMzwCvq9XOKMlC2Lgj7";
BLYNK_WRITE(V1)
{
int pinValue = param.asInt(); // assigning incoming value from pin V1 to a variable
// process received value
}
void setup()
{
// Debug console
DebugSerial.begin(9600);
DebugSerial.println("Waiting for connections...");
// Blynk will work through Serial
// Do not read or write this serial manually in your sketch
Serial.begin(9600);
Blynk.begin(Serial, auth);
}
void loop()
{
Blynk.run();
Serial.print ("pinValue");
}
Also by putting a Serial.print in your loop Blynk will crash. Read the documentation on Blynk about the importance of keeping the void loop() clean. It is vital to the running of Blynk. Looking at your setup it is not correct. This is what you should have in your setup which is straight from the Blynk sketch builder. Your Serial.println(pinValue); should go into your BLYNK_WRITE(V1) function and NOTE the integer is pinValue NOT "pinValue" - no inverted commas. With inverted commas you are asking to print the word pinValue as opposed to its value.
Ive done it, was so simple I had gone so far down the wrong road making it super complicated in my head.
Thanks for your pointers and help, dont laugh when you see how basic it is, if you knew how long its had taken me!
#define BLYNK_USE_DIRECT_CONNECT
// You could use a spare Hardware Serial on boards that have it (like Mega)
#include <SoftwareSerial.h>
SoftwareSerial DebugSerial(2, 3); // RX, TX
#define BLYNK_PRINT DebugSerial
#include <BlynkSimpleSerialBLE.h>
// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = "NX3G-fEjF8pz_YMzwCvq9XOKMlC2Lgj7";
int myVoltPin=A2; //input voltage
int readVal;
float Volt2; //output voltage or reading.
int myDisplayPin=A3;
void setup() {
// put your setup code here, to run once:
// Debug console
DebugSerial.begin(9600);
DebugSerial.println("Waiting for connections...");
// Blynk will work through Serial
// Do not read or write this serial manually in your sketch
Serial.begin(9600);
Blynk.begin(Serial, auth);
}
void loop() {
// put your main code here, to run repeatedly:
readVal=analogRead(myVoltPin);
Volt2=(readVal-540.)*7;
//analogWrite(A3,Volt2);
Blynk.virtualWrite(V5,Volt2);
Blynk.run();
}
Your void loop is still wrong. You will flood the Blynk server and you will be continously disconnected which makes for an unstable app. I pointed to you to read Blynks documentation on methods and importance on keeping the void loop clean