1

I am using RN-42 with Arduino Micro and able to connect RN-42 in HID mode and it's connected to the PC as Mouse. I am using BPLib (https://github.com/witnessmenow/BPLib) for Bluetooth communication. I am not sure where I am making a mistake as whenever I roll the ball on my trackball there is no movement detected. But it is working fine when using it as a wired solution with a mouse library with Arduino.

Here is the code using Serial1

#include <Wire.h>
#include "I2Cdev.h"
#include <PMW3360.h>
#include <BPLib.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 0 // connect to TXD of module #define TX_PIN 1 // connect to RXD of module (logic level 3.3v!)

Serial1 swSer(RX_PIN, TX_PIN, false); // Only three arguments BPLib *BPMod;

void setup() { Serial.begin(9600);
Serial1.begin(9600); // Set the baud rate for hardware serial BPMod = new BPLib(Serial1); 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 could help to solve the issue? or point out where I am making a mistake.

Abubakar
  • 39
  • 2

0 Answers0