Read ESP8266 serial console with Arduino UNO

Posted on
  • Hello, I am trying to read ESP-01 (ESP8266) Espruino log with Arduino UNO by serial and not works correctly.

    My Arduino UNO code:

    [#include](https://forum.espruino.com/se­arch/?q=%23include) <SoftwareSerial.h>
    SoftwareSerial mySerial(0, 1); // RX, TX
     
    void setup() {
      //Init serial ports
      Serial.begin(9600);
      mySerial.begin(115200);
    
      Serial.println("Hello from arduino");
    
      delay(5000);
    }
     
    void loop(){
     String IncomingString = "";
     boolean StringReady = false;
     
     while (mySerial.available()){
       IncomingString = mySerial.readString();
       StringReady =  true;
      }
     
      if (StringReady){
        Serial.println("Received String: " + IncomingString);
      }
    }
    

    Espruino code:

    var wifi = require("Wifi");
    var http = require("http");
    wifi.connect('YYYY', {password:'XXXX'}, function(e) {
      if (e) {
        console.log('error during connect:',e);
        wifi.disconnect();
      } else {
        console.log('connected to wifi');
        wifi.stopAP();
        //wifi.save();
        http.get("https://jsonplaceholder.typico­de.com/posts/1", function(res) {
          res.on('data', function(data) {
            console.log(data);
          });
        });
      }
    });
    

    Actual arduino uno log: Screenshot in attachments

    Excepted log:

    connected to wifi
    {
      "userId": 1,
      "id": 1,
      "title": "sunt aut facere repellat provident occaecati excepturi o
    ptio reprehenderit",
      "body": "quia et suscipit\nsuscipit recusandae consequuntur expedita et cum\nreprehenderit molestiae ut ut quas totam\nnostrum rerum est autem sunt rem eveniet architecto"
    }
    

    1 Attachment

    • Screenshot 2022-05-28 at 15.52.12.png
  • Your Adruino code looks complicated, and I'm not sure if it's correct, or if you're overwriting the variable IncomingString in the while loop.

    The sample code for serial input from https://www.javatpoint.com/arduino-seria­l-available:

    void loop( ) // loop function that executes repeatedly  
    {  
    if(Serial.available( ) > 0) //  It will only send data when the received data is greater than 0.  
    {  
    arrivingdatabyte = Serial.read( );  // It will read the incoming or arriving data byte  
    Serial.print("data byte received:");  
    Serial.println(arrivingdatabyte, DEC); // here, DEC means Decimal  
    }  
    }  
    

    I'd suggest to remove the while and the true/false in your code, and change it according to the sample code.

  • Post a reply
    • Bold
    • Italics
    • Link
    • Image
    • List
    • Quote
    • code
    • Preview
About

Read ESP8266 serial console with Arduino UNO

Posted by Avatar for user144453 @user144453

Actions