i have soldered out buttons and replaced them with wired in USB mouse. Mouse itself is connected to device. Is it possible to wire those cables to GPIO in Raspberry PI model 2. And control clicks via python? I have little project to do but must be used hardware click.

I am attaching photos what i have done so far.

image1 image2

And this page for reference: https://www.google.com/amp/s/electropeak.com/learn/tutorial-raspberry-pi-gpio-programming-using-python-full-guide/amp/

How can i put it all together? What else would i need?

Thanks for any tips. What i was thinking is connect ground to grd pin in rpi gpio and use pin 18 and resistor for left button wire to control it via python.

Current in button is 2.7V. I am newbie please shine some light over it for me.

I dont want to burn my PI on first try that is why im asking here. All tutorials i have found was about input but not much about output of GPIO Thanks!

=======PARTIAL CONCLUSION AND PROBABLY BEST ONE====================== Would be using OPTO-COUPLER, witch creates isolated environment between RPI and EXTERNAL Device such as separately powered usb mouse in my case even knowing that power is more-less than 5v (and could be manageable via GPIO itself to do what it need to be done such as pressing button?).

Its a lot safer to use OPTO-COUPLER. Instructions and video can be found here: https://youtu.be/pYENAGK8qH4

  • Ah, let me see. So you have two buttons. Press a button makes something happen. The button circuit is usually a "pull down" circuit, sending a High/Low signal to the "make something" guy. You said "current" in button is 2V7. I guess you measure the button terminal and found voltage 2V7. If you press the button, which closes/shorts the button switch, and the 2V7 goes to 0V. So now what Rpi can do is to ask GPIO send a similar output signal about 3V to 3V3 to the mouse at the button terminal where you measure 2V7. Please let me know if you more or less know what I am talking about.
    – tlfong01
    Commented Sep 9, 2019 at 2:00
  • You might find my answer to this following question helpful (the intstructable on remote with a 2N2222 pull down circuit diagram is good): raspberrypi.stackexchange.com/questions/99823/…. The HDMI switch controls something different, but the trick of using a "pull down" stuff is the same. You might google/wiki to know more about the "pull down" thing.
    – tlfong01
    Commented Sep 9, 2019 at 2:04
  • I forgot to mention that I assumed that you are using a wireless mouse, not a wired USB mouse, which is a bit more complicated.
    – tlfong01
    Commented Sep 9, 2019 at 2:15
  • Hi all, jsotola its not unspecified problem. I dont want to use IR or Solenoids or nothing simillar. Job is simple basically if i short yellow and green cable left mouse button is pressed. If i short red and yellow then right mouse button is pressed. If none of them are not shorted its like off state. And im pretty sure its like tlfong said Its just simple send voltage to terminal to make button press. I am going to try it out and let You guys know. Thanks. How about resistor? any particullar one 330ohm should do? Commented Sep 9, 2019 at 2:23
  • tflong01 does it really matter if it is usb or wireless? both has to have current flow to work battery or usb powered. All it is to press that switch to short circuit (currently connect 2 wires together (green and yellow or red and yellow ) as there is no buttons no more ;) ) i am going to measure current on both states but u might be right 2.7v is when nothing is pressed and goes to zero if shorted. Also googling pull down thing is good tip need to take a look at that. Commented Sep 9, 2019 at 2:48

1 Answer 1


If the devices share a common ground another possible solution is a MOSFET e.g. BS170. These can be driven by the Pi GPIO and provide reasonable isolation. Without details of the external circuitry this can only be considered a suggestion, but the devices are readily available inexpensively (~10c) but is certainly safe.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.