Relative Content

Author Archive for chen

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 […]

WeMos (b5) I2C (BMP180+OLED)

先日OLEDの文字表示できたが、今度 I2Cに (BMP180+OLED)両方を繋いで、センサーデータの表示を試み。 たまたま、この種類のBMP180とOLEDの結線順番は同じだから、4本線だけで済む。 プログラム /* * */ #include <Wire.h> #include <Adafruit_BMP085.h> #include <Adafruit_GFX.h> #include <Adafruit_SSD1306.h> #define OLED_RESET 0 // GPIO0 Adafruit_SSD1306 OLED(OLED_RESET); Adafruit_BMP085 bmp; void setup() { OLED.begin(); OLED.clearDisplay(); //Add stuff into the ‘display buffer’ OLED.setTextWrap(false); OLED.setTextSize(1); OLED.setTextColor(WHITE); OLED.setCursor(0,0); OLED.println(“automatedhome.party”); OLED.display(); //output ‘display buffer’ to screen // OLED.startscrollleft(0x00, 0x0F); //make display scroll if (!bmp.begin()) […]

WeMos (b4) DHT22 温度湿度表示

BMP280気圧センサーとNikia 5110同時に使うため、SPIで通信する環境を作って試したが、相性が悪いようだ。 どちらでも単独では動くが、一緒になると、表示がうあくいかない。 そこで、DHT22という温度湿度を試して見ることに。I2C,SPIどちらでもないので、相性が問題ならないと思う。 これは成功 /* Hello World * Display a simple message on the first line of the screen * * Connections: * WeMos D1 Mini Nokia 5110 Description * (ESP8266) PCD8544 LCD * * D2 (GPIO4) 0 RST Output from ESP to reset display * D1 (GPIO5) 1 CE Output from ESP to […]

WeMos (7) I2C OLED SSD1306 (Adafruit)

仕様 [0.96 インチ 4Pin IIC I2C ブルー OLED ディスプレイ モジュール Arduino対応]を使ってみる。 主な仕様は次のようになっています。 I2C通信 ディスプレイコントローラ: SSD1306 解像度: 128×64 電圧: 3.3V-5V ライブラリ 次の2つライブラリが必要 Adafruit_GFX Adafruit_SSD1306 こちらを参考にして、すんなりできた。下記の2つライブラリもSSD1306対応だ。 ThingPulseのライブラリ(SSD1306, SH1106対応) U8g2ライブラリ(多数OLED対応) 結線 I2Cの場合、デフォルトはSDA、SCLはD1、D2。 サンプルコード デフォルトはSDA、SCLはD1、D2。変更する場合、 Wire.begin(4,5); // OLED:SDA,SCL 行を変更して対応できるらしい。 #include <Adafruit_GFX.h> #include <Adafruit_SSD1306.h> #define OLED_RESET 0 // GPIO0 Adafruit_SSD1306 OLED(OLED_RESET); void setup() { // Wire.begin(4,5); // OLED:SDA,SCL OLED.begin(); OLED.clearDisplay(); //Add stuff […]

WeMos (b3) BMP280 I2C

BMP280センサーの利用し、 I2Cで気圧温度を測って見る。 ライブラリの追加 “Adafruit Unified Sensor”ライブラリの追加 センサーをライブラリ追加 BMP280センサーを利用する ライブラリからBMP280を検索して、追加してください 測定プログラム   /*************************************************************************** This is a library for the BMP280 humidity, temperature & pressure sensor Designed specifically to work with the Adafruit BMEP280 Breakout —-> http://www.adafruit.com/products/2651 These sensors use I2C or SPI to communicate, 2 or 4 pins are required to interface. Adafruit invests time and […]