Go Down

Topic: PS2 and Serial (Read 764 times) previous topic - next topic

WhoseTheNerd

I'm making arduino trackpad, aka convert ps2 to usb. I have problem that serial communication is not working when ps2 is doing something, when I comment out ps2 commands in loop function then it works Serial communication works perfectly. I tried with Serial and SerialUSB, no luck.

Code: [Select]
#include <Mouse.h>
#include <ps2.h>

#define PS2_DATA 10
#define PS2_CLK 9

PS2 mouse(10, 9);

void setup() {
  mouse.write(0xff); // Reset
  mouse.read(); // ACK byte
  mouse.read(); // Blank
  mouse.read(); // Blank
  mouse.write(0xf0); // Remote mode
  mouse.read(); // ACK
  delayMicroseconds(100);
  //Mouse.begin();
  SerialUSB.begin(9600);
  while (!SerialUSB);
  SerialUSB.println("Hello!");
}

void loop() {
  char mstat;
  char mx;
  char my;
  char mz;

  mouse.write(0xeb); // Give me data
  mouse.read(); // Ignore ack
  mstat = mouse.read();
  mx = mouse.read();
  my = mouse.read();
  mz = mouse.read();

  SerialUSB.print("X: ");
  SerialUSB.print(mx);
  SerialUSB.print(" Y: ");
  SerialUSB.print(my);
  SerialUSB.print(" Z: ");
  SerialUSB.println(mz);
  SerialUSB.flush();
  delay(1000);

  //Mouse.move(mx, -my);
}

groundFungus

#1
Jan 27, 2020, 05:48 am Last Edit: Jan 27, 2020, 05:49 am by groundFungus
What Arduino board?  A wiring diagram may be helpful.

Go Up