0
  • 聊天消息
  • 系統(tǒng)消息
  • 評論與回復(fù)
登錄后你可以
  • 下載海量資料
  • 學(xué)習(xí)在線課程
  • 觀看技術(shù)視頻
  • 寫文章/發(fā)帖/加入社區(qū)
會員中心
創(chuàng)作中心

完善資料讓更多小伙伴認識你,還能領(lǐng)取20積分哦,立即完善>

3天內(nèi)不再提示

基于ESP32和Wio Terminal的DeepSeeek移動終端項目

柴火創(chuàng)客空間 ? 來源:柴火創(chuàng)客空間 ? 2025-02-28 16:51 ? 次閱讀

今天小標給大家?guī)淼氖怯《萂aker的DeepSeek移動終端項目,該項目使用ESP32開發(fā)板作為主控,結(jié)合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 位處理器。

多種通信協(xié)議:支持 Wi-Fi 6、藍牙 5、Zigbee 3.0 和 Thread 1.32。

超低功耗:具有深度睡眠模式,電流消耗僅為 14uA。

電池管理:集成鋰電池充電管理,使其適用于可穿戴應(yīng)用。

緊湊的尺寸:尺寸僅為 25*20.5 毫米,像硬幣一樣小。

Wio Terminal 是一個基于 ATSAMD51 微控制器的完整開源開發(fā)平臺。

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

它具有 2.4 英寸 LCD 屏幕、板載傳感器和無線連接選項,使其成為各種應(yīng)用的絕佳選擇。主要功能包括:

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

高性能:配備 120MHz ARM Cortex-M4F 處理器

顯示屏:2.4 英寸 LCD 屏幕,分辨率為 320x240

連接性:通過附加模塊支持 Wi-Fi、藍牙和 LoRa

多功能 I/O:包括 GPIO、數(shù)字、模擬、I2C、UART 和 SPI 接口。

內(nèi)置傳感器:具有陀螺儀、加速度計、麥克風(fēng)和光傳感器。

使用 Wio Terminal,可以輕松擴展 Beetle ESP32 聊天機器人項目的功能,提供實時反饋和交互式顯示。

設(shè)置硬件

首先將 LED 連接到 Beetle ESP32。以下是引腳連接:

電阻器將 LED1 連接到引腳 4。

這個簡單的設(shè)置將使我們能夠通過閃爍的 LED 來可視化聊天機器人的活動。

接下來,通過 UART 將 Wio 終端連接到 Beetle ESP32:

將 Wio Terminal 的 TX 引腳連接到 Beetle ESP32 C6 的 RX 引腳。

將 Wio Terminal 的 RX 引腳連接到 Beetle ESP32 C6 的 TX 引腳。

確保連接兩個設(shè)備的接地 (GND)。

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

這個簡單的設(shè)置將允許我們通過在 Wio 終端上顯示 API 響應(yīng)來可視化聊天機器人的活動。

連接Wi-Fi

要將 Beetle ESP32 連接到 Wi-Fi 網(wǎng)絡(luò),請使用以下代碼片段:

#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"

創(chuàng)建 Web 服務(wù)器

接下來,讓我們在 Beetle ESP32 上設(shè)置一個 Web 服務(wù)器:

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



  
  
  DFRobot Chatbot
  


  
  

DFRobot Beetle ESP32 C3 Chatbot

Debug Panel

)rawliteral";

此代碼設(shè)置了一個基本的 Web 服務(wù)器,該服務(wù)器用作 HTML 頁面,用戶可以在其中輸入他們的問題。

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

處理用戶問題,首先導(dǎo)航到 Open router 并創(chuàng)建一個新的 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 代碼:

這是完整的草圖,請將憑據(jù)更改為您的憑據(jù)。

#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 獲取數(shù)據(jù)并在屏幕上打印出來。

#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);        
  }        
}

串行終端響應(yīng):

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

然后在 Web 瀏覽器中打開 IP 地址。

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

接下來,輸入提示符。

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

您可以在 Wio 終端屏幕中看到響應(yīng)。

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

如果您想查看整個 API 響應(yīng),只需按網(wǎng)站上的 Debug log 按鈕即可。這將顯示完整的 API 響應(yīng)以進行調(diào)試。

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

結(jié)論

通過此項目,您已經(jīng)使用 Beetle ESP32 和 Wio Terminal 創(chuàng)建了一個基本的聊天機器人。可以通過添加更多功能(例如更多交互式網(wǎng)頁、高級錯誤處理或集成其他 API)來進一步擴展此設(shè)置。DFRobot Beetle ESP32 C6 的緊湊尺寸和多功能功能,結(jié)合強大的 Wio 終端,使其成為各種物聯(lián)網(wǎng)應(yīng)用的絕佳選擇。

聲明:本文內(nèi)容及配圖由入駐作者撰寫或者入駐合作網(wǎng)站授權(quán)轉(zhuǎn)載。文章觀點僅代表作者本人,不代表電子發(fā)燒友網(wǎng)立場。文章及其配圖僅供工程師學(xué)習(xí)之用,如有內(nèi)容侵權(quán)或者其他違規(guī)問題,請聯(lián)系本站處理。 舉報投訴
  • 移動終端
    +關(guān)注

    關(guān)注

    1

    文章

    214

    瀏覽量

    24973
  • ESP32
    +關(guān)注

    關(guān)注

    18

    文章

    987

    瀏覽量

    17957
  • DeepSeek
    +關(guān)注

    關(guān)注

    1

    文章

    636

    瀏覽量

    431

原文標題:創(chuàng)客項目秀|基于ESP32和Wio Terminal的DeepSeeek終端

文章出處:【微信號:ChaiHuoMakerSpace,微信公眾號:柴火創(chuàng)客空間】歡迎添加關(guān)注!文章轉(zhuǎn)載請注明出處。

收藏 0人收藏

    評論

    相關(guān)推薦

    《電子發(fā)燒友電子設(shè)計周報》聚焦硬科技領(lǐng)域核心價值 第2期:2025.03.3--2025.03.7

    E907 RISC-V MCU,能夠提供高效的計算能力。 基于ESP32Wio TerminalDeepSeeek移動
    發(fā)表于 03-07 18:03

    WIO Terminal +MCP2515 實現(xiàn)車輛OBD的速度監(jiān)控

    WIO Terminal +MCP2515 實現(xiàn)車輛OBD的速度監(jiān)控
    發(fā)表于 06-14 11:05

    Wio Terminal是什么?

    有人知道Wio Terminal是什么嗎,能簡單做一下介紹嗎,它都能做些什么?
    發(fā)表于 10-07 07:11

    esp32 例程 藍牙_wifi&amp;藍牙MCU 該不該選ESP32

    ESP32是了國內(nèi)樂鑫科技推出的Wifi&藍牙物聯(lián)網(wǎng)MCU,而最近項目正好在用ESP32,所以我們今天就來分享下,如何讓你的ESP32跑起來,并應(yīng)用于更多實際
    發(fā)表于 12-06 20:06 ?31次下載
    <b class='flag-5'>esp32</b> 例程 藍牙_wifi&amp;藍牙MCU  該不該選<b class='flag-5'>ESP32</b>

    ESP32/STM32電源系統(tǒng)開源項目

    電子發(fā)燒友網(wǎng)站提供《ESP32/STM32電源系統(tǒng)開源項目.zip》資料免費下載
    發(fā)表于 07-13 09:27 ?13次下載
    <b class='flag-5'>ESP32</b>/STM32電源系統(tǒng)開源<b class='flag-5'>項目</b>

    ESP32低成本板開源項目

    電子發(fā)燒友網(wǎng)站提供《ESP32低成本板開源項目.zip》資料免費下載
    發(fā)表于 07-18 11:20 ?3次下載
    <b class='flag-5'>ESP32</b>低成本板開源<b class='flag-5'>項目</b>

    ESP32開源項目分享

    電子發(fā)燒友網(wǎng)站提供《ESP32開源項目分享.zip》資料免費下載
    發(fā)表于 08-04 14:52 ?8次下載
    <b class='flag-5'>ESP32</b>開源<b class='flag-5'>項目</b>分享

    使用ESP32制作ESP RainMaker IoT項目

    電子發(fā)燒友網(wǎng)站提供《使用ESP32制作ESP RainMaker IoT項目.zip》資料免費下載
    發(fā)表于 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終端擴展Arduboy

    電子發(fā)燒友網(wǎng)站提供《使用Wio終端擴展Arduboy.zip》資料免費下載
    發(fā)表于 11-03 09:24 ?0次下載
    使用<b class='flag-5'>Wio</b><b class='flag-5'>終端</b>擴展Arduboy

    ESP32房間項目

    電子發(fā)燒友網(wǎng)站提供《ESP32房間項目.zip》資料免費下載
    發(fā)表于 11-08 09:23 ?0次下載
    <b class='flag-5'>ESP32</b>房間<b class='flag-5'>項目</b>

    ESP32 UWB室內(nèi)定位測試開源項目

    電子發(fā)燒友網(wǎng)站提供《ESP32 UWB室內(nèi)定位測試開源項目.zip》資料免費下載
    發(fā)表于 06-14 10:56 ?9次下載
    <b class='flag-5'>ESP32</b> UWB室內(nèi)定位測試開源<b class='flag-5'>項目</b>

    使用Wio Terminal和Tensorflow Lite創(chuàng)建智能氣象站

    電子發(fā)燒友網(wǎng)站提供《使用Wio Terminal和Tensorflow Lite創(chuàng)建智能氣象站.zip》資料免費下載
    發(fā)表于 06-25 10:30 ?0次下載
    使用<b class='flag-5'>Wio</b> <b class='flag-5'>Terminal</b>和Tensorflow Lite創(chuàng)建智能氣象站

    基于ESP32的開源項目

    電子發(fā)燒友網(wǎng)站提供《基于ESP32的開源項目.zip》資料免費下載
    發(fā)表于 07-03 10:29 ?3次下載
    基于<b class='flag-5'>ESP32</b>的開源<b class='flag-5'>項目</b>

    Seeed Wio終端開源分享

    電子發(fā)燒友網(wǎng)站提供《Seeed Wio終端開源分享.zip》資料免費下載
    發(fā)表于 07-12 10:04 ?0次下載
    Seeed <b class='flag-5'>Wio</b><b class='flag-5'>終端</b>開源分享

    ESP32開源項目

    電子發(fā)燒友網(wǎng)站提供《ESP32開源項目.zip》資料免費下載
    發(fā)表于 07-13 10:47 ?6次下載
    <b class='flag-5'>ESP32</b>開源<b class='flag-5'>項目</b>

    電子發(fā)燒友

    中國電子工程師最喜歡的網(wǎng)站

    • 2931785位工程師會員交流學(xué)習(xí)
    • 獲取您個性化的科技前沿技術(shù)信息
    • 參加活動獲取豐厚的禮品