久しぶりにBlynkをいじってみました。
今回は巷で大モテの ESP8266 をターゲットボードとして使いました。
前回Blynkの記事を書いたときは対応しているボードが少なかったのですが現在はずいぶん増えています。
まず、スマホのアプリ作成ですが、
これは単にプロジェクトの作成時にターゲットボードに
「ESP8266」を選択するだけです。
今回は1個のSWと1個のLEDを接続しているだけなので操作画面は
以下のようにいたってシンプルです。
次にArduino IDEでESP8266のスケッチを作成してターゲットボードに書き込みます。
スケッチはBlynkのサンプルに含まれている
「ESP8266_Standalone」を使います。
(BlynkのライブラリーをArduino IDEに取り込んでおく必要があります。)
ssid、password、authはご自身の環境に合わせてください。
GPIO16に接続したSWの入力でスマホのLED表示を変化させているで
GPIOの入力をBlynkのバーチャル入力へ変換する処理を入れています。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 | /************************************************************** * Blynk is a platform with iOS and Android apps to control * Arduino, Raspberry Pi and the likes over the Internet. * You can easily build graphic interfaces for all your * projects by simply dragging and dropping widgets. * * Downloads, docs, tutorials: http://www.blynk.cc * Blynk community: http://community.blynk.cc * Social networks: http://www.fb.com/blynkapp * http://twitter.com/blynk_app * * Blynk library is licensed under MIT license * This example code is in public domain. * ************************************************************** * This example runs directly on ESP8266 chip. * * You need to install this for ESP8266 development: * https://github.com/esp8266/Arduino * * Change WiFi ssid, pass, and Blynk auth token to run :) * **************************************************************/ #define BLYNK_PRINT Serial // Comment this out to disable prints and save space #include <ESP8266WiFi.h> #include <BlynkSimpleEsp8266.h> const char ssid[] = "lo--------87"; const char password[] = "12----------4"; // You should get Auth Token in the Blynk App. // Go to the Project Settings (nut icon). char auth[] = "56----------------------------3d"; int in_data = 0; void setup() { Serial.begin(9600); Blynk.begin(auth, ssid, password); } void loop() { Blynk.run(); in_data = digitalRead(16) * 255 ; Blynk.virtualWrite(1, in_data); } |