ESP32 腳位34 連接到可變電阻腳位 2
ESP32 腳位VIN 連接到可變電阻腳位 1
ESP32 腳位GND 連接到可變電阻腳位 3
1.jpg


讀取數值為12 bits = 4096
0 - 4095

程式碼:

  1. const int potPin = 34;
  2. int val=0;
  3. void setup() {
  4.   Serial.begin(115200); //連線速率
  5.   delay(1000);
  6. }
  7.  
  8. void loop() {
  9.   // put your main code here, to run repeatedly:
  10.   val = analogRead(potPin); //讀取電壓數值
  11.   Serial.println(val); //印出電壓數值
  12.   delay(500); //延遲0.5秒
  13. }
文章標籤

NetYea 網頁設計 發表在 痞客邦 留言(0) 人氣()

ESP32 腳位 34 對應10K歐姆電阻與光敏電組連接處
ESP32 腳位 27 對應LED 正極
10K歐姆電阻另一腳接VCC
LED腳負極接地
光敏另一腳接地
光敏電阻與10K歐姆電阻連接
如圖:

1.jpg

文章標籤

NetYea 網頁設計 發表在 痞客邦 留言(0) 人氣()

影片



伺服馬達接線圖
1.png

黃線  GPIO27  紅線  5V  黑線  GND
ESP32 電力只能推動一個馬達,如果要推動兩個馬達就要外接電源了

程式碼

  1. #include <Servo.h>
  2. Servo myservo;  // 建立伺服馬達控制
  3.  
  4. // 伺服馬達的連接 GPIO
  5. static const int servoPin = 27;
  6. int pos = 0;
  7. void setup() {
  8.   // put your setup code here, to run once:
  9.   myservo.attach(servoPin);  // 將伺服馬達連接的GPIO pin連接伺服物件
  10.   Serial.begin(115200);//序列阜連線速率
  11. }
  12.  
  13. void loop() {
  14.   // put your main code here, to run repeatedly:
  15.   if(Serial.available()){                 //
  16.     int num = Serial.parseInt();     // case 前置 num(數字鍵)
  17.    
  18.     switch(num) {                            //   
  19.    
  20.       case 1 :   //1~9
  21.         for(pos = 0; pos < 180; pos += 1) // 一度一度由 0 度旋轉到 180 度
  22.         myservo.write(pos);
  23.         delay(200);
  24.         break;
  25.       
  26.       case 2 : // 1~9
  27.         for(pos = 180; pos>=1; pos-=1) // 一度一度由 180 度旋轉到 0 度
  28.         myservo.write(pos);
  29.         delay(200);
  30.         break;
  31.     }
  32.   }
  33. }
文章標籤

NetYea 網頁設計 發表在 痞客邦 留言(0) 人氣()

學會Arduino基本操控後
一定會想學會無線遙控,如藍芽Bluetooth, Wifi
這篇說明藍芽Bluetooth操控

結果圖
1.png


影片


代碼:

  1. // Include necessary libraries
  2. #include <BLEDevice.h>
  3. #include <BLEServer.h>
  4. #include <BLEUtils.h>
  5. //#include <BLE2902.h>
  6. //#include <Wire.h>
  7.  
  8. // 定義 UUIDs (注意要與App Inventor內容對應)
  9. #define SERVICE_UUID            "C6FBDD3C-7123-4C9E-86AB-005F1A7EDA01"
  10. #define CHARACTERISTIC_UUID_RX  "B88E098B-E464-4B54-B827-79EB2B150A9F"
  11. #define CHARACTERISTIC_UUID_TX  "D769FACF-A4DA-47BA-9253-65359EE480FB"
  12.  
  13. // 定義LM35 ESP32 GPIO接腳
  14. const int analogIn = A0;
  15.   
  16. int RawValue= 0;
  17. double Voltage = 0;
  18. double tempC = 0;
  19. double tempF = 0;
  20. String BLE_Code;
  21. BLECharacteristic *pCharacteristic;
  22. bool deviceConnected = false;
  23. // Handle received and sent messages
  24. boolean ledState=false;
  25. String message = "";
  26. char incomingChar;
  27.  
  28. // Temperature Sensor 與led接腳變數
  29. float temperature = 0;
  30. const int ledPin = 2;
  31.  
  32. // 設定 callbacks onConnect & onDisconnect函數
  33. class MyServerCallbacks: public BLEServerCallbacks {
  34.   void onConnect(BLEServer* pServer) {
  35.     deviceConnected = true;
  36.   };
  37.   void onDisconnect(BLEServer* pServer) {
  38.     deviceConnected = false;
  39.   }
  40. };
  41.  
  42. // 設定 callback function 當收到新的資訊 (from the Android application)
  43. class MyCallbacks: public BLECharacteristicCallbacks {
  44.   void onWrite(BLECharacteristic *pCharacteristic) {
  45.     std::string rxValue = pCharacteristic->getValue();
  46.     BLE_Code="";
  47.     if(rxValue.length() > 0) {
  48.       Serial.print("接收資料為 : ");
  49.       for(int i = 0; i < rxValue.length(); i++) {
  50.         BLE_Code+=rxValue[i];
  51.         Serial.print(rxValue[i]);
  52.       }
  53.       Serial.println();
  54.       BLE_Code.toUpperCase();
  55.       Serial.println(BLE_Code);
  56.       if(BLE_Code.indexOf("LED")==0)
  57.       {
  58.         ledState=!ledState;
  59.       Serial.println(ledState);
  60.       }
  61.       if(BLE_Code.indexOf("ON")==0)
  62.       {
  63.         Serial.println("LED 點亮!");
  64.         ledState=true;
  65.       }
  66.       else if(BLE_Code.indexOf("OFF")==0) {
  67.         Serial.println("LED 熄滅!");
  68.         ledState=false;
  69.       }
  70.     }
  71.   }
  72. };
  73.  
  74. void setup() {
  75.   Serial.begin(115200);
  76.   pinMode(ledPin, OUTPUT);
  77.    
  78.   // 建立BLE Device
  79.   BLEDevice::init("ESP32_WeMos1");
  80.  
  81.   // 建立BLE Server
  82.   BLEServer *pServer = BLEDevice::createServer();
  83.   pServer->setCallbacks(new MyServerCallbacks());
  84.  
  85.   // 建立BLE Service
  86.   BLEService *pService = pServer->createService(SERVICE_UUID);
  87.  
  88.   // 建立BLE Characteristic
  89.   pCharacteristic = pService->createCharacteristic(
  90.                       CHARACTERISTIC_UUID_TX,
  91.                       BLECharacteristic::PROPERTY_NOTIFY);                     
  92. //  pCharacteristic->addDescriptor(new BLE2902());
  93.   BLECharacteristic *pCharacteristic = pService->createCharacteristic(
  94.                                          CHARACTERISTIC_UUID_RX,
  95.                                          BLECharacteristic::PROPERTY_WRITE);
  96. pCharacteristic->setCallbacks(new MyCallbacks());
  97.  
  98.   // 開始(起)service
  99.   pService->start();
  100.  
  101.   // 開始(起)advertising
  102.   pServer->getAdvertising()->start();
  103.   Serial.println("等待BLE手機連線....");
  104.   
  105.   digitalWrite(ledPin,LOW);
  106.   delay(500);
  107.   digitalWrite(ledPin,HIGH);
  108.   delay(500);
  109.   digitalWrite(ledPin,LOW);
  110. }
  111.  
  112. void loop() {
  113.   // Check received message and control output accordingly
  114.     if (ledState)
  115.         digitalWrite(ledPin, HIGH);
  116.       else
  117.         digitalWrite(ledPin, LOW);
  118.   delay(20);
  119. }
文章標籤

NetYea 網頁設計 發表在 痞客邦 留言(0) 人氣()

影片



TB6612FNG是東芝生產的馬達驅動與控制IC,內部包含兩組H橋式電路,可驅動和控制兩個小型直流馬達,或者一個雙極性步進馬達。

1.jpg

文章標籤

NetYea 網頁設計 發表在 痞客邦 留言(0) 人氣()



ESP32 控制 TB6612FNG 直流馬達驅動∕控制板 請看這篇

 

使用Android手機如何用Arduino藍芽連線ESP32控制蜘蛛機器人
需要使用雙電源
如果使用單電源,電流會被馬達抽走
ESP32晶片電流不足會無法正常運作
文章標籤

NetYea 網頁設計 發表在 痞客邦 留言(0) 人氣()

最近電腦重灌WIN10
arduino重新安裝及設定
發現輸入開發管理員網址時會出現錯誤

  1. https://dl.espressif.com/dl/package_esp32_index.json
文章標籤

NetYea 網頁設計 發表在 痞客邦 留言(0) 人氣()

首先可以到FPDF網站下載程式,當然FPDF的網站有教學也值得前往觀看http://www.fpdf.org/

或直接點選這邊下載fpdf16.zip

文章標籤

NetYea 網頁設計 發表在 痞客邦 留言(0) 人氣()

sqlite3的名擴展在PHP 5.3.0+以上都會默認啟用。在可以compile-時使用--without-sqlite3來禁用它。
視窗柯林斯用戶通過啟用php_sqlite3.dll才能使用此擴展。php_sqlite3.dll默認所有遊戲在PHP 5.3.0之後的PHP發行版中。
有關詳細的安裝說明,請查看PHP教程及其官方網站。
連接到的SQLite數據庫以下PHP代碼顯示如何連接到SQLite數據庫。如果數據庫不存在,那麼它將創建一個新的數據庫,最後將返回一個數據庫對象。

  1. <?php
  2.    class SQLiteDB extends SQLite3
  3.    {
  4.       function __construct()
  5.       {
  6.          $this->open('phpdb.db');
  7.       }
  8.    }
  9.    $db = new SQLiteDB();
  10.    if(!$db){
  11.       echo $db->lastErrorMsg();
  12.    } else {
  13.       echo "Yes, Opened database successfully\n";
  14.    }
  15. ?>
文章標籤

NetYea 網頁設計 發表在 痞客邦 留言(0) 人氣()

有時候會需要寫PHP程式去取得指定資料夾內的檔案列表,這三個函式分別是glob、scandir、readdir
 
文章標籤

NetYea 網頁設計 發表在 痞客邦 留言(0) 人氣()