新闻详情

新闻详情

首页 / 资讯中心 / 详情

ESP32-S3代码分享

发布时间:2026/9/2 13:40:39来源:尧图网络
ESP32-S3代码分享
RGB 灯程序参考#include Arduino.h #define RGB_LED_PIN 38 #define RGB_BRIGHTNESS 80 // 0~255 void rgbOff() { rgbLedWrite(RGB_LED_PIN, 0, 0, 0); } void setup() { Serial.begin(115200); delay(300); rgbOff(); Serial.println(RGB test start); } void loop() { Serial.println(RED); rgbLedWrite(RGB_LED_PIN, RGB_BRIGHTNESS, 0, 0); delay(1000); Serial.println(GREEN); rgbLedWrite(RGB_LED_PIN, 0, RGB_BRIGHTNESS, 0); delay(1000); Serial.println(BLUE); rgbLedWrite(RGB_LED_PIN, 0, 0, RGB_BRIGHTNESS); delay(1000); Serial.println(WHITE); rgbLedWrite(RGB_LED_PIN, RGB_BRIGHTNESS, RGB_BRIGHTNESS, RGB_BRIGHTNESS); delay(1000); Serial.println(OFF); rgbOff(); delay(1000); }ESP32-S3 WIFI 扫描#include WiFi.hconst char* ssid_list[]{he,JS,Your_SSID_3};// List of SSIDs you want to try to connect to const char* password123;// Wi-Fi passwordforthe networks voidsetup(){// Start serial communication Serial.begin(115200);// Initialize Wi-Fi WiFi.mode(WIFI_STA);WiFi.disconnect();// WaitforWi-Fi to completely disconnect delay(1000);// Start scanning Serial.println(Scanning for networks...);int nWiFi.scanNetworks();// Scan networks // Check scan resultif(n0){Serial.println(No networks found);}else{Serial.print(n);Serial.println( networks found);// Print SSID and signal strength of each networkfor(int i0;in;i){Serial.print(Network Name: );Serial.print(WiFi.SSID(i));Serial.print( Signal Strength: );Serial.println(WiFi.RSSI(i));}// You canselectwhichnetwork you want to connect to by specifying its index // For example, we will connect to the first network found(index0)Serial.print(Trying to connect to: );Serial.println(WiFi.SSID(0));// Select the first SSID found const char* ssidWiFi.SSID(0).c_str();// Get the first networks SSID // You can also hardcode the SSID you want to connect to: // const char* ssidYour_SSID;// Replace with the SSID you want to connect to // const char* passwordYour_PASSWORD;// Wi-Fi passwordforthe selected network WiFi.begin(ssid, password);// Waitforconnection int attempts0;while(WiFi.status()!WL_CONNECTEDattempts10){delay(1000);Serial.print(.);attempts;}if(WiFi.status()WL_CONNECTED){Serial.println();Serial.print(Successfully connected to network: );Serial.println(ssid);Serial.print(IP Address: );Serial.println(WiFi.localIP());}else{Serial.println();Serial.print(Failed to connect to: );Serial.println(ssid);}}}voidloop(){// Nothing todohere, all the logic isinsetup}ESP32-A7670-HTTP-POST#includeArduino.hstaticconstintRXPin17,TXPin18;staticconstuint32_tModuleBaud115200;String responseBuffer;String fullResponse;voidsendSerialCommand(constchar*command){Serial1.flush();delay(50);// Send command character by characterfor(size_ti0;istrlen(command);i){Serial1.write(command[i]);delay(15);}// Send termination sequencedelay(20);Serial1.write(\r);delay(20);Serial1.write(\n);delay(20);Serial1.flush();}boolsendATCommand(constchar*command,unsignedlongtimeout5000){Serial.print([SEND] );Serial.println(command);fullResponse;sendSerialCommand(command);unsignedlongstartmillis();bool responseReceivedfalse;while(millis()-starttimeout){while(Serial1.available()){charcSerial1.read();fullResponsec;if(c\r||c\n){responseReceivedtrue;Serial.print([RECV] );Serial.println(fullResponse);if(fullResponse.indexOf(OK)!-1||fullResponse.indexOf(ERROR)!-1){Serial.print([RESULT] );Serial.println(fullResponse);return(fullResponse.indexOf(OK)!-1);}fullResponse;}}if(responseReceived!Serial1.available()){delay(10);}}if(fullResponse.length()0){Serial.print([INCOMPLETE] );Serial.println(fullResponse);}Serial.print([TIMEOUT] );Serial.println(command);returnfalse;}voidsetupNetwork(){// Check module readinesswhile(!sendATCommand(AT)){delay(1000);}// Basic configurationsendATCommand(ATE0);// Disable echosendATCommand(ATCPIN?);// Check SIM status// Network configurationsendATCommand(ATCGDCONT1,\IP\,\PCCW\);// Set APNsendATCommand(ATCGACT1,1);// Activate network context}voidsendHTTPPost(){if(!sendATCommand(ATHTTPINIT)){Serial.println(HTTP initialization failed);return;}delay(1000);// Set target URLString urlCommandATHTTPPARA\URL\,\https://www.waveshare.cloud/api/sample-test/\;if(!sendATCommand(urlCommand.c_str(),8000)){Serial.println(URL setup failed);sendATCommand(ATHTTPTERM);return;}// Configure POST requestsendATCommand(ATHTTPPARA\CONTENT\,\text/plain\);// Send datasendATCommand(ATHTTPDATA12,5000);// Hello World! is 12 charssendSerialCommand(Hello world!);// Send actual data// Execute POST requestif(!sendATCommand(ATHTTPACTION1,15000)){Serial.println(HTTP request failed);}sendATCommand(ATHTTPTERM);}voidsetup(){Serial.begin(115200);Serial1.begin(ModuleBaud,SERIAL_8N1,RXPin,TXPin);setupNetwork();sendHTTPPost();}voidloop(){staticString asyncBuffer;while(Serial1.available()){charcSerial1.read();asyncBufferc;if(c\n||c\r){if(asyncBuffer.length()0){Serial.print([ASYNC] );Serial.println(asyncBuffer);asyncBuffer;}}}}
网站建设高端定制企业官网
RELATED

相关资讯

更多精彩内容,欢迎继续阅读

较早相关资讯

最新相关资讯

航拍图像序列拼接实战:从特征提取到全景图融合的完整技术链 2026/9/2 14:28:50

航拍图像序列拼接实战:从特征提取到全景图融合的完整技术链

简介:面向航拍图像序列拼接需求者,这份代码提供基于递归分组策略的C实现,适用于测绘、环境监测等无人机影像处理场景。算法刻意避开光束平差等高计算量步骤,通过分块、逐层拼接降低复杂度,并针对NPU硬件做优化&#xf…

阅读更多 →
Muse Spark与Apache Spark区别:AI编程助手如何提升大数据开发效率 2026/9/2 14:28:50

Muse Spark与Apache Spark区别:AI编程助手如何提升大数据开发效率

Muse Spark 周榜冲入前三,这个消息在开发者圈子里传播得很快。作为一个长期关注 AI 编程工具的人,我的第一反应是:这已经不是“AI 能不能写代码”的问题了,而是“AI 编程助手已经进入了拼版本、拼体验、拼场景深度”的新阶段。 但…

阅读更多 →
Qdrant向量数据库实战指南:RAG检索不准怎么破,如何落地生产级集群 2026/9/2 14:28:50

Qdrant向量数据库实战指南:RAG检索不准怎么破,如何落地生产级集群

Qdrant向量数据库实战指南:RAG检索不准怎么破,如何落地生产级集群 【免费下载链接】qdrant Qdrant - High-performance, massive-scale Vector Database and Vector Search Engine for the next generation of AI. Also available in the cloud https://…

阅读更多 →
免费开源的 Czkawka 磁盘清理指南:14 种扫描一次找出重复文件、相似图片和空文件夹 2026/9/2 14:28:50

免费开源的 Czkawka 磁盘清理指南:14 种扫描一次找出重复文件、相似图片和空文件夹

免费开源的 Czkawka 磁盘清理指南:14 种扫描一次找出重复文件、相似图片和空文件夹 【免费下载链接】czkawka Multi functional app to find duplicates, empty folders, similar images etc. 项目地址: https://gitcode.com/GitHub_Trending/cz/czkawka Czk…

阅读更多 →
如何上手 Ryujinx Switch 模拟器:在 PC 上运行 Switch 游戏 2026/9/2 14:28:50

如何上手 Ryujinx Switch 模拟器:在 PC 上运行 Switch 游戏

如何上手 Ryujinx Switch 模拟器:在 PC 上运行 Switch 游戏 【免费下载链接】Ryujinx 用 C# 编写的实验性 Nintendo Switch 模拟器 项目地址: https://gitcode.com/GitHub_Trending/ry/Ryujinx Ryujinx(Switch 模拟器)是一个用 C# 编写…

阅读更多 →
写论文软件哪个好?避开通用AI大坑,云智变AI才是毕业论文专属刚需工具 2026/9/2 14:25:46

写论文软件哪个好?避开通用AI大坑,云智变AI才是毕业论文专属刚需工具

每到毕业季,几乎所有大学生都会纠结同一个问题:写论文软件哪个好。打开网络搜索,五花八门的AI写作工具层出不穷,有的主打极速出稿,有的主打免费生成,很多同学跟风试用后,最终只剩满盘皆输的挫败…

阅读更多 →

今日资讯

本周资讯

本月资讯

看完文章仍有疑问?

联系尧图顾问,获取一对一建站咨询

立即免费咨询 📞 400-888-8888
📞