簡體   English   中英

esp8266和atmega328p之間的串行通信

[英]Serial communication between esp8266 and atmega328p

我在esp8266上運行了一個Web服務器。

代碼在這里:

#include <ESP8266WiFi.h>
#include <WiFiClient.h>
#include <ESP8266WiFiMulti.h> 
#include <ESP8266mDNS.h>
#include <ESP8266WebServer.h>

#include "index.h"
#include "login.h"

ESP8266WiFiMulti wifiMulti;     // Create an instance of the ESP8266WiFiMulti class, called 'wifiMulti'

ESP8266WebServer server(80);    // Create a webserver object that listens for HTTP request on port 80

void handleRoot();              // function prototypes for HTTP handlers
void handleLogin();
void handleNotFound();

void setup(void){
  Serial.begin(115200);         // Start the Serial communication to send messages to the computer
  delay(100);

  wifiMulti.addAP("DIGISOL", "edot2017");   // add Wi-Fi networks you want to connect to
  Serial.println("Connecting ...");
  while (wifiMulti.run() != WL_CONNECTED) { // Wait for the Wi-Fi to connect: scan for Wi-Fi networks, and connect to the strongest of the networks above
    delay(250);
    Serial.print('.');
  }
  Serial.println('\n');
  Serial.print("Connected to ");
  Serial.println(WiFi.SSID());               // Tell us what network we're connected to
  Serial.print("IP address:\t");
  Serial.println(WiFi.localIP());            // Send the IP address of the ESP8266 to the computer

  server.on("/", HTTP_GET, handleRoot);        // Call the 'handleRoot' function when a client requests URI "/"
  server.on("/login", HTTP_POST, handleLogin); // Call the 'handleLogin' function when a POST request is made to URI "/login"
  server.on("/back",HTTP_POST,handleRoot);
  server.onNotFound(handleNotFound);           // When a client requests an unknown URI (i.e. something other than "/"), call function "handleNotFound"

  server.begin();                            // Actually start the server
  Serial.println("HTTP server started");
}

void loop(void){
  server.handleClient();                     // Listen for HTTP requests from clients
}

void handleRoot() {                          // When URI / is requested, send a web page 
  String indexPage = MAIN_page;
  server.send(200, "text/html",indexPage);
}

void handleLogin() {                         // If a POST request is made to URI /login
  String message = "";        
  if( ! server.hasArg("data") || server.arg("data") == NULL ){ // If the POST request doesn't have username and password data
    server.send(400, "text/plain", "400: Invalid Request");         // The request is invalid, so send HTTP status 400
    return;
  }
  else
  {
      message += server.arg("data");  //Get the name of the parameter
      Serial.println(message);
      String loginpage = LOGIN_PAGE;
      server.send(200, "text/html",loginpage);
  }
}
void handleNotFound(){
  server.send(404, "text/plain", "404: Not found"); // Send HTTP status 404 (Not Found) when there's no handler for the URI in the request
} 

然后,我有一個草圖可以在ledp10顯示屏上顯示一條消息,該消息運行正常。

ledp10顯示消息代碼:

#include <SPI.h>
#include <DMD2.h>
#include <fonts/SystemFont5x7.h>
#include <fonts/Arial14.h>
#include <fonts/Droid_Sans_24.h>
#include <fonts/Droid_Sans_16.h>
// Set Width to the number of displays wide you have
const int WIDTH = 1;
const int COUNTDOWN_FROM = 0;
int counter = COUNTDOWN_FROM;
// You can change to a smaller font (two lines) by commenting this line,
// and uncommenting the line after it:
const uint8_t *FONT = SystemFont5x7;
const uint8_t *FONT2 = SystemFont5x7;

const char *MESSAGE = "GOA";

SoftDMD dmd(WIDTH,1);  // DMD controls the entire display
DMD_TextBox box(dmd, 0, 1);
DMD_TextBox box1(dmd,11,1);  // "box" provides a text box to automatically write to/scroll the display

// the setup routine runs once when you press reset:
void setup() {
  Serial.begin(9600);
  dmd.setBrightness(255);
  //dmd.selectFont(FONT);
  dmd.begin();  
}

// the loop routine runs over and over again forever:
void loop() {
  dmd.selectFont(FONT);
  box.print(counter);
  dmd.selectFont(FONT2);
  const char *next = MESSAGE;
 while(*next) {
  Serial.print(*next);
  box1.print(*next);
  delay(500);
  next++;
  }
    box.println(F(""));
    counter++;
    if(counter == 60) {
    dmd.clearScreen();
    counter = 0;
  }
}

現在我需要在esp8266和atmega328p之間進行通信。 即,在網頁上發送的消息需要顯示在ledp10顯示屏上。 我該怎么辦?

請僅在esp8266和atmega328p之間的串行通信中提供幫助。

修改LCD Atmega草圖以從串行監視器接收文本。

然后將esp8266連接到Atmega的Serial,Atmega草圖將在esp草圖中接收您打印到Serial的文本

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM