This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

Arduino + Accel/Gyro + nRF8001 HID Mouse

Hi,

For the past few weeks I've been trying to make a small device that would simulate a mouse with Arduino and MPU6050 accelerator + gyroscope sensor. I wanted the device to run on batteries and the communication to be done via Bluetooth LE, so I searched for Bluetooth chips with HID capability and stumbled upon nRF8001. It seemed the perfect chip for my project because of its small form factor, the compatibility with Arduino and easy to use examples and template.

After couple of days working with the chip I had successfully paired/connected the device with my Android phone and got basic mouse movements with the device. The problem was that the movement of the mouse pointer was abrupt/stuttering(!?) or in other words it wasn't moving as a mouse should move. The first thing I suspected was the values I get from the MPU6050 sensor, so I tried to test the sensor with Atmega32U4 Arduino via Serial on Windows 7, and it was working like a charm. So I tried another experiment with 2 NRF24L01+ modules, one on the device itself and the other attached to Atmega32U4 Arduino that would act as a dongle connected to the PC, and again the results were amazing. So that led me to suspect my Bluetooth LE setup, because this is my first experience with Bluetooth LE and I was hoping that I might get some help or directions here. I think it has something to do with the data transfer rate.

The code I am using is the same as the template provided by Nordic except for the method for sending HID reports where I'm using the values I get from the MPU6050 instead of the analog values for joystick:

if (lib_aci_is_pipe_available(&aci_state, PIPE_HID_SERVICE_HID_REPORT_ID2_TX)
  && (aci_state.data_credit_available > 0) )  {

uint8_t mouse[3] = {0, 0, 0};

mouse[0] = 0;                  //Button
mouse[1] = sensor.x;           //X axis
mouse[2] = sensor.y;           //Y axis

lib_aci_send_data(PIPE_HID_SERVICE_HID_REPORT_ID2_TX, &mouse[0], 3);
aci_state.data_credit_available--;  }

I'm generating the services.h, services_lock.h and ublue_setup.gen.out.txt files with the hid_mouse_batt_nordic_works.xml also provided by Nordic.

P.S. I have seen the video for nRFready µBlue Smart Remote which uses the nRF8001, and it does exactly what I want to achieve with my device, so theoretically it can be done.

Related