首頁 > 評測 > FireBeetle Board-ESP32——HttpServer&Touch IO
FireBeetle Board-ESP32——HttpServer&Touch IO
- [導(dǎo)讀]
- 本文展示了如何使用Arduino的IDE在Firebeetle ESP32中構(gòu)建一個(gè)網(wǎng)絡(luò)服務(wù)器以及使用touchIO來配置一個(gè)觸摸按鍵。
通常情況下會(huì)想要通過訪問網(wǎng)頁來實(shí)現(xiàn)對某些設(shè)備的操作和控制,在arm平臺上建立httpserver,使用lwip協(xié)議棧的話開啟SSI和CGI就可以比較容易的實(shí)現(xiàn)上述想法。那么在arduino中,同樣可以創(chuàng)建網(wǎng)絡(luò)服務(wù)器,一下舉個(gè)例子
需要的庫就是FireBeetle Board-ESP32提供的
if (c == '\n') { // if the byte is a newline character
// if the current line is blank, you got two newline characters in a row.
// that's the end of the client HTTP request, so send a response:
if (currentLine.length() == 0) {
// HTTP headers always start with a response code (e.g. HTTP/1.1 200 OK)
// and a content-type so the client knows what's coming, then a blank line:
client.println("HTTP/1.1 200 OK");
client.println("Content-type:text/html");
client.println();
// the content of the HTTP response follows the header:
client.print("
LED Control
");
client.print("Turn On The LED
");
client.print("Turn Off The LED
");
// The HTTP response ends with another blank line:
client.println();
// break out of the while loop:
break;
} else { // if you got a newline, then clear currentLine:
currentLine = "";
}
} else if (c != '\r') { // if you got anything else but a carriage return character,
currentLine += c; // add it to the end of the currentLine
}
以上實(shí)現(xiàn)了發(fā)送http頭和內(nèi)容,假如要控制一個(gè)led,還需要發(fā)送點(diǎn)亮或者關(guān)閉的請求,然后解析后執(zhí)行IO動(dòng)作。
以下就是對應(yīng)的IO操作,2端口就是D9,連接到板載的LED.
// Check to see if the client request was "GET /H" or "GET /L":
if (currentLine.endsWith("GET /H")) {
digitalWrite(2, HIGH); // GET /H turns the LED on
}
if (currentLine.endsWith("GET /L")) {
digitalWrite(2, LOW); // GET /L turns the LED off
}
無線開啟后搜索程序中制定的AP并連接,然后我們可以訪問模塊在路由器中獲得的IP地址,調(diào)試程序在串口也會(huì)輸出這些信息。
點(diǎn)擊鏈接就可以操作模塊上的LED了,這就是實(shí)現(xiàn)網(wǎng)頁控制的基本原型。除此之外,還有值得一提的地方是FireBeetle Board-ESP32 提供了多達(dá) 10 個(gè)電容式傳感器 GPIO,能夠探測由手指或其他物品直接接觸或 接近而產(chǎn)生的電容差異。這種低噪聲特性和電路的高靈敏度設(shè)計(jì)適用于較小的觸摸板,可以直接用于觸摸開關(guān)。
接下來測試一下是否如實(shí)。
查找?guī)煳募,簡單書寫下面代碼
//觸摸IO測試
void setup() {
Serial.begin(115200);
delay(1000); // give me time to bring up serial monitor
Serial.println("FireBeetle Board-ESP32 Touch Test");
}
//10 個(gè)具有觸摸傳感器的IO,D0-D9,即T0-T9
void loop(){
//讀取IO 狀態(tài)
Serial.println(touchRead(T2)); // get value using T0->D9
delay(1000);
}
然后直接用手去觸摸IO,通過串口監(jiān)視器看到如下,在有手指觸摸的時(shí)候會(huì)變?yōu)楦唠娖?/p>

這樣的功能可以的確可以嘗試作為電容觸摸按鍵了。后續(xù)準(zhǔn)備還是回到C環(huán)境下了,不過不否定Arduino是很好用的
-
- 本文系21ic原創(chuàng),未經(jīng)許可禁止轉(zhuǎn)載!
網(wǎng)友評論
- 聯(lián)系人:巧克力娃娃
- 郵箱:board@21ic.com
- 我要投稿
-
歡迎入駐,開放投稿
-
人均百萬?英偉達(dá)中國員工收入曝光! 2024-08-29
-
《黑神話:悟空》玩家硬盤升級攻略:提升游戲體驗(yàn),暢享3A大作 2024-08-29
-
數(shù)睿數(shù)據(jù)參加《系統(tǒng)與軟件工程 低代碼開發(fā)平臺通用技術(shù)要求》國家標(biāo)準(zhǔn)編制 2024-08-29
- NRF52810藍(lán)牙數(shù)字耳機(jī)找人定制
預(yù)算:¥30005天前
- 125KW模塊式PCS軟硬件外包開發(fā)
預(yù)算:¥1100000015小時(shí)前
- 12V汽車啟動(dòng)電源項(xiàng)目BMS設(shè)計(jì)
預(yù)算:¥50000023小時(shí)前
- 數(shù)據(jù)可視化軟件 開發(fā)
預(yù)算:¥5000023小時(shí)前
- PLC項(xiàng)目調(diào)試修改
預(yù)算:¥100001天前
- 起動(dòng)電機(jī)控制器開發(fā)
預(yù)算:¥1100001天前