ESP-32でメカナム　4WDを動かそう

ROTSONを作りましたが、手軽に動かせる子が欲しいので作ってみました。
なお、手軽に動かせる割に、製作は滅茶苦茶手がかかりました・・・
<img src="https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/285344/0f380506-8663-dde3-70e6-4a0832d76140.jpeg" alt="ROTSON ESP-32Power" width="1000" >
当初TB6612FNGを2個使用した専用ボードを作りましたが
どうやってもストールしてしまうために、L293DDを使用した
NodeMCU ESP-32 MotorShield FULL IO Extension Boardを2個使用しました。
https://qiita.com/usashirou/items/4674ece87d452e71256c
<img src="https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/285344/938b6330-9c7e-7a68-8870-30771a4a3dd9.jpeg" alt="ROTSON ESP-32Power" width="1000" >
TB6612を2個使用した際に、どうしても電流が全く足りない状態になるのは、リークしているのか、
電流制限が入っていないのか不明ですが、L293DDを2個使用した場合には全く問題ありません。

ESP-32 MotorShield FULLとは、ジャンパーワイヤーでつないでいます。
また、NodeMCUに搭載している、ダイオードが１A品の為にNodeMCUが1個壊れてしまいました。
(2.5A程度は流れるバッテリーを使用しているので当然ですね）
このためもあり、バッテリーは、2個使用していますが、本来は1個でも動くはずです。
5Vのラインは、ダイオードの後ろにあります。
<blockquote class="twitter-tweet"><p lang="ja" dir="ltr">ESP-32＠メカナム4WD完成<br>ESP-32 MotorShieldFull <a href="https://t.co/aNzY75Dthg">pic.twitter.com/aNzY75Dthg</a></p>&mdash; usashirou (@usashirou1) <a href="https://twitter.com/usashirou1/status/1248543602159976448?ref_src=twsrc%5Etfw">April 10, 2020</a></blockquote> <script async src="https://platform.twitter.com/widgets.js" charset="utf-8"></script>

コードは以下を加工しています。
ESP32-DevKitを使ってWiFiコントロール・カーを製作(1)
http://mukujii.sakura.ne.jp/esp1.html

![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/285344/613470bc-c66b-ef06-58f5-5c77ac6db713.png)

```
  /* WiFi-Control-Car */
  
  #include <WiFi.h>
const char* ssid     = "yokohama";      //アクセスポイントのSSID
const char* password = "12345678";     //アクセスポイントのパスワード
const char html[] =
    "<!DOCTYPE html><html lang='ja'><head><meta charset='UTF-8'>\
  <style>input {margin:8px;width:80px;}\
  div {font-size:16pt;color:red;text-align:center;width:400px;border:groove 40px orange;}</style>\
  <title>WiFi_Car Controller</title></head>\
  <body><div><p>Tank Controller</p>\
  <form method='get'>\
  <input type='submit' name='fl' value='斜左' />\
  <input type='submit' name='fo' value='前進' />\
  <input type='submit' name='fr' value='斜右' /><br>\
  <input type='submit' name='le' value='左' />\
  <input type='submit' name='st' value='停止' />\
  <input type='submit' name='ri' value='右' /><br>\
  <input type='submit' name='bl' value='斜左後' />\
  <input type='submit' name='ba' value='後退' />\
  <input type='submit' name='br' value='斜右後' /><br><br>\
  <input type='submit' name='tl' value='左回転' />\
  <input type='submit' name='tr' value='右回転' /><br>\
  </form></div></body></html>";
  
  void stop() {
    digitalWrite(12, LOW);
    digitalWrite(13, LOW);
    ledcWrite(0, 0);
    digitalWrite(25, LOW);
    digitalWrite(26, LOW);
    ledcWrite(1, 0);
    digitalWrite(15, LOW);
    digitalWrite(16, LOW);
    ledcWrite(2, 0);
    digitalWrite(18, LOW);
    digitalWrite(19, LOW);
    ledcWrite(3, 0);
  }
  
  WiFiServer server(80);
  
  void setup()
  {
    Serial.begin(115200);
  //右後
    pinMode(12, OUTPUT);
    pinMode(13, OUTPUT);
    pinMode(14, OUTPUT);
  //右前
    pinMode(15, OUTPUT);
    pinMode(16, OUTPUT);
    pinMode(17, OUTPUT);
  //左前 
    pinMode(18, OUTPUT);
    pinMode(19, OUTPUT);
    pinMode(21, OUTPUT);
  //左後 
    pinMode(25, OUTPUT);
    pinMode(26, OUTPUT);
    pinMode(27, OUTPUT);
  
    ledcSetup(0, 490, 8);
    ledcSetup(1, 490, 8);
    ledcSetup(2, 490, 8);
    ledcSetup(3, 490, 8);
    ledcAttachPin(14, 0);
    ledcAttachPin(27, 1);
    ledcAttachPin(17, 2);
    ledcAttachPin(21, 3);
    delay(10);
  
    Serial.println();
    Serial.println();
    Serial.print("Connecting to ");
    Serial.println(ssid);
  
    WiFi.begin(ssid, password);
  
    while (WiFi.status() != WL_CONNECTED) {
      delay(500);
      Serial.print(".");
    }
  
    Serial.println("");
    Serial.println("WiFi connected.");
    Serial.println("IP address: ");
    Serial.println(WiFi.localIP());
  
    server.begin();
  
  }
  
  void loop() {
    WiFiClient client = server.available();
  
    if (client) {
      Serial.println("New Client.");
      String currentLine = "";
      while (client.connected()) {
        if (client.available()) {
          char c = client.read();
          Serial.write(c);
          if (c == '\n') {
            if (currentLine.length() == 0) {
              client.println("HTTP/1.1 200 OK");
              client.println("Content-type:text/html");
              client.println();
  
              client.print(html);
              client.println();
              break;
            } else {
              currentLine = "";
            }
          } else if (c != '\r') {
            currentLine += c;
          }
  
          if (currentLine.endsWith("GET /?fo")) {
            stop();
            digitalWrite(12, LOW);
            digitalWrite(13, HIGH);
            ledcWrite(0, 255);
            digitalWrite(25, LOW);
            digitalWrite(26, HIGH);
            ledcWrite(1, 255);
            digitalWrite(15, LOW);
            digitalWrite(16, HIGH);
            ledcWrite(2, 255);
            digitalWrite(18, LOW);
            digitalWrite(19, HIGH);
            ledcWrite(3, 255);
          }
          if (currentLine.endsWith("GET /?fr")) {
            stop();
            digitalWrite(12, LOW);
            digitalWrite(13, LOW);
            ledcWrite(0, 0);
            digitalWrite(25, LOW);
            digitalWrite(26, HIGH);
            ledcWrite(1, 255);
            digitalWrite(15, LOW);
            digitalWrite(16, LOW);
            ledcWrite(2, 0);
            digitalWrite(18, LOW);
            digitalWrite(19, HIGH);
            ledcWrite(3, 255);
          }
          if (currentLine.endsWith("GET /?fl")) {
            stop();
            digitalWrite(12, LOW);
            digitalWrite(13, HIGH);
            ledcWrite(0, 255);
            digitalWrite(25, LOW);
            digitalWrite(26, LOW);
            ledcWrite(1, 0);
            digitalWrite(15, LOW);
            digitalWrite(16, HIGH);
            ledcWrite(2, 255);
            digitalWrite(18, LOW);
            digitalWrite(19, LOW);
            ledcWrite(3, 0);
          }
          if (currentLine.endsWith("GET /?ri")) {
            stop();
            digitalWrite(12, HIGH);
            digitalWrite(13, LOW);
            ledcWrite(0, 255);
            digitalWrite(25, LOW);
            digitalWrite(26, HIGH);
            ledcWrite(1, 255);
            digitalWrite(15, HIGH);
            digitalWrite(16, LOW);
            ledcWrite(2, 255);
            digitalWrite(18, LOW);
            digitalWrite(19, HIGH);
            ledcWrite(3, 255);
          }
          if (currentLine.endsWith("GET /?le")) {
            stop();
            digitalWrite(12, LOW);
            digitalWrite(13, HIGH);
            ledcWrite(0, 255);
            digitalWrite(25, HIGH);
            digitalWrite(26, LOW);
            ledcWrite(1, 255);
            digitalWrite(15, LOW);
            digitalWrite(16, HIGH);
            ledcWrite(2, 255);
            digitalWrite(18, HIGH);
            digitalWrite(19, LOW);
            ledcWrite(3, 255);
          }
          
          if (currentLine.endsWith("GET /?ba")) {
            stop();
            digitalWrite(12, HIGH);
            digitalWrite(13, LOW);
            ledcWrite(0, 255);
            digitalWrite(25, HIGH);
            digitalWrite(26, LOW);
            ledcWrite(1, 255);
            digitalWrite(15, HIGH);
            digitalWrite(16, LOW);
            ledcWrite(2, 255);
            digitalWrite(18, HIGH);
            digitalWrite(19, LOW);
            ledcWrite(3, 255);
          }
          if (currentLine.endsWith("GET /?br")) {
            stop();
            digitalWrite(12, HIGH);
            digitalWrite(13, LOW);
            ledcWrite(0, 255);
            digitalWrite(25, LOW);
            digitalWrite(26, LOW);
            ledcWrite(1, 0);
            digitalWrite(15, HIGH);
            digitalWrite(16, LOW);
            ledcWrite(2, 255);
            digitalWrite(18, LOW);
            digitalWrite(19, LOW);
            ledcWrite(3, 0);
          }
          if (currentLine.endsWith("GET /?bl")) {
            stop();
            digitalWrite(12, LOW);
            digitalWrite(13, LOW);
            ledcWrite(0, 0);
            digitalWrite(25, HIGH);
            digitalWrite(26, LOW);
            ledcWrite(1, 255);
            digitalWrite(15, LOW);
            digitalWrite(16, LOW);
            ledcWrite(2, 0);
            digitalWrite(18, HIGH);
            digitalWrite(19, LOW);
            ledcWrite(3, 255);
          }
          if (currentLine.endsWith("GET /?st")) {
            stop();
            digitalWrite(12, LOW);
            digitalWrite(13, LOW);
            ledcWrite(0, 255);
            digitalWrite(25, LOW);
            digitalWrite(26, LOW);
            ledcWrite(1, 255);
            digitalWrite(15, LOW);
            digitalWrite(16, LOW);
            ledcWrite(2, 255);
            digitalWrite(18, LOW);
            digitalWrite(19, LOW);
            ledcWrite(3, 255);
          }
          if (currentLine.endsWith("GET /?tr")) {
            stop();
            digitalWrite(12, LOW);
            digitalWrite(13, HIGH);
            ledcWrite(0, 255);
            digitalWrite(25, HIGH);
            digitalWrite(26, LOW);
            ledcWrite(1, 255);
            digitalWrite(15, HIGH);
            digitalWrite(16, LOW);
            ledcWrite(2, 255);
            digitalWrite(18, LOW);
            digitalWrite(19, HIGH);
            ledcWrite(3, 255);
          }
          if (currentLine.endsWith("GET /?tl")) {
            stop();
            digitalWrite(12, HIGH);
            digitalWrite(13, LOW);
            ledcWrite(0, 255);
            digitalWrite(25, LOW);
            digitalWrite(26, HIGH);
            ledcWrite(1, 255);
            digitalWrite(15, LOW);
            digitalWrite(16, HIGH);
            ledcWrite(2, 255);
            digitalWrite(18, HIGH);
            digitalWrite(19, LOW);
            ledcWrite(3, 255);
          }
        }
      }
      client.stop();
      Serial.println("Client Disconnected.");
    }
  }
```