Here is the code I am currently using Serial1
#include <Wire.h>
#include "I2Cdev.h"
#include <PMW3360.h>
#include <BPLib.h>
#include <SoftwareSerial.h>
// Mouse Movement Variables
#define SS 17 // Slave Select pin. Connect this to SS on the module
PMW3360 sensor;
const unsigned long accumulationTime = 10; // Accumulate data for --- milliseconds
const int sensitivity = 500;
const int DPI = 400;
// Bluetooth Variables
// Bluetooth Variables
#define RX_PIN 90 // connect to TXD of module
#define TX_PIN 101 // connect to RXD of module (logic level 3.3v!)
SoftwareSerialSerial1 swSer(RX_PIN, TX_PIN, false); // Only three arguments
BPLib *BPMod;
void setup()
{
Serial.begin(9600);
swSerSerial1.begin(9600); // Set the baud rate for softwarehardware serial
BPMod = new BPLib(swSerSerial1);
BPMod->begin(BP_MODE_HID, BP_HID_MOUSE);
if (sensor.begin(SS)) // Initialize the PMW3360 sensor
{
Serial.println("Sensor initialization succeeded");
}
else
{
Serial.println("Sensor initialization failed");
}
sensor.setCPI(DPI);
//Mouse.begin();
}
void loop()
{
float Acc_X = 0;
float Acc_Y = 0;
bool movementDetected = false;
unsigned long startTime = millis(); // Record the start time
// Accumulate readings for the --- duration
while (millis() - startTime < accumulationTime) {
PMW3360_DATA data = sensor.readBurst();
if (data.isOnSurface && data.isMotion) {
float mdx = constrain(data.dx, -127, 127);
float mdy = constrain(data.dy, -127, 127);
Acc_X += mdx;
Acc_Y += mdy;
movementDetected = true;
}
}
Acc_X /= DPI;
Acc_Y /= DPI;
// Move the mouse based on accumulated values if movement was detected
if (movementDetected) {
BPMod->mouseMove(-Acc_X * sensitivity, Acc_Y * sensitivity);
//Mouse.move(-Acc_X * sensitivity, Acc_Y * sensitivity);
}
}