เราเพิ่งทราบว่า WiFi และ Bluetooth LE ไม่สามารถใช้งานพร้อมกันได้บนบอร์ด Arduino ที่ใช้โมดูลไร้สาย ESP32-based u-blox NINA-W102 ซึ่งส่งผลกระทบต่อบอร์ด Arduino Nano RP2040 Connect, Arduino MKR WiFi 1010 และ Arduino Nano 33 IoT
ปัญหานี้เกิดขึ้นมาเป็นเวลานานตั้งแต่บอร์ด Arduino รุ่นแรกที่ใช้โมดูล NINA-W10 เปิดตัวในปี 2018 โดยผู้ใช้สามารถเลือกใช้งาน WiFi หรือ Bluetooth LE, แต่ไม่สามารถใช้งานทั้งสองอย่างพร้อมกันได้ ตอนนี้ปัญหานี้ได้รับการแก้ไขเรียบร้อยแล้ว ด้วยเฟิร์มแวร์เวอร์ชันใหม่สำหรับโมดูล รวมถึงไลบรารี WiFi และ BLE เวอร์ชันใหม่ที่ช่วยให้สามารถใช้งาน WiFi และ Bluetooth LE พร้อมกันได้ในที่สุด
คุณจะต้องใช้ไลบรารีและเฟิร์มแวร์เวอร์ชันต่อไปนี้:
- WiFiNINA library เวอร์ชัน 2.0.0 หรือใหม่กว่า
- ArduinoBLE library เวอร์ชัน 2.0.0 หรือใหม่กว่า
- NINA-W102 firmware เวอร์ชัน 3.0.1 หรือใหม่กว่า
ไลบรารีทั้งสองสามารถอัปเดตได้อย่างง่ายดายผ่าน Library Manager ใน Arduino IDE ส่วนเฟิร์มแวร์ของโมดูลสามารถอัปเดตได้ด้วย Firmware Updater Tool ที่เมนู Tools > WiFi101 / WiFiNINA Firmware Updater
บอร์ดทั้งสามรุ่นที่กล่าวถึงในตอนต้นจะได้รับประโยชน์จากการอัปเดตนี้ แต่บอร์ด Arduino UNO WiFi Rev2 ไม่สามารถใช้ความสามารถนี้ได้ เนื่องจากมี หน่วยความจำจำกัด แม้ว่าบอร์ดจะใช้โมดูล u-blox NINA-W102 เช่นเดียวกันก็ตามไม่สามารถใช้ความสามารถนี้ได้ เนื่องจากมีหน่วยความจำจำกัด แม้ว่าบอร์ดจะใช้โมดูล u-blox NINA-W102 เช่นเดียวกันก็ตาม ต่อไปนี้คือตัวอย่างโค้ดที่แสดงการใช้งาน WiFi และ Bluetooth พร้อมกันในเวลาเดียวกัน:
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
#include <WiFiNINA.h> #include <ArduinoBLE.h> char ssid[] = "yourSSID"; // your network SSID (name) char pass[] = "yourPassword"; // your network password (use for WPA, or use as key for WEP) int status = WL_IDLE_STATUS; void setup() { Serial.begin(9600); while (!Serial); String fv = WiFi.firmwareVersion(); if (fv < "3.0.0") { Serial.println("Please upgrade the firmware, you can't run both WiFi and BLE with this version"); } // attempt to connect to WiFi network: while (status != WL_CONNECTED) { Serial.print("Attempting to connect to SSID: "); Serial.println(ssid); // Connect to WPA/WPA2 network. status = WiFi.begin(ssid, pass); // wait 10 seconds for connection: delay(10000); } Serial.println("Connected to WiFi"); // Initialize BLE if (!BLE.begin()) { Serial.println("Failed to initialize BLE!"); while (true); } // Set BLE device name and local name BLE.setLocalName("ArduinoCNXSoftPeripheral"); // Create and add a dummy BLE service BLEService dummyService("180A"); // UUID for the Device Information service BLE.addService(dummyService); // Start BLE advertising BLE.advertise(); Serial.println("BLE advertising started..."); } void loop() { // Add logic here to handle BLE connections or WiFi tasks if needed } |
ทั้งหมดนี้ฟังดูดี…แต่คำถามคือทำไมก่อนหน้านี้จึงไม่สามารถใช้งาน WiFi และ Bluetooth LE พร้อมกันได้? สาเหตุคือ WiFi เชื่อมต่อผ่านอินเทอร์เฟซ SPI ในขณะที่ Bluetooth เชื่อมต่อผ่าน UART และอินเทอร์เฟซ SPI กับ UART มีการใช้พินบางส่วนร่วมกัน เพื่อให้เหลือ GPIO สำหรับผู้ใช้มากขึ้น บนบอร์ด Arduino แต่การแชร์พินดังกล่าวทำให้เกิดความขัดแย้งของสัญญาณ (pin conflict) เมื่อพยายามใช้งาน WiFi และ Bluetooth พร้อมกันในเวลาเดียวกัน แนวทางแก้ไขคือเปลี่ยนให้ทั้ง WiFi และ Bluetooth ใช้อินเทอร์เฟซ SPI เหมือนกัน ซึ่งช่วยหลีกเลี่ยงปัญหาการใช้พินร่วมกันได้ แต่ยังไม่มีคำอธิบายชัดเจนว่าทำไมการแก้ไขปัญหานี้จึงใช้เวลานานกว่าจะสำเร็จ

แปลจากบทความภาษาอังกฤษ : WiFi and Bluetooth LE can now be used simultaneously on Arduino boards with NINA-W102 (ESP32) module

บรรณาธิการข่าวและบทความภาษาไทย CNX Software ได้มีความสนใจในด้านเทคโนโลยี โดยเฉพาะ Smart Home และ IoT

