0

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???

Maximus
  • 111
  • 6
  • *I've connected the Mega's RX0 (pin 0) and TX0 (pin 1) to my NodeMCU's RX (pin 21) and TX (pin 22).* Does that mean RX0 to RX and TX0 to TX? – Marcos G. Dec 09 '19 at 10:35
  • @MarcosG. Yes it is. Wait... so to say, RX0 to TX and TX0 to RX is the correct connection? right? – Maximus Dec 09 '19 at 10:40
  • yes, that's correct, RX to TX and vice-versa. You might need to connect GND to GND if you have battery power devices or you are powering them from isolated power supplies – Marcos G. Dec 09 '19 at 10:44
  • I had connected them properly now , but still doesn't display the right data output from my terminal – Maximus Dec 09 '19 at 10:52
  • It's not easy to pinpoint what is wrong with your setup. Maybe you can first follow a simplified tutorial to make sure everything is working. Have you looked at [this](http://www.acraigie.com/programming/firmatavb/default.html) or [this](https://forum.arduino.cc/index.php?topic=605324.0) – Marcos G. Dec 09 '19 at 11:09
  • @MarcosG. the latter one. yes. but I wanted to make my nodemcu act as a bridge between the two, like arduino can send or receive data and that data will be coming from/to that brdige which has a firmata in it, and that data will be parsed and pass it to the web app and vice versa. arduino <<=send/receive= >> NodeMCU(with Firmata protocol)<<==parse== >> WebApp(using Firmata js) – Maximus Dec 09 '19 at 11:22
  • OK, then you know that both serial ports work, right? I think you need to go one by one checking the links on that chain. I think there are some things missing from your NodeMCU code – Marcos G. Dec 09 '19 at 13:27

0 Answers0