// ****** ESP8266_OLED_RC.ino *********** // ESP8266 WiFi と スマホを直結(AP不要) // WiFi ラジコン化 2021.9.10 稼働始めた // **************************************** // DiyStudio 0.91インチESP8266 OLED // ディスプレイ0.91インチOLED // ESP8266 WIFI開発ボードWIFIキット8 // CP2104 IOTサポート // Arduino IDE NodeMCU LUA // 白い底板+ブルースクリーンOLED // ¥1,199 アマゾン 2021/6/9に購入 /**************** Board *****************/ // CP210x USB to UART Bridge VCP Drivers // Board ==> Generic ESP8266 Module // Port ==> CP210x USB to UART Bridge (COM14) /******************************************/ // ファイル → 環境設定 // http://arduino.esp8266.com/stable/package_esp8266com_index.json // "esp8266 by ES8266 Community" → インストール // ボードマネージャー → "Generic ESP8266 Module" // ソースコード // https://www.elekit.co.jp/product/docs/PU-2709Wi-ficar.pdf // 日本語指定 // http://mukujii.sakura.ne.jp/esp1.html /* Configuring access point...AP IP address: 192.168.4.1 ※この状態はWi-fiモジュールとスマートホンがダイレクトに接続されている 状態ですので、インターネットは使用できません。 */ // Display OLED // https://qiita.com/jakalada/items/793a6cf5ff2796db4e86 // #include #include #include #include #include #include #include #define SCREEN_WIDTH 128 #define SCREEN_HEIGHT 32 // Declaration for an SSD1306 display connected to I2C (SDA, SCL pins) #define OLED_RESET 16 // Reset pin # (or -1 if sharing Arduino reset pin) Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET); /* Set these to your desired credentials. */ const char *ssid = "WIFI-RC"; // AP モード時のSSID const char *password = "12345678"; // パスワード ESP8266WebServer server(80); String form = "\n\ \
\
\
\
\
\  \
\  \
\
\
\
\
"; /* プロトタイプ宣言*/ void handleRoot(); void handle_stop(); void handle_forward(); void handle_turn_left(); void handle_turn_right(); void handle_back(); void ST_ACT(); void FD_ACT(); void TL_ACT(); void TR_ACT(); void BK_ACT(); void setup() { delay(500); Serial.begin(115200); Serial.println(); Serial.print("Configuring access point..."); if (!display.begin(SSD1306_SWITCHCAPVCC, 0x3C)) { // Address 0x3C for 128x32 Serial.println(F("SSD1306 allocation failed")); for (;;); // Don't proceed, loop forever } display.display(); delay(1000); display.clearDisplay(); display.setTextSize(3); display.setTextColor(WHITE); display.setCursor(0, 10); display.println("WiFi RC"); display.display(); delay(1000); /* You can remove the password parameter if you want the AP to be open. */ WiFi.softAP(ssid, password); IPAddress myIP = WiFi.softAPIP(); Serial.print("AP IP address: "); Serial.println(myIP); server.on("/", handleRoot); /* 各アクション時のハンドル設定*/ server.on("/ST", handle_stop); server.on("/FD", handle_forward); server.on("/TL", handle_turn_left); server.on("/TR", handle_turn_right); server.on("/BK", handle_back); server.begin(); Serial.println("HTTP server started"); Serial.println("STOP"); } void loop() { server.handleClient(); } /*--- ここから下は全て新しく追加するプログラムです ----*/ /* 各ハンドルの内容記述*/ /* ハンドル初期状態の記述*/ void handleRoot() { server.send(200, "text/html", form); handle_stop(); } /* ストップハンドルの記述*/ void handle_stop() { Serial.println("□"); ST_ACT(); server.send(200, "text/html", form); } /* 前進ハンドルの記述*/ void handle_forward() { Serial.println("⇧"); FD_ACT(); server.send(200, "text/html", form); } /* 左折ハンドルの記述*/ void handle_turn_left() { Serial.println("<<==="); TL_ACT(); server.send(200, "text/html", form); } /* 右折ハンドルの記述*/ void handle_turn_right() { Serial.println("===>>"); TR_ACT(); server.send(200, "text/html", form); } /* バックハンドルの記述*/ void handle_back() { Serial.println("⇩"); BK_ACT(); server.send(200, "text/html", form); } /*---- 各ハンドル記述内の関数内容 --------*/ /* ストップの関数*/ void ST_ACT() { display.clearDisplay(); display.setTextSize(3); display.setTextColor(WHITE); display.setCursor(0, 10); display.println("STOP"); display.display(); } /* 前進の関数*/ void FD_ACT() { display.clearDisplay(); display.setTextSize(3); display.setTextColor(WHITE); display.setCursor(0, 10); display.println("FORWARD"); display.display(); } /* 左折の関数*/ void TL_ACT() { display.clearDisplay(); display.setTextSize(3); display.setTextColor(WHITE); display.setCursor(0, 10); display.println("<<==="); display.display(); } /* 右折の関数*/ void TR_ACT() { display.clearDisplay(); display.setTextSize(3); display.setTextColor(WHITE); display.setCursor(0, 10); display.println("===>>"); display.display(); } /* バックの関数*/ void BK_ACT() { display.clearDisplay(); display.setTextSize(3); display.setTextColor(WHITE); display.setCursor(0, 10); display.println("BACK"); display.display(); }