|
arduino IDEArduino
|
|
|
OrCad Cadance |
Raspberry Pi Pico as HID Mouse
Hello Everyone.
So here's a fun little project that tackles a major issue with the Raspberry Pi Pico Microcontroller.
The Raspberry Pi Pico's pinout information is located on the bottom side of the board, which makes prototyping difficult. When we mount the device on a breadboard, we have to utilize a reference guide to determine which pins are whose, which is a messy procedure.
All the pinout details are on the top side of the expansion board I made. To showcase the Pico's HID capabilities, we connect it to an extension board and utilise it to build a simple mouse.
This Expansion board have extra 4 pins for each GPIO pins and have few extra pins on both sides which are not connected to anything, these are for placement of XYZ components for making quick prototypes.
Now that we know how to use this expansion board, let's get started with the article's discussion of the entire process.
Material required
Following are the materials used in this built-
- RPi Pico
- Custom PCB (which was provided by PCBWAY)
- Push Buttons
- Connection wires
- PCB Standoffs
Expansion board Design
The expansion board was designed by keeping a few things in mind which were the extra GPIO Pins for each Pin and a few extra con pins for adding stuff, another thing was that GPIO Number Details on the Topside were nice and clear.
The project's schematic was incredibly straightforward; I simply duplicated a Pico design in my CAD software and connected a CON4 pin to each of the Pico's GPIO pins.
I created a PCB design from the PCB schematic and included a hybrid pad for Pico's placement that contains a hole for header pins and a pad for mounting Pico as an SMD module on the PCB.
PCBWAY
I sent the finished PCB to PCBWAY for samples and receive them after a week.
White Soldermask with Black Silkscreen was chosen for the order since it generally makes PCBs seem beautiful.
In terms of overall quality, it was outstanding. Each of the 10 boards I bought was flawless.
I've been using their service for a while, and I must say that the PCBs I received was excellent, just as I had hoped.
Check out PCBWAY for getting great PCB service for an economic price and high quality!
Board Assembly
- Board Assembly Process begins by first adding solder paste to each component pad one by one.
- Next, using a tweezer, we pick RPi Pico and place it in the designated position, we do have to align the board according to the pads.
- Following that, we carefully lifted the entire circuit board and set it down on the Mini SMT Hotplate, which heats the PCB from below up to the solder paste melting temperature. As soon as the PCB reaches that temperature, the solder paste melts, and all the components are connected to their pads.
- Due to the board's slightly larger size compared to the PCB Hotplate's pads, I had to reflow the board twice by shifting the PCB.
Pico as HID
Fun fact: The Pico offers Human Interface Device (HID) capability.
Mouse, Keyboard, Controllers, and other HID devices,
The Atmega382PU or AU used in general-purpose boards like the Arduino Nano or UNO is fantastic for prototyping for any project, but it does not support HID, so we cannot build a game console project with one of these boards. (There is another, more complicated way to use an Uno or Nano as a game controller.)
We use the Atmega32U-powered Arduino Micro or Leonardo for projects involving HID.
With better peripherals and a processor that is on par with ESP32 but without WiFi, the Raspberry Pi Pico is a direct replacement for the Micro or Leonardo.
Perhaps Pico is now superior to ESP32 because it is also offered in a WiFi version? That is debatable.
Wiring Diagram
This is the wiring connection we'll be using in the next step.
Mouse Assembly
- In order to build an HID mouse, we first take another expansion PCB, add push buttons to it, and solder the buttons into position.
- We attach one pin of each Push button to GND and then attach other pins to GPIO0, GPIO1, GPIO2, GPIO3, and GPIO4. (see the attached Wiring Diagram)
- By using Four PCB standoffs, we attach two PCBs together using four Mounting holes.
Code
For the code, I'm using HID Mouse Sketch, which is available in the Example> USB>Mouse>mousebuttons menu.
#include "Mouse.h"
// set pin numbers for the five buttons:
const int upButton = 0;
const int downButton = 1;
const int leftButton = 2;
const int rightButton = 3;
const int mouseButton = 4;
int range = 5; // output range of X or Y movement; affects movement speed
int responseDelay = 10; // response delay of the mouse, in ms
void setup() {
// initialize the buttons' inputs:
pinMode(upButton, INPUT_PULLUP);
pinMode(downButton, INPUT_PULLUP);
pinMode(leftButton, INPUT_PULLUP);
pinMode(rightButton, INPUT_PULLUP);
pinMode(mouseButton, INPUT_PULLUP);
// initialize mouse control:
Mouse.begin();
}
void loop() {
// read the buttons:
int upState = digitalRead(upButton);
int downState = digitalRead(downButton);
int rightState = digitalRead(rightButton);
int leftState = digitalRead(leftButton);
int clickState = digitalRead(mouseButton);
// calculate the movement distance based on the button states:
int xDistance = (leftState - rightState) * range;
int yDistance = (upState - downState) * range;
// if X or Y is non-zero, move:
if ((xDistance != 0) || (yDistance != 0)) {
Mouse.move(xDistance, yDistance, 0);
}
// if the mouse button is pressed:
if (clickState == HIGH) {
// if the mouse is not pressed, press it:
if (!Mouse.isPressed(MOUSE_LEFT)) {
Mouse.press(MOUSE_LEFT);
}
}
// else the mouse button is not pressed:
else {
// if the mouse is pressed, release it:
if (Mouse.isPressed(MOUSE_LEFT)) {
Mouse.release(MOUSE_LEFT);
}
}
// a delay so the mouse doesn't move too fast:
delay(responseDelay);
}
We only need to modify the pin number and the INPUT to INPUT PULLUP so that each GPIO we use will have an internal pull-up resistor. Other than those two modifications, nothing else has to be changed.
- We must first press and hold the Bootsel Button while connecting the USB to the Pico Board in order to upload the sketch.
- After that, we just upload the sketch after choosing the board from the board manager. (Pico does not require the selection of a COM Port; leave it unchecked or blank.)
Result
Here's the result of this build: a functional HID mouse with one button for selection and four directional buttons for movement.
This configuration cannot take the place of a standard mouse. This is merely a concept to demonstrate the RP2040's capabilities and how it can take the place of Arduino-powered HID-capable microcontrollers.
I'm going to be prototyping with the RPi Pico board and utilizing this expansion PCB going forward.
I hope this article was useful, if yes, then leave a comment.
Special thanks to PCBWAY for supporting this project; do check them out for great PCB service at a lower cost.
Thanks again, and I will be back with a new project soon.
#include "Mouse.h"
// set pin numbers for the five buttons:
const int upButton = 0;
const int downButton = 1;
const int leftButton = 2;
const int rightButton = 3;
const int mouseButton = 4;
int range = 5; // output range of X or Y movement; affects movement speed
int responseDelay = 10; // response delay of the mouse, in ms
void setup() {
// initialize the buttons' inputs:
pinMode(upButton, INPUT_PULLUP);
pinMode(downButton, INPUT_PULLUP);
pinMode(leftButton, INPUT_PULLUP);
pinMode(rightButton, INPUT_PULLUP);
pinMode(mouseButton, INPUT_PULLUP);
// initialize mouse control:
Mouse.begin();
}
void loop() {
// read the buttons:
int upState = digitalRead(upButton);
int downState = digitalRead(downButton);
int rightState = digitalRead(rightButton);
int leftState = digitalRead(leftButton);
int clickState = digitalRead(mouseButton);
// calculate the movement distance based on the button states:
int xDistance = (leftState - rightState) * range;
int yDistance = (upState - downState) * range;
// if X or Y is non-zero, move:
if ((xDistance != 0) || (yDistance != 0)) {
Mouse.move(xDistance, yDistance, 0);
}
// if the mouse button is pressed:
if (clickState == HIGH) {
// if the mouse is not pressed, press it:
if (!Mouse.isPressed(MOUSE_LEFT)) {
Mouse.press(MOUSE_LEFT);
}
}
// else the mouse button is not pressed:
else {
// if the mouse is pressed, release it:
if (Mouse.isPressed(MOUSE_LEFT)) {
Mouse.release(MOUSE_LEFT);
}
}
// a delay so the mouse doesn't move too fast:
delay(responseDelay);
}
Raspberry Pi Pico as HID Mouse
*PCBWay community is a sharing platform. We are not responsible for any design issues and parameter issues (board thickness, surface finish, etc.) you choose.
- Comments(0)
- Likes(1)
- emiliomiguez Jul 06,2024
- 0 USER VOTES
- YOUR VOTE 0.00 0.00
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
More by Arnov Arnov sharma
- WALKPi PCB Version Greetings everyone and welcome back, This is the WalkPi, a homebrew audio player that plays music fr...
- Delete Button XL Greetings everyone and welcome back, and here's something fun and useful.In essence, the Delete Butt...
- Arduino Retro Game Controller Greetings everyone and welcome back. Here's something fun.The Arduino Retro Game Controller was buil...
- Super Power Buck Converter Greetings everyone and welcome back!Here's something powerful, The SUPER POWER BUCK CONVERTER BOARD ...
- Pocket Temp Meter Greetings and welcome back.So here's something portable and useful: the Pocket TEMP Meter project.As...
- Pico Powered DC Fan Driver Hello everyone and welcome back.So here's something cool: a 5V to 12V DC motor driver based around a...
- Mini Solar Light Project with a Twist Greetings.This is the Cube Light, a Small and compact cube-shaped emergency solar light that boasts ...
- PALPi V5 Handheld Retro Game Console Hey, Guys what's up?So this is PALPi which is a Raspberry Pi Zero W Based Handheld Retro Game Consol...
- DIY Thermometer with TTGO T Display and DS18B20 Greetings.So this is the DIY Thermometer made entirely from scratch using a TTGO T display board and...
- Motion Trigger Circuit with and without Microcontroller GreetingsHere's a tutorial on how to use an HC-SR505 PIR Module with and without a microcontroller t...
- Motor Driver Board Atmega328PU and HC01 Hey, what's up folks here's something super cool and useful if you're making a basic Robot Setup, A ...
- Power Block Hey Everyone what's up!So this is Power block, a DIY UPS that can be used to power a bunch of 5V Ope...
- Goku PCB Badge V2 Hey everyone what's up!So here's something SUPER cool, A PCB Board themed after Goku from Dragon Bal...
- RGB Mixinator V2 Hey Everyone how you doin!So here's a fun little project that utilizes an Arduino Nano, THE MIXINATO...
- Gengar PCB Art Hey guys and how you doing!So this is the GENGAR PCB Badge or a Blinky Board which is based around 5...
- R2D2 Mini Edition So here's something special, A Mini R2D2 PCB that speaks ASTROMECH.Astromech is a fictional language...
- C-3PO Blinky Board Hey guys and how you doing!So this is the C3P0 PCB Badge or a Blinky Board which is based around 555...
- WALKPi Breadboard Version Greetings everyone and welcome back, Here's something loud and musical.Similar to a traditional walk...
-
-
kmMiniSchield MIDI I/O - IN/OUT/THROUGH MIDI extension for kmMidiMini
71 0 0 -
DIY Laser Power Meter with Arduino
83 0 2 -
-
-
Box & Bolt, 3D Printed Cardboard Crafting Tools
120 0 2 -
-
A DIY Soldering Station Perfect for Learning (Floppy Soldering Station 3.0)
413 0 1 -
Custom Mechanic Keyboard - STM32
239 0 3