RN-42 HID MOUSE

First,i used Google Translator.

I am making a glove mouse with Arduino Leonardo, RN-42 HID, flexible sensor, gyroscope sensor.

The USB connection is already confirmed to operate normally, but mouse does not work when communicating with RN-42 HID.

Gyroscopes value seems to be delivered to a computer but Mouse.begin() function does not seem to work.

thank you for any help.

Post your code if you want help with code.

I would suggest trying a simple sketch to only try moving the mouse - no sensors, and first try to make that work - then add the sensors.

#include <SoftwareSerial.h>
#include <Wire.h>
#include "Kalman.h"

#define BT_RX 10
#define BT_TX 11

#define PORATE 115200

int16_t gyroX, gyroY;
int F1 = A3;
int F2 = A4;
int F3 = A5;

int Sensitivity = 600;

SoftwareSerial bluetooth(BT_RX, BT_TX);

uint32_t timer;
uint8_t i2cData[14]; // Buffer for I2C data

void setup() {
Serial.begin(PORATE);
bluetooth.begin(PORATE);
Wire.begin();
i2cData[0] = 7; // Set the sample rate to 1000Hz - 8kHz/(7+1) = 1000Hz
i2cData[1] = 0x00; // Disable FSYNC and set 260 Hz Acc filtering, 256 Hz Gyro filtering, 8 KHz sampling

i2cData[3] = 0x00; // Set Accelerometer Full Scale Range to ±2g
while(i2cWrite(0x19,i2cData,4,false)); // Write to all four registers at once
while(i2cWrite(0x6B,0x01,true)); // PLL with X axis gyroscope reference and disable sleep mode
while(i2cRead(0x75,i2cData,1));
if(i2cData[0] != 0x68) { // Read "WHO_AM_I" register
Serial.print(F("Error reading sensor"));
while(1);
}

delay(100); // Wait for sensor to stabilize

/* Set kalman and gyro starting angle */
while(i2cRead(0x3B,i2cData,6));
timer = micros();

Mouse.begin();
}

void loop() {
/* Update all the values */
int FR1 = analogRead(F1);
int FR2 = analogRead(F2);
int FR3 = analogRead(F3);
while(i2cRead(0x3B,i2cData,14));
gyroX = ((i2cData[8] << 8) | i2cData[9]);
gyroY = ((i2cData[12] << 8) | i2cData[13]);

gyroX = gyroX / Sensitivity; /* 1.1 * -1;/
gyroY = gyroY / Sensitivity; /
-1;*/

Serial.print("\t");
Serial.print(gyroX);
Serial.print(gyroY);
Serial.print(F("digtal\n"));
Serial.print(FR2);

Mouse.move(-gyroX, gyroY);

Serial.print("\r\n");
delay(3);
if(FR2>700)
{
Mouse.press(MOUSE_LEFT);
delay(100);
}
else
Mouse.release(MOUSE_LEFT);

}

here is my code

Did you configure your RN-42 to HID mode first before doing this? And you don't need to use mouse.move commands. You need to send HID mouse reports in this Format

// This is what the HID report should consist
buffer[0] = 0xFD; //Setting to HID Mouse mode
buffer[1] = 0x05; //Setting to HID Mouse mode
buffer[2] = 0x02; //Setting to HID Mouse mode
buffer[3] = 0x00; //Buttons
buffer[4] = byte( xsend ); //X-stop
buffer[5] = byte( ysend ); //Y-stop
buffer[6] = 0x00; //mouseWheel