Difference between revisions of "Blynk"

From Digipool-Wiki
Jump to: navigation, search
(Sparkfun-Blynk-ESP8266 Read Onboard-Button)
Line 2: Line 2:
 
[[File:Blynk-Pinout.jpg|600px]]
 
[[File:Blynk-Pinout.jpg|600px]]
  
== Sparkfun-Blynk-ESP8266 Simple-Setup a New-Board ==
+
== Sparkfun-Blynk-ESP8266 Read Onboard-Button ==
  
Setup
+
Auf dem Sparkfun-Blynk-ESP8266 Board befindet sich ein Taster, der sich gut dazu eignet, um zum Beispiel den aktuellen Zustand einer Tür (Reed-Schalter) in der App sichtbar zu machen. Dieser Taster ist mit '''Pin 0''' verdrahtet und kann ober einen virtuellen Pin gelesen werden.
# Install the Blynk App on your Phone
+
# Creat an Account and log in
+
# Scann the QR-Code
+
# Follow the steps
+
# If the App is connecting to your Blynk board, open WLAN-Setting and select the boards WLAN by hand
+
#
+
  
[https://learn.sparkfun.com/tutorials/getting-started-with-the-sparkfun-blynk-board?_ga=1.196250085.890988720.1429644996 SparkFun-Tutorial]
+
 
 +
'''Onboard-RGB-LED'''
 +
* Board: [https://www.sparkfun.com/products/13794 Sparkfun-Blynk-ESP8266]
 +
* Onboard-Taster an Pin — kann auch über einen externen Taster zischen Pin 0 und GND geschaltet werden
 +
* Example-Code (siehe unten)
 +
* Example-Blynk-App-Settings (siehe unten)
 +
 
 +
 
 +
[[File:Sparkfun-Blynk-ESP8266-LED-Widget-Onboard-Button.jpg|150px]]
 +
[[File:Sparkfun-Blynk-ESP8266-Read-Onboard-Button.jpg|150px]]
 +
 
 +
<pre>
 +
 
 +
// Sparkfun-Blynk-ESP8266 Read Onboard-Button Example
 +
 
 +
/* Comment this out to disable prints and save space */
 +
#define BLYNK_PRINT Serial
 +
 
 +
#include <ESP8266WiFi.h>
 +
#include <BlynkSimpleEsp8266.h>
 +
 
 +
// You should get Auth Token in the Blynk App.
 +
// Go to the Project Settings (nut icon).
 +
char auth[] = "YourAuthToken";
 +
 
 +
// Your WiFi credentials.
 +
// Set password to "" for open networks.
 +
char ssid[] = "YourNetworkName";
 +
char pass[] = "YourPassword";
 +
 
 +
#define ButtonPin 0
 +
 
 +
int prevState = -1;
 +
int currState = -1;
 +
long lastChangeTime = 0;
 +
 
 +
void checkPin()
 +
{
 +
  // Invert state, since button is "Active LOW"
 +
  // int state = !digitalRead(ButtonPin);
 +
  boolean state = !digitalRead(ButtonPin);
 +
 
 +
  // Debounce mechanism
 +
  long t = millis();
 +
  if (state != prevState) {
 +
    lastChangeTime = t;
 +
  }
 +
  if (t - lastChangeTime > 50) {
 +
    if (state != currState) {
 +
      currState = state;
 +
      if (state == 0) {
 +
        Blynk.virtualWrite(V1, 0);
 +
        Serial.println("Button Off");
 +
      }
 +
      if (state == 1) {
 +
        Blynk.virtualWrite(V1, 1023);
 +
        Serial.println("Button On");
 +
      }
 +
    }
 +
  }
 +
  prevState = state;
 +
}
 +
 
 +
void setup()
 +
{
 +
  // Debug console
 +
  Serial.begin(9600);
 +
 
 +
  Blynk.begin(auth, ssid, pass);
 +
 
 +
  // Make ButtonPin default HIGH, and attach INT to our handler
 +
  pinMode(ButtonPin, INPUT_PULLUP);
 +
}
 +
 
 +
void loop()
 +
{
 +
  Blynk.run();
 +
  checkPin();
 +
}
 +
 
 +
</pre>
  
 
<br>
 
<br>
Line 219: Line 293:
 
   Blynk.virtualWrite(V6, tempc);
 
   Blynk.virtualWrite(V6, tempc);
 
}
 
}
</pre>
 
 
<br>
 
 
== Sparkfun-Blynk-ESP8266 Read Onboard-Button ==
 
 
Auf dem Sparkfun-Blynk-ESP8266 Board befindet sich ein Taster, der sich gut dazu eignet, um zum Beispiel den aktuellen Zustand einer Tür (Reed-Schalter) in der App sichtbar zu machen. Dieser Taster ist mit '''Pin 0''' verdrahtet und kann ober einen virtuellen Pin gelesen werden.
 
 
 
'''Onboard-RGB-LED'''
 
* Board: [https://www.sparkfun.com/products/13794 Sparkfun-Blynk-ESP8266]
 
* Onboard-Taster an Pin — kann auch über einen externen Taster zischen Pin 0 und GND geschaltet werden
 
* Example-Code (siehe unten)
 
* Example-Blynk-App-Settings (siehe unten)
 
 
 
[[File:Sparkfun-Blynk-ESP8266-LED-Widget-Onboard-Button.jpg|150px]]
 
[[File:Sparkfun-Blynk-ESP8266-Read-Onboard-Button.jpg|150px]]
 
 
<pre>
 
 
// Sparkfun-Blynk-ESP8266 Read Onboard-Button Example
 
 
/* Comment this out to disable prints and save space */
 
#define BLYNK_PRINT Serial
 
 
#include <ESP8266WiFi.h>
 
#include <BlynkSimpleEsp8266.h>
 
 
// You should get Auth Token in the Blynk App.
 
// Go to the Project Settings (nut icon).
 
char auth[] = "YourAuthToken";
 
 
// Your WiFi credentials.
 
// Set password to "" for open networks.
 
char ssid[] = "YourNetworkName";
 
char pass[] = "YourPassword";
 
 
#define ButtonPin 0
 
 
int prevState = -1;
 
int currState = -1;
 
long lastChangeTime = 0;
 
 
void checkPin()
 
{
 
  // Invert state, since button is "Active LOW"
 
  // int state = !digitalRead(ButtonPin);
 
  boolean state = !digitalRead(ButtonPin);
 
 
  // Debounce mechanism
 
  long t = millis();
 
  if (state != prevState) {
 
    lastChangeTime = t;
 
  }
 
  if (t - lastChangeTime > 50) {
 
    if (state != currState) {
 
      currState = state;
 
      if (state == 0) {
 
        Blynk.virtualWrite(V1, 0);
 
        Serial.println("Button Off");
 
      }
 
      if (state == 1) {
 
        Blynk.virtualWrite(V1, 1023);
 
        Serial.println("Button On");
 
      }
 
    }
 
  }
 
  prevState = state;
 
}
 
 
void setup()
 
{
 
  // Debug console
 
  Serial.begin(9600);
 
 
  Blynk.begin(auth, ssid, pass);
 
 
  // Make ButtonPin default HIGH, and attach INT to our handler
 
  pinMode(ButtonPin, INPUT_PULLUP);
 
}
 
 
void loop()
 
{
 
  Blynk.run();
 
  checkPin();
 
}
 
 
 
</pre>
 
</pre>
  
 
<br>
 
<br>

Revision as of 15:30, 24 January 2021

Blynk-Pinout.jpg

Sparkfun-Blynk-ESP8266 Read Onboard-Button

Auf dem Sparkfun-Blynk-ESP8266 Board befindet sich ein Taster, der sich gut dazu eignet, um zum Beispiel den aktuellen Zustand einer Tür (Reed-Schalter) in der App sichtbar zu machen. Dieser Taster ist mit Pin 0 verdrahtet und kann ober einen virtuellen Pin gelesen werden.


Onboard-RGB-LED

  • Board: Sparkfun-Blynk-ESP8266
  • Onboard-Taster an Pin — kann auch über einen externen Taster zischen Pin 0 und GND geschaltet werden
  • Example-Code (siehe unten)
  • Example-Blynk-App-Settings (siehe unten)


Sparkfun-Blynk-ESP8266-LED-Widget-Onboard-Button.jpg Sparkfun-Blynk-ESP8266-Read-Onboard-Button.jpg


// Sparkfun-Blynk-ESP8266 Read Onboard-Button Example

/* Comment this out to disable prints and save space */
#define BLYNK_PRINT Serial

#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>

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

// Your WiFi credentials.
// Set password to "" for open networks.
char ssid[] = "YourNetworkName";
char pass[] = "YourPassword";

#define ButtonPin 0

int prevState = -1;
int currState = -1;
long lastChangeTime = 0;

void checkPin()
{
  // Invert state, since button is "Active LOW"
  // int state = !digitalRead(ButtonPin);
  boolean state = !digitalRead(ButtonPin);

  // Debounce mechanism
  long t = millis();
  if (state != prevState) {
    lastChangeTime = t;
  }
  if (t - lastChangeTime > 50) {
    if (state != currState) {
      currState = state;
      if (state == 0) {
        Blynk.virtualWrite(V1, 0);
        Serial.println("Button Off");
      }
      if (state == 1) {
        Blynk.virtualWrite(V1, 1023);
        Serial.println("Button On");
      }
    }
  }
  prevState = state;
}

void setup()
{
  // Debug console
  Serial.begin(9600);

  Blynk.begin(auth, ssid, pass);

  // Make ButtonPin default HIGH, and attach INT to our handler
  pinMode(ButtonPin, INPUT_PULLUP);
}

void loop()
{
  Blynk.run();
  checkPin();
}


Sparkfun-Blynk-ESP8266 Onboard-NeoPixel

Auf dem Sparkfun-Blynk-ESP8266 Board befindet sich eine RGB LED, die sich sehr gut dazu eignet, um zum Beispiel einen aktuellen Zustand anzuzeigen. Diese RGB LED vom Type WS2812 ist mit Pin 4 verdrahtet und kann über die Library Adafruit_NeoPixel.h angesteuert werden.


Onboard-RGB-LED


Sparkfun-Blynk-Onboard-NeoPixel-2.jpg Sparkfun-Blynk-Onboard-NeoPixel-1.jpg Sparkfun-Blynk-Onboard-NeoPixel-3.jpg


// Sparkfun-Blynk-ESP8266 Onboard-NeoPixel Example

#define BLYNK_PRINT Serial
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
#include <Adafruit_NeoPixel.h>

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

// Your WiFi credentials.
// Set password to "" for open networks.
char ssid[] = "YourNetworkName";
char pass[] = "YourPassword";

#define PIN 4
int stripR = 0;
int stripG = 0;
int stripB = 0;
int stripL = 0;

Adafruit_NeoPixel strip = Adafruit_NeoPixel(1, PIN, NEO_GRB + NEO_KHZ800);

BLYNK_WRITE(V1)
{
  stripR = param[0].asInt();
  stripG = param[1].asInt();
  stripB = param[2].asInt();
  showRGB();
}

BLYNK_WRITE(V2)
{
  stripL = 255 - param.asInt();
  showRGB();
}

void showRGB() {
  int r = stripR - stripL;
  if (r < 0) r = 0;
  int g = stripG - stripL;
  if (g < 0) g = 0;
  int b = stripB - stripL;
  if (b < 0) b = 0;

  strip.setPixelColor(0, strip.Color(r, g, b));
  strip.show();
}

void setup()
{
  // Debug console
  Serial.begin(9600);
  Blynk.begin(auth, ssid, pass);

  strip.begin();
  strip.show();
}

void loop()
{
  Blynk.run();
}


Sparkfun-Blynk-ESP8266 Onboard-Temp-Humidity

Auf dem Sparkfun-Blynk-ESP8266 Board befindet sich eine Temperatur- und Feuchtigkeitssensor, der sich sehr gut dazu eignet, um zum Beispiel das Raumklima zu erfassen. Diese I2C Sensor vom Type Si7021 ist mit Pin 2 und Pin 14 verdrahtet und kann über die Library SparkFun_Si7021_Breakout_Library.h ausgelesen werden.


Onboard Temperature and Humidity Sensor


Sparkfun-Blynk-ESP8266 Onboard Temperature-Sensor.jpg Sparkfun-Blynk-ESP8266 Onboard Humidity-Sensor.jpg Sparkfun-Blynk-ESP8266 Onboard Temperature-Humidity-Sensor.jpg

// Sparkfun-Blynk-ESP8266_Onboard-TempHumidity_Example

/* Comment this out to disable prints and save space */
#define BLYNK_PRINT Serial

#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
// #include <DHT.h>
#include "SparkFun_Si7021_Breakout_Library.h"
#include <Wire.h>

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

// Your WiFi credentials.
// Set password to "" for open networks.
char ssid[] = "YourNetworkName";
char pass[] = "YourPassword";

float humidity = 0;
float tempf = 0;
float tempc = 0;

//Create Instance of HTU21D or SI7021 temp and humidity sensor and MPL3115A2 barrometric sensor
Weather sensor;

BlynkTimer timer;

// This function sends Arduino's up time every second to Virtual Pin (5).
// In the app, Widget's reading frequency should be set to PUSH. This means
// that you define how often to send data to Blynk App.
void sendSensor()
{
  getWeather();
  printInfo();
  sendValues();
}

void setup()
{
  // Debug console
  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);

  //Initialize the I2C sensors and ping them
  sensor.begin();

  // Setup a function to be called every second
  timer.setInterval(1000L, sendSensor);
}

void loop()
{
  Blynk.run();
  timer.run();
}

//---------------------------------------------------------------
void getWeather()
{
  // Measure Relative Humidity from the HTU21D or Si7021
  humidity = sensor.getRH();

  // Measure Temperature from the HTU21D or Si7021
  // tempf = sensor.getTempF();
  tempc = sensor.getTemp();
  // Temperature is measured every time RH is requested.
  // It is faster, therefore, to read it from previous RH
  // measurement with getTemp() instead with readTemp()
}
//---------------------------------------------------------------
void printInfo()
{
  //This function prints the weather data out to the default Serial Port

  Serial.print("Temp:");
  Serial.print(tempc);
  Serial.print("°C, ");

  Serial.print("Humidity:");
  Serial.print(humidity);
  Serial.println("%");
}

void sendValues() {
  // You can send any value at any time.
  // Please don't send more that 10 values per second.
  Blynk.virtualWrite(V5, humidity);
  Blynk.virtualWrite(V6, tempc);
}