Relative Content

Monthly Archives: October 2017

WeMos (c4) JSON

WeMosをRESPのクライアントとして機能するため、JSONと、HTTPClientを検証する。 ライブラリの追加 JSONを扱うライブラリに「ArduinoJSON」というのがあるので、ライブラリの追加で、リストが出てくるので、JSONと入力し絞込。 (2018/7現在、5.x と6.x が共存して、6.xはまたベター版のため、エラーが発生する。5.xを利用する) ArduinoJSONの動作、JsonBuffer size、Parsing program、Serializing programは、下記のURLで確認しながら進める方が便利でしょう。 https://bblanchon.github.io/ArduinoJson/assistant/ 動作確認 公式のサンプルJsonParserExampleをそのまんま。 // Copyright Benoit Blanchon 2014-2017 // MIT License // // Arduino JSON library // https://bblanchon.github.io/ArduinoJson/ // If you like this project, please add a star! #include <ArduinoJson.h> void setup() { Serial.begin(9600); while (!Serial) { // wait serial port initialization } // Memory […]

WeMos (c3) Home IoT Server

いよいよWiFiManagerを組み込み、理想のIoT-Cloud-Mobile Study Kit (IoT実験キット)の形ができた。 今回の実験はWeMosにhttpサーバを立ち上げて、ブラウザーから接続 を待機;接続するとBMP280センサー情報を返送する。 つまり、スマートフォンまたはPCから直接接続して利用する。この場合ローカル環境の利用に限られ、出かける時でも利用するため、クラウド(例えばTinyWebDB API)が必要だ。 WiFiManagerを組み込みだ、Home IoT Server。 /* * */ #include <Wire.h> #include <Adafruit_BMP280.h> #include <Adafruit_GFX.h> #include <Adafruit_SSD1306.h> #define OLED_RESET 0 // GPIO0 Adafruit_SSD1306 OLED(OLED_RESET); #define BMP_SCK 13 #define BMP_MISO 12 #define BMP_MOSI 11 #define BMP_CS 10 Adafruit_BMP280 bmp; // I2C //Adafruit_BMP280 bmp(BMP_CS); // hardware SPI //Adafruit_BMP280 bmp(BMP_CS, BMP_MOSI, BMP_MISO, BMP_SCK); […]

WeMos (8) MAX7219-LED-4x8x8-Matrix

4連装8×8 LEDは数ヶ月前購入したが、発表用タイマーを作りたい。 まず点灯テストから。 googleでなかなかいい事例が見つからないので、githubで検索してみたら、すぐ見つかった。 https://github.com/G6EJD/ESP8266-MAX7219-LED-4x8x8-Matrix-Clock   #include <SPI.h> #include <Adafruit_GFX.h> #include <Max72xxPanel.h> #include <time.h> int pinCS = D4; // Attach CS to this pin, DIN to MOSI and CLK to SCK (cf http://arduino.cc/en/Reference/SPI ) int numberOfHorizontalDisplays = 4; int numberOfVerticalDisplays = 1; char time_value[20]; // LED Matrix Pin -> ESP8266 Pin // Vcc -> 3v […]

WeMos (c2) WiFiManager

WeMos のWiFiが、前回のようにSSIDとPASSWORDをコードに書き込む方法の他に、オンライン変更できるような方法もある。 WiFiManager というライブラリを使うと簡単にできる https://github.com/tzapu/WiFiManager このソースを参考に試してみる。 まず、ライブラリマネージャーから、WiFiManagerを検索して、インストールする。 ライブラリを使える状態にすると,下記のサンプルで、接続するだけで上のユースケースが満たされて大変便利だ…。標準でWebUIもついてる。 #include <ESP8266WiFi.h> //https://github.com/esp8266/Arduino //needed for library #include <DNSServer.h> #include <ESP8266WebServer.h> #include “WiFiManager.h” //https://github.com/tzapu/WiFiManager void configModeCallback (WiFiManager *myWiFiManager) { Serial.println(“Entered config mode”); Serial.println(WiFi.softAPIP()); //if you used auto generated SSID, print it Serial.println(myWiFiManager->getConfigPortalSSID()); } void setup() { // put your setup code here, to run once: Serial.begin(115200); //WiFiManager //Local intialization. […]

WeMos (c1) Web on WiFi

いよいよ内蔵WiFiを活用する時期が来た! 前回のセンサー情報をWebからでも見れるようにする。 処理の流れ setup() { WiFi初期化 Web初期化 センサー初期化 } loop() { If (Webからリクエスト) .1 パラメタよりLED点/滅 .2 センサー情報取得 .3 クライアントに返信 Else .1 センサー情報取得 .2 LCDに情報表示 } setup() WiFi 初期化:内蔵WiFiをアクセスポイントに接続 Web初期化:内蔵Webサーバを立ち上げる センサー初期化:BMP280を初期化 loop() Webからのリクエストをチェックする システム構成 完成したプログラム /* * */ #include <Wire.h> #include <Adafruit_BMP280.h> #include <LiquidCrystal_I2C.h> //For SPI connection! #define BMP_SCK D5 #define BMP_MISO D6 #define BMP_MOSI D7 […]

WeMos (b6) I2C (BMP280+1602 LCD)

/* * */ #include <Wire.h> #include <Adafruit_BMP280.h> #include <LiquidCrystal_I2C.h> //For SPI connection! #define BMP_SCK D5 #define BMP_MISO D6 #define BMP_MOSI D7 #define BMP_CS D3 Adafruit_BMP280 bmp; // I2C // Adafruit_BMP280 bmp(BMP_CS); // hardware SPI // Adafruit_BMP280 bmp(BMP_CS, BMP_MOSI, BMP_MISO, BMP_SCK); // Set the LCD address to 0x27 for a 16 chars and 2 line display […]