Serial(UART) Communication between Arduino Mega and NodeMCU ESP8266 using johnny five / Firmata js

788 Views Asked by At

I'm making a project wherein I wanted to make the two devices communicate (Arduino Mega and NodeMCU respectively) which the Arduino Mega can send data via serial comm.(UART) to the NodeMCU. The NodeMCU acts as a bridge which has a Firmata in it(standardFirmataWifi) and it is connected to a wifi.

I've connected the Mega's RX0 (pin 0) and TX0 (pin 1) to my NodeMCU's RX (pin 21) and TX (pin 22).

I also made a web app that can receive / control a device connected on the Arduino Mega via the NodeMCU.

But for now I just make it simple and receive some data coming from the Arduino Mega.

Here is my code :

var EtherPortClient = require("etherport-client").EtherPortClient;
var board = new Firmata(new EtherPortClient({
  host: "ip_hostname",
  port: 3030
}));
    board.on("ready", () => {
      console.log("READY");

      const HW_SERIAL0 = board.SERIAL_PORT_IDs.HW_SERIAL0;


      board.serialConfig({
        portId: HW_SERIAL0,
        baud: 115200
      });

      board.serialRead(HW_SERIAL0, (data) => {
        console.log(Buffer.from(data).toString('ascii'));
    console.log('Serial port reading');
      });
      board.on('string', (message) => { console.log(message) });
      console.log('Connected board...');
    }); 

I'm using the Firmata.js library here. Supposedly it should be johnny-five since I can't get the UART ports of the NodeMCU using johnny-five, I use the latter. (I'm kinda bit new using these library though but not the language used.)

The only problem is that it doesn't show the data readings coming from the Serial port. It only displays the these.

    READY 
    Connected board...

I'm expecting that it should display like these :

   READY
   Serial port reading
   *message from the serial reading*
   Connecting board...

I'm thinking the problem is within my serial configuration itself???

0

There are 0 best solutions below