Interface USB Mouse to your Arduino using CH375B

CH375B module. It is usually supplied with a 2 way jumper mounted on TXD and RXD pin.
The TXD RXD pins are located next to the female USB receptacle. Please unmount the jumper before use.
  1. Get the following components:
    1. Arduino Nano
    2.  Male to female jumper wires  - 4 pieces
    3. USB Mouse
    4. CH375B module
  2. Download MeUsb.cpp and MeUsb.h from https://github.com/xeecos/Me-USB-Host
  3. On your Windows computer which already has arduino installed, go to your documents folder. There you will find a folder called arduino and within that another folder called libraries. Inside this libraries folder create a new folder called "MeUsb"
  4. Place MeUsb.cpp and MeUsb.h in this folder
  5. In the arduino\libraries folder, create another folder called "SoftwareSerial_fix"
  6. And in this folder download and place SoftwareSerial_fix.cpp and SoftwareSerial_fix.h from the same link as above.
  7. Assemble the circuit on the bread board as follows:
    1. +5V of Arduino Nano to +5V of CH375B
    2. GND of Arduino Nano to GND of CH375B
    3. D10 of Arduino Nano to TXD of CH375B
    4. D9 of Arduino Nano to RXD of CH375B 
      Connecting the CH375B to Arduino Nano

      Connecting the CH375B to Arduino Nano
  8. Start arduino and open a new sketch. Copy the source code into it and download it into the arduino nano.
  9. Once the code is downloaded successfully, start serial monitor on your PC with baud rate set to 115200 and observe the pattern of 4 bytes that are being received.
    Every time you move the mouse, 4 bytes are sent to the Arduino Nano.
    You will observe that there are 4 bytes being printed on the serial monitor. Here are what those 4 bytes mean:
Deciphering the 4 bytes received from CH375B when a mouse is connected to it
You can CH375B module in India from www.vishaworld.com

To interface a USB Joystick, have a look at Me-USB-Host.ino available at https://github.com/xeecos/Me-USB-Host

Source Code to interface USB Mouse.


#include <Arduino.h>
#include "SoftwareSerial_fix.h"
#include "MeUsb.h"

MeUsb usb(10,9);

void setup() 
{
   Serial.begin(115200); 
   usb.init(USB1_0);
}

void loop()
{
  if(!usb.device_online)
  {
    usb.probeDevice(); 
    delay(100);
  }
  else
  {
    int len = usb.host_recv();
    if (len == 4){
      Serial.print(usb.RECV_BUFFER[0],DEC);
      Serial.print(',');
      Serial.print(usb.RECV_BUFFER[1],DEC);
      Serial.print(',');
      Serial.print(usb.RECV_BUFFER[2],DEC);
      Serial.print(',');
      Serial.print(usb.RECV_BUFFER[3],DEC);
      Serial.print('\n');
    }
  }
}

Comments

  1. Hi Anurag,
    Very Nice and simple Tutorial!

    I have got a question though.

    I have tried it with 2 different mice (1 hp which works, and a cheap chines mouse which doesn't work)

    Do you have any idea why the 2nd mouse wouldn't work?
    Is there firmware in the CH375 that recognises the mouse, and if it doesn't recognise it, Then it is tough luck?

    Or should it work with all USB devices (I really like to use it with an old USB touchscreen (Which doesn't give any reaction)

    Regards,
    Albert

    ReplyDelete
  2. Hey Albert,
    No idea as to why the second mouse is not working.
    You can try connecting your second mouse to your windows PC and use some USB packet sniffer like:
    http://www.eltima.com/products/usb-port-monitor/

    and check if it is sending the same packets as the first mouse.

    ReplyDelete
  3. hello sir,,how can i use this module with avr and copy bmp image through this,,please give instructions.. thank you :-)

    ReplyDelete
  4. Fix you shared code --> if (len == 4){ to if (len != 0){

    ReplyDelete
  5. how to write into pendrive sensor value

    ReplyDelete
  6. I think you should use CH376 chip for writing to USB Flash drives:
    https://www.mpja.com/download/ch376ds1.pdf

    ReplyDelete
  7. Hello i wanted to write the sensor value to the pen drive. i am not able to do it

    ReplyDelete
  8. i have already purchased CH375B

    ReplyDelete
  9. We are also getting the same issue.......i too can't create file or write data to USB Pendrive....kindly advice me

    ReplyDelete
  10. i tried to do this but only prints "101" several times

    ReplyDelete
  11. This comment has been removed by the author.

    ReplyDelete
  12. Thank you for the example.
    It took me 1 week to get it working.
    Thge problem seems to be in using a Chinese clone Arduino. With a very old original Uno it works!
    Butonly with 1 mouse (logitech), not the HP one. And you must move the mouse to get data.
    But... now I can start working on the USB serial protocol I need to get my Dream Cheeky Thunder working :)

    I wondered what you changed in the Software Serial library. I had a look at the differences but it puzzles me. I thought you added the extra 9th bit needed for communicating with the 375 I cannot find that. Could you elaborate please?

    ReplyDelete
  13. s it possible to read a keyboard with this module?

    ReplyDelete
  14. Jose,

    I got some response from a keyboard (not all I tried). But I think there is still some stuff missing. That might be the reasin that no all mouses work properly.
    Someone with more experience with USB HID could maybe elaborate.
    If I find time I will try to dive into the subject because the chip itself is capable of connecting to most USB devices.

    ReplyDelete
  15. Hello this is an interesting find.
    I have an interesting idea for a project and I'm wondering if this will work and whether I would need an Arduino in the middle after it is all set up.
    I have two Logitech trackball mice and there's only one slight problem.... I only have two USB ports on this laptop so if I plug in the Logitech dongle I lose one whole port. Yes I know a hub will work but that's a whole set of dongle's and cables to get out every time I want to use the mouse.
    Plus there's bandwidth limitations and everything says "you shouldn't use audio interfaces, etc with a hub".
    I have only run into that issue once (bandwidth) but most of my concern is multiple points of failure.
    So since the mouse dongle shows up as a generic mouse without the software loaded, I would love to pipe that data over Bluetooth since its built-in and then just have it show up as a Bluetooth mouse.
    It is at this point where I say yes Logitech came out with a track ball mouse that has Bluetooth finally and it is really nice but it was $$ and it's a little flaky with my Computer with older Bluetooth and has a version 4+ limitation.
    So I'm thinking taking the dongle(s) and plugging it into a socket connecting to a Bluetooth module in maybe like a stick of gum pack size container with a little battery. But I need the program glued to connect that all together.

    reRereading this it sounds ramblly, I don't know how to fix it. I hope it makes sense?

    ReplyDelete
  16. Good Day all ,
    Does any know if it is possible to use the Ch376 or CH375 to be able to host a CH340 Serial com port?
    Effectively i am trying to achieve this
    https://www.hobbytronics.co.uk/usb-host-serial

    ReplyDelete
  17. Hi, i am trying to read the data of my optical usb mouse but the serial monitor spits out a constant value "37", I am using an arduino Nano with the same usb module. Any help is appreciated. It is a bit urgent, i am working on a project so, do reply.

    ReplyDelete
  18. hi, can i with the same module do as a recive data from a sensor than try to send the data to a txt file or csv to save it in a usb flash memory

    ReplyDelete
  19. I tried this with ch376s, it does not work, what should I change before trying this code? or does this setup work with ch376s at all?

    ReplyDelete

Post a Comment

Popular posts from this blog

Replacing the current sense resistor in Portable Chargers/Power Banks for powering low power DIY projects.

Simple TCP client server sockets application using IPv6 and IPv6