1

I am working with an arduino pro micro and I am facing a peculiar problem. The project I am working with includes arduino MKR NB 1500 as well. I am transferring data from MKR NB 1500 to arduino pro micro through Serial1(Rx/Tx pins). I have added the sample code that i am using on both boards

program in arduino MKR NB 1500

void setup() {
  Serial1.begin(9600);
}
void loop() {
  Serial1.print("printing");
  delay(2000);
}

program in pro micro

#include "Keyboard.h"

void setup() { Serial1.begin(9600); Keyboard.begin(); }

void loop() { Keyboard.write(Serial1.read()); }

I would like to transfer some data from MKR NB 1500 to pro micro which emulates a keyboard and prints the data in a editor. I am powering the arduino MKR NB 1500 via USB using its native USB port. The pro micro works as expected when I connect both these boards to USB ports in the same laptop. (Output: printingprintingprintingprinting)

However, the pro micro prints garbage values when I connect the MKR NB 1500 to a USB port belonging to a different laptop. (Output: a10joh<qqj<zstjo)

Is there any reason for such a behavior. Please let me know if you need more information from my side or if i have not made myself clear.

sud.ng7
  • 31
  • 5

1 Answers1

1

You have to connect ground between the modules. Without common ground the logic level of signal can't be measured. While both boards were powered over USB from the same laptop the boards had common ground.


read returns -1 if nothing is available so check if some character was received:

void loop() {
  if (Serial1.available()) {
    Keyboard.write(Serial1.read());
  }
}

btw: The MKR can emulate a keyboard too with the Keyboard library.

Juraj
  • 18,264
  • 4
  • 31
  • 49