Hello everyone
I am currently working on controlling multiple tablets with a single keyboard and using Arduinos to get everything to talk. I currently have an Arduino Due acting as the USB host for the keyboard, which is working fine. I then have an Arduino Pro Micro pretending to be the keyboard at the tablet end, which is also working fine. The problem is getting them to talk to each other over serial.
Currently I am using the following code on each board.
This is the Due code. Whenever it receives a key press from the keyboard it sends the keypress info out on the first serial port TX1. It also prints to the serial monitor on the computer. Both appear to be working correctly (computer serial monitor shows correct decimal ascii codes for each key pressed, oscilloscope on TX line shows a byte transmitted whenever a key is pressed.)
#include <address.h>
#include <adk.h>
#include <confdescparser.h>
#include <hid.h>
#include <hidboot.h>
#include <hidusagestr.h>
#include <KeyboardController.h>
#include <MouseController.h>
#include <parsetools.h>
#include <Usb.h>
#include <usb_ch9.h>
//#include <Keyboard.h>
bool LED;
// Initialize USB Controller
USBHost usb;
// Attach Keyboard controller to USB
KeyboardController keyboard(usb);
void setup() {
  Serial.begin(9600);
  Serial1.begin(9600);
}
void loop(){
 usb.Task();
}
void keyPressed() {
 Serial.print("Pressed: ");
 Serial.print(keyboard.getKey());
 Serial1.write(keyboard.getKey());
 Serial.println();
}
Now here is the code that I am using to monitor the incoming received serial messages on the Pro Micro. It is literally just printing whatever is received directly to the serial monitor. Also I made it so that if pin 8 goes high it just sends the message "Button" to the serial monitor so that I can check if it is working correctly.
void setup()
{
 Serial.begin(9600);
}
void loop()
{
  if (digitalRead(8)) {
   Serial.print ("Button");
   Serial.println();
  }
}
void serialEvent() {
 while (Serial.available()) {
  char inChar = (char)Serial.read();
  Serial.print (inChar);
  Serial.println();
  }
 }
I also am using a CD4051 as a level shifter (it's what I had at hand) since the Due is a 3.3V device and the Pro Micro is a 5V device. The output signal looks to be quite clean, going quickly between 0-5V. Just to be safe I tried the circuit without the level shifter and it still didn't work so I doubt that it is the cause of my problems.
Anyways when I have the two arduinos hooked up, Due Tx1 -> level shifter -> Pro Micro Rx1 I get nothing on the serial monitor, even though my test "button" on the Pro Micro works and when I scope the signal going into Rx on the Pro Micro it appears to look healthy.
Since this is such a simple set up I am guessing that I made a stupid mistake. I am a little new to serial communication on the Arduino so I am basically copy-pasting from example codes. Can one of you arduino wizards out there see what I may have overlooked?
Thank you!