0
  • 聊天消息
  • 系统消息
  • 评论与回复
登录后你可以
  • 下载海量资料
  • 学习在线课程
  • 观看技术视频
  • 写文章/发帖/加入社区
会员中心
创作中心

完善资料让更多小伙伴认识你,还能领取20积分哦,立即完善>

3天内不再提示

基于ESP32和Wio Terminal的DeepSeeek移动终端项目

柴火创客空间 来源:柴火创客空间 2025-02-28 16:51 次阅读
加入交流群
微信小助手二维码

扫码添加小助手

加入工程师交流群

今天小标给大家带来的是印度Maker的DeepSeek移动终端项目,该项目使用ESP32开发板作为主控,结合Wio Terminal的屏幕进行DeepSeeek输出显示。

2c42e6d0-f4fd-11ef-9310-92fbcf53809c.png

材料清单

Beetle ESP32 C6

面包板

跳线

Wio 终端

DFRobot Beetle ESP32 C6

2c79a5da-f4fd-11ef-9310-92fbcf53809c.jpg

高性能:配备 160MHz RISC-V 32 位处理器

多种通信协议:支持 Wi-Fi 6、蓝牙 5、Zigbee 3.0 和 Thread 1.32。

超低功耗:具有深度睡眠模式,电流消耗仅为 14uA。

电池管理:集成锂电池充电管理,使其适用于可穿戴应用。

紧凑的尺寸:尺寸仅为 25*20.5 毫米,像硬币一样小。

Wio Terminal 是一个基于 ATSAMD51 微控制器的完整开源开发平台。

2c9bbb02-f4fd-11ef-9310-92fbcf53809c.jpg

它具有 2.4 英寸 LCD 屏幕、板载传感器和无线连接选项,使其成为各种应用的绝佳选择。主要功能包括:

2cb381d8-f4fd-11ef-9310-92fbcf53809c.jpg

高性能:配备 120MHz ARM Cortex-M4F 处理器

显示屏:2.4 英寸 LCD 屏幕,分辨率为 320x240

连接性:通过附加模块支持 Wi-Fi、蓝牙和 LoRa

多功能 I/O:包括 GPIO、数字、模拟I2CUART 和 SPI 接口

内置传感器:具有陀螺仪、加速度计、麦克风和光传感器。

使用 Wio Terminal,可以轻松扩展 Beetle ESP32 聊天机器人项目的功能,提供实时反馈和交互式显示。

设置硬件

首先将 LED 连接到 Beetle ESP32。以下是引脚连接:

电阻器将 LED1 连接到引脚 4。

这个简单的设置将使我们能够通过闪烁的 LED 来可视化聊天机器人的活动。

接下来,通过 UART 将 Wio 终端连接到 Beetle ESP32:

将 Wio Terminal 的 TX 引脚连接到 Beetle ESP32 C6 的 RX 引脚。

将 Wio Terminal 的 RX 引脚连接到 Beetle ESP32 C6 的 TX 引脚。

确保连接两个设备的接地 (GND)。

2cc41296-f4fd-11ef-9310-92fbcf53809c.jpg

这个简单的设置将允许我们通过在 Wio 终端上显示 API 响应来可视化聊天机器人的活动。

连接Wi-Fi

要将 Beetle ESP32 连接到 Wi-Fi 网络,请使用以下代码片段:

#include


      
const char* ssid = "Your_SSID";      
const char* password = "Your_PASSWORD";      


      
void setup() {      
  Serial.begin(115200);      
  WiFi.begin(ssid, password);      
        
  while (WiFi.status() != WL_CONNECTED) {      
    delay(1000);      
    Serial.print(".");      
  }      
        
  Serial.println("Connected to WiFi");      
}

替换为本地实际 Wi-Fi 凭证 "Your_SSID""Your_PASSWORD"

创建 Web 服务器

接下来,让我们在 Beetle ESP32 上设置一个 Web 服务器:

// HTML content to be served
const char index_html[] PROGMEM = R"rawliteral(



  
  
  DFRobot Chatbot
  


  
  

DFRobot Beetle ESP32 C3 Chatbot

Debug Panel

)rawliteral";

此代码设置了一个基本的 Web 服务器,该服务器用作 HTML 页面,用户可以在其中输入他们的问题。

2ce62020-f4fd-11ef-9310-92fbcf53809c.jpg

处理用户问题,首先导航到 Open router 并创建一个新的 API 密钥。

2cff37f4-f4fd-11ef-9310-92fbcf53809c.jpg

将以下代码添加到您的项目中:

HTTPClient http;          
    http.begin("https://openrouter.ai/api/v1/chat/completions");          
    http.addHeader("Content-Type", "application/json");          
    http.addHeader("Authorization", String("Bearer ") + apiKey);          




          
    StaticJsonDocument<512> jsonDoc;          
    jsonDoc["model"] = "deepseek/deepseek-r1-distill-llama-70b";  // deepseek/deepseek-r1-distill-llama-70b //openai/gpt-4o-mini-2024-07-18          
    JsonArray messages = jsonDoc.createNestedArray("messages");          




          
    JsonObject systemMessage = messages.createNestedObject();          
    systemMessage["role"] = "system";          
    systemMessage["content"] = "Answer the user's question concisely and informatively.";          




          
    JsonObject userMessage = messages.createNestedObject();          
    userMessage["role"] = "user";          
    userMessage["content"] = question;          




          
    String requestBody;          
    serializeJson(jsonDoc, requestBody);          




          
    Serial.println("Sending HTTP POST request...");          
    int httpResponseCode = http.POST(requestBody);          
    Serial.print("HTTP Response code: ");          
    Serial.println(httpResponseCode);          




          
    String response = http.getString();          
    Serial.print("HTTP Response: ");          
    Serial.println(response);          




          
    StaticJsonDocument<1024> responseDoc;          
    DeserializationError error = deserializeJson(responseDoc, response);          




          
    if (!error) {          
      String assistantResponse = responseDoc["choices"][0]["message"]["content"].as();      
      Serial.print("Assistant Response: ");      
      Serial.println(assistantResponse); // Print the assistant response      
      Serial1.println(assistantResponse);      
      return response; // Return entire API response      
    } else {      
      return "Failed to parse JSON response.";      
    }      
  }

不要忘记替换为 OpenAI 的实际 API 密钥。"Your_API_Key"

最后,让我们在处理问题时通过闪烁 LED 来添加一些视觉反馈:

int led0 = 15;          
int led1 = 4;          




          
void setup() {          
  pinMode(led0, OUTPUT);          
  pinMode(led1, OUTPUT);          
}          




          
void loop() {          
  digitalWrite(led0, HIGH);          
  digitalWrite(led1, LOW);          
  delay(100);          
  digitalWrite(led0, LOW);          
  digitalWrite(led1, HIGH);          
  delay(100);          
}

Beetle ESP32 C6 代码:

这是完整的草图,请将凭据更改为您的凭据。

#include 
#include 
#include 
#include 

int led0 = 15;
int led1 = 4;

// WiFi credentials
const char* ssid = "";
const char* password = "";
const char* apiKey = "";

// Create WebServer object on port 80
WebServer server(80);

// HTML content to be served
const char index_html[] PROGMEM = R"rawliteral(



  
  
  DFRobot Chatbot
  


  
  

DFRobot Beetle ESP32 C3 Chatbot

Debug Panel

)rawliteral"; // Function to process the user question and get the response String processQuestion(String question) { Serial.print("User Question: "); Serial.println(question); // Print the user question if (WiFi.status() == WL_CONNECTED) { HTTPClient http; http.begin("https://openrouter.ai/api/v1/chat/completions"); http.addHeader("Content-Type", "application/json"); http.addHeader("Authorization", String("Bearer ") + apiKey); StaticJsonDocument<512> jsonDoc; jsonDoc["model"] = "deepseek/deepseek-r1-distill-llama-70b"; // deepseek/deepseek-r1-distill-llama-70b //openai/gpt-4o-mini-2024-07-18 JsonArray messages = jsonDoc.createNestedArray("messages"); JsonObject systemMessage = messages.createNestedObject(); systemMessage["role"] = "system"; systemMessage["content"] = "Answer the user's question concisely and informatively."; JsonObject userMessage = messages.createNestedObject(); userMessage["role"] = "user"; userMessage["content"] = question; String requestBody; serializeJson(jsonDoc, requestBody); Serial.println("Sending HTTP POST request..."); int httpResponseCode = http.POST(requestBody); Serial.print("HTTP Response code: "); Serial.println(httpResponseCode); String response = http.getString(); Serial.print("HTTP Response: "); Serial.println(response); StaticJsonDocument<1024> responseDoc; DeserializationError error = deserializeJson(responseDoc, response); if (!error) { String assistantResponse = responseDoc["choices"][0]["message"]["content"].as(); Serial.print("Assistant Response: "); Serial.println(assistantResponse); // Print the assistant response Serial1.println(assistantResponse); return response; // Return entire API response } else { return "Failed to parse JSON response."; } } return "WiFi not connected!"; } void setup() { // Start Serial Monitor Serial.begin(115200); Serial1.begin(9600, SERIAL_8N1, /*rx =*/17, /*tx =*/16); pinMode(led0, OUTPUT); pinMode(led1, OUTPUT); // Connect to Wi-Fi WiFi.begin(ssid, password); Serial.print("Connecting to WiFi..."); while (WiFi.status() != WL_CONNECTED) { delay(1000); Serial.print("."); } Serial.println(" Connected to WiFi"); // Print ESP32 Local IP Address Serial.print("ESP32 IP Address: "); Serial.println(WiFi.localIP()); // Serve HTML content server.on("/", HTTP_GET, []() { server.send_P(200, "text/html", index_html); }); // Handle POST request from the web page server.on("/getQuestion", HTTP_POST, []() { if (server.hasArg("plain")) { String body = server.arg("plain");

Wio 终端代码 :

将以下代码上传到 Wio 终端,从 Beetle 获取数据并在屏幕上打印出来。

#include
#include// Include the graphics library (this includes the sprite functions)        


        
// Create a SoftwareSerial object on pins 2 (RX) and 3 (TX)        
SoftwareSerial mySerial(2, 3); // RX, TX        


        
// Initialize the TFT screen        
TFT_eSPI tft = TFT_eSPI();  // Create object "tft"        


        
// Screen dimensions        
#define SCREEN_WIDTH 320        
#define SCREEN_HEIGHT 240        


        
void setup() {        
  Serial.begin(115200);        
  mySerial.begin(9600);        


        
  // Initialize the TFT screen        
  tft.begin();        
  tft.setRotation(3); // Set the screen orientation (1 for landscape mode)        
  tft.fillScreen(TFT_BLACK); // Clear the screen with black color        
  tft.setTextColor(TFT_WHITE); // Set text color to white        
  tft.setTextSize(2); // Set text size        


        
  // Print initial message to the screen        
  tft.drawString("Waiting for data...", 10, 10);        
}        


        
void loop() {        
  while (mySerial.available()) {        
    String str = mySerial.readString(); // Read the incoming data as a string        
    str.trim();        
    Serial.println(str);        


        
    // Clear the screen and display the new data with text wrapping        
    tft.fillScreen(TFT_BLACK); // Clear the screen with black color        
    printWrappedText(str, 10, 10, SCREEN_WIDTH - 20, 2);        


        
    mySerial.println("initialization done.");        
  }        
}        


        
// Function to print wrapped text on the screen        
void printWrappedText(String str, int x, int y, int lineWidth, int textSize) {        
  tft.setCursor(x, y);        
  tft.setTextSize(textSize);        


        
  int cursorX = x;        
  int cursorY = y;        
  int spaceWidth = tft.textWidth(" ");        
  int maxLineWidth = lineWidth;        


        
  String word;        
  for (int i = 0; i < str.length(); i++) {        
    if (str[i] == ' ' || str[i] == '
') {        
      int wordWidth = tft.textWidth(word);        


        
      if (cursorX + wordWidth > maxLineWidth) {        
        cursorX = x;        
        cursorY += tft.fontHeight();        
      }        


        
      tft.drawString(word, cursorX, cursorY);        
      cursorX += wordWidth + spaceWidth;        


        
      if (str[i] == '
') {        
        cursorX = x;        
        cursorY += tft.fontHeight();        
      }        


        
      word = "";        
    } else {        
      word += str[i];        
    }        
  }        


        
  if (word.length() > 0) {        
    int wordWidth = tft.textWidth(word);        
    if (cursorX + wordWidth > maxLineWidth) {        
      cursorX = x;        
      cursorY += tft.fontHeight();        
    }        
    tft.drawString(word, cursorX, cursory);        
  }        
}

串行终端响应:

2d1e788a-f4fd-11ef-9310-92fbcf53809c.jpg

然后在 Web 浏览器中打开 IP 地址。

2d3e0f1a-f4fd-11ef-9310-92fbcf53809c.jpg

接下来,输入提示符。

2d569238-f4fd-11ef-9310-92fbcf53809c.jpg

您可以在 Wio 终端屏幕中看到响应。

2d6f5e30-f4fd-11ef-9310-92fbcf53809c.jpg

如果您想查看整个 API 响应,只需按网站上的 Debug log 按钮即可。这将显示完整的 API 响应以进行调试。

2d8f41a0-f4fd-11ef-9310-92fbcf53809c.jpg

结论

通过此项目,您已经使用 Beetle ESP32 和 Wio Terminal 创建了一个基本的聊天机器人。可以通过添加更多功能(例如更多交互式网页、高级错误处理或集成其他 API)来进一步扩展此设置。DFRobot Beetle ESP32 C6 的紧凑尺寸和多功能功能,结合强大的 Wio 终端,使其成为各种物联网应用的绝佳选择。

声明:本文内容及配图由入驻作者撰写或者入驻合作网站授权转载。文章观点仅代表作者本人,不代表电子发烧友网立场。文章及其配图仅供工程师学习之用,如有内容侵权或者其他违规问题,请联系本站处理。 举报投诉
  • 移动终端
    +关注

    关注

    1

    文章

    218

    浏览量

    25593
  • ESP32
    +关注

    关注

    24

    文章

    1082

    浏览量

    20836
  • DeepSeek
    +关注

    关注

    2

    文章

    824

    浏览量

    2799

原文标题:创客项目秀|基于ESP32和Wio Terminal的DeepSeeek终端

文章出处:【微信号:ChaiHuoMakerSpace,微信公众号:柴火创客空间】欢迎添加关注!文章转载请注明出处。

收藏 人收藏
加入交流群
微信小助手二维码

扫码添加小助手

加入工程师交流群

    评论

    相关推荐
    热点推荐

    《电子发烧友电子设计周报》聚焦硬科技领域核心价值 第2期:2025.03.3--2025.03.7

    E907 RISC-V MCU,能够提供高效的计算能力。 基于ESP32Wio TerminalDeepSeeek移动
    发表于 03-07 18:03

    WIO Terminal +MCP2515 实现车辆OBD的速度监控

    WIO Terminal +MCP2515 实现车辆OBD的速度监控
    发表于 06-14 11:05

    Wio Terminal是什么?

    有人知道Wio Terminal是什么吗,能简单做一下介绍吗,它都能做些什么?
    发表于 10-07 07:11

    esp32 例程 蓝牙_wifi&amp;蓝牙MCU 该不该选ESP32

    ESP32是了国内乐鑫科技推出的Wifi&蓝牙物联网MCU,而最近项目正好在用ESP32,所以我们今天就来分享下,如何让你的ESP32跑起来,并应用于更多实际
    发表于 12-06 20:06 31次下载
    <b class='flag-5'>esp32</b> 例程 蓝牙_wifi&amp;蓝牙MCU  该不该选<b class='flag-5'>ESP32</b>

    ESP32/STM32电源系统开源项目

    电子发烧友网站提供《ESP32/STM32电源系统开源项目.zip》资料免费下载
    发表于 07-13 09:27 13次下载
    <b class='flag-5'>ESP32</b>/STM32电源系统开源<b class='flag-5'>项目</b>

    ESP32低成本板开源项目

    电子发烧友网站提供《ESP32低成本板开源项目.zip》资料免费下载
    发表于 07-18 11:20 4次下载
    <b class='flag-5'>ESP32</b>低成本板开源<b class='flag-5'>项目</b>

    ESP32开源项目分享

    电子发烧友网站提供《ESP32开源项目分享.zip》资料免费下载
    发表于 08-04 14:52 9次下载
    <b class='flag-5'>ESP32</b>开源<b class='flag-5'>项目</b>分享

    使用ESP32制作ESP RainMaker IoT项目

    电子发烧友网站提供《使用ESP32制作ESP RainMaker IoT项目.zip》资料免费下载
    发表于 10-24 10:54 9次下载
    使用<b class='flag-5'>ESP32</b>制作<b class='flag-5'>ESP</b> RainMaker IoT<b class='flag-5'>项目</b>

    使用Wio终端读取OBD2

    电子发烧友网站提供《使用Wio终端读取OBD2.zip》资料免费下载
    发表于 10-26 14:34 0次下载
    使用<b class='flag-5'>Wio</b><b class='flag-5'>终端</b>读取OBD2

    使用Wio终端扩展Arduboy

    电子发烧友网站提供《使用Wio终端扩展Arduboy.zip》资料免费下载
    发表于 11-03 09:24 0次下载
    使用<b class='flag-5'>Wio</b><b class='flag-5'>终端</b>扩展Arduboy

    ESP32房间项目

    电子发烧友网站提供《ESP32房间项目.zip》资料免费下载
    发表于 11-08 09:23 1次下载
    <b class='flag-5'>ESP32</b>房间<b class='flag-5'>项目</b>

    使用Wio Terminal和Tensorflow Lite创建智能气象站

    电子发烧友网站提供《使用Wio Terminal和Tensorflow Lite创建智能气象站.zip》资料免费下载
    发表于 06-25 10:30 0次下载
    使用<b class='flag-5'>Wio</b> <b class='flag-5'>Terminal</b>和Tensorflow Lite创建智能气象站

    基于ESP32的开源项目

    电子发烧友网站提供《基于ESP32的开源项目.zip》资料免费下载
    发表于 07-03 10:29 8次下载
    基于<b class='flag-5'>ESP32</b>的开源<b class='flag-5'>项目</b>

    Seeed Wio终端开源分享

    电子发烧友网站提供《Seeed Wio终端开源分享.zip》资料免费下载
    发表于 07-12 10:04 0次下载
    Seeed <b class='flag-5'>Wio</b><b class='flag-5'>终端</b>开源分享

    ESP32开源项目

    电子发烧友网站提供《ESP32开源项目.zip》资料免费下载
    发表于 07-13 10:47 7次下载
    <b class='flag-5'>ESP32</b>开源<b class='flag-5'>项目</b>