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.

9
  • 1
    Have you connected the grounds? Also you should check Serial1.available() on the pro micro.
    – Majenko
    Oct 20 at 14:49
  • 1
    Thank you for your response. Connecting the grounds seems to be working, i will do few more tests. Could you please let me know why this is the case. I am new to working with arduino it would be helpful in the future.
    – sud.ng7
    Oct 20 at 15:03
  • majenko.co.uk/blog/our-blog-1/…
    – Majenko
    Oct 20 at 15:04
  • 1
    The data I would like to transfer to pro micro comes from the barcode scanner.
    – sud.ng7
    Oct 20 at 15:22
  • 1
    Ground is the reference point for the microcontrollers to measure and output voltage. The actual place of their ground (as electrical potential) may be different, so the output voltage of the other microcontroller will not make much sense. When connecting the grounds you make sure, that both microcontrollers use the same reference point and thus can talk to each other
    – chrisl
    Oct 20 at 17:05
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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.