I am currently using an RN-42 Bluetooth module with an Arduino Micro and have successfully connected the RN-42 in HID mode to my PC, where it is recognized as a Mouse. For Bluetooth communication, I am utilizing the BPLib library (https://github.com/witnessmenow/BPLib). However, I am encountering an issue: when rolling the ball on my trackball, there is no detected movement. This same setup works perfectly when connected via a wired solution using the Mouse library on the Arduino. I am unsure of the source of the problem.
Current code, I am using
#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
#define RX_PIN 9 // connect to TXD of module
#define TX_PIN 10 // connect to RXD of module (logic level 3.3v!)
SoftwareSerial swSer(RX_PIN, TX_PIN, false); // Only three arguments
BPLib *BPMod;
void setup()
{
Serial.begin(9600);
swSer.begin(9600); // Set the baud rate for software serial
BPMod = new BPLib(swSer);
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);
}
}```
Anyone point out the problem with the code or any useful information. I am having hard time figure out the problem.