VOGONS


USB to Serial Mouse using the Pi Pico!

Topic actions

First post, by CalamityLime

User metadata
Rank Member
Rank
Member

Hey there.

A project that I've been working on the past little while is building an adaptor to convert a bog standard USB mouse to a Serial mouse.
Some people might remember me from this topic -> Fixing up a broken 486 I got from a local radio. While I had been working on this project I was keeping an eye on eBay for some Serial mouse to use at a decent price, while a few popped up, they were a bit rubbish. Thus began my adventure looking for some way to convert a newer mouse to a serial mouse.
I had a look around the forums for solutions. Matze's, Lameguy64's and Necroware's PS/2 to serial boards popped up as did that one solution that used a nullmodem cable + a pi to go from USB to Serial.

At the time I decided go with Matze's solution and ordered the bits to make up my own board, plus a few extra with the intention of trying to sell off the few extra. There's a bit more information on this in the thread linked above. Ultimately I thought "why can't this be done with a USB mouse?"
I turned to the Pi Pico because it has a USB host device caked in plus I had three of them kicking around. There aren't many examples out there for the Pico acting as a USB host which was frustrating and in the end I went with the C SDK from the Raspberry pi foundation. I hadn't used C since learning to code so it was a bit of a challenge.

It already exists....
A few days into hacking code together and trying to figure out how exactly a Serial Mouse works I found that I'm not the only one who's had this idea. A fellow vogons user by the name Aviancy made amouse, which was exactly what I was trying to make. Their thread is here.
For a while I actually thought I was the only person actually going down this path since I honestly couldn't find anything on using a Pico to convert a USB mouse to Serial mouse, other than people suggesting the idea. The discovery hurt my motivation for bit, it was sort of embarrassing since I found that project right after I made a post talking about this idea on my other thread (which I do suggest reading).
None the less, I decided to keep going and try to enjoy it. BTW because that project exists, I'm not writing this post as an announcement and more like a blog.

It did something!
After I got my hands on a max232 I very quickly wired it up and it actually did something. The PC detected the pico as a mouse but that was all at the time.
The momentum from this moment got me to make something very hacky but did actually work. I could connect a mouse to the pico and the pc was happy out using that input as serial mouse input.
I called it a day after that since it was sometime in the AMs by then. Since that point I've been cleaning up my code and trying to make the user experience better than "if the LED stops blinking, it crashed"

Where is this project now?
It's still in the "cleaning up code and improving user experience" stage. I'm not releasing the code right now just because the code is still a bit of a mess. I'm quite self conscious about my code and I'd like to doll it up before sharing.

Why am I even posting this?
Well I'd like to get some idea as to how much interest there is for something like this. Depending on the interest level, I could even go as far as to make up and sell a small batch of ready made boards.
If you're interested on where and how far this project goes, let me know. If you have ideas for this, feel free to comment. I'm all ears!

In terms of pin header options here's what I have currently.

  • 25%/50%/75% Mouse XY Tracking Speeds. (Thanks to my testing mouse being broken!)
  • Three Button / Microsoft Wheel mouse.
  • Double Stop bit. (This idea came from Necrowares PS/2 to Serial adaptor)

I'm not sure what else to say, so I'll leave it here for now.
Thank you for reading, your comments and your interest.
-Lime

Attachments

Be Happy, it's only going to get worse.
- Projects
Limes Strange 3D models
USB-2-232

Reply 2 of 230, by CalamityLime

User metadata
Rank Member
Rank
Member

Hey there.

I think in good news I think managed to fix a problem where the pico crashed when the USB mouse is disconnected and reconnected. It does seem like the USB and serial side of things are fairly separated. So the serial side doesn't die when the USB mouse is disconnected and the USB side doesn't die when the Serial side is disconnected.
I had been trying to trick that into working right without an extra transistor.

I'll have to test that on my old KVM, if the PSU for it is still kicking around. I had read that the PS/2 to serial mice struggle with KVM's so getting KVM's working right with this would be nice.

I want some LED blink codes for various things, like "serial connection lost" or "Incompatible USB device" in the same vain as the Dell blink codes. #

I do have one question for the audience, with this I'm finding that the y axis feels a lot more sensitive than the X axis.
It feels fairly okay in Doom but in Monkey island (because it has a cursor) I can really feel the difference.
Is that normal for older serial mice?

That's all for today I think.

Thank you for reading, your comments and your interest.
-Lime

Be Happy, it's only going to get worse.
- Projects
Limes Strange 3D models
USB-2-232

Reply 3 of 230, by CalamityLime

User metadata
Rank Member
Rank
Member

Hey there.

Sorry for not giving any updates, I got the chance to do nothing for a few days and I took it.
I've been tinkering a bit with this project for a bit now and I think I've made decent progress with it.

Things I've changed/Fixed

  • 25%/50%/75% Mouse XY Tracking Speeds:
    At first this worked by just dividing the numbers for X and Y before sending it over serial. Problem is that the Pi Pico is missing a floating point unit so I used integer division for the sake of speed. This worked fine for larger moments but got very weird with slow and accurate movements due to rounding issues.
    So I decided to switch over to a lookup table instead. I pre-calculated the values I need in python and threw them into a switch statement for the pi. That works much better. The 25% still feels a little weird but much improved compared to before. A massive lookup table shouldn't impact the speed of the Pico too much.
  • Hot Swapping the USB mouse:
    This was particularly annoying.
    So TinyUSB on the Pi Pico has this wonderful feature that makes the Pico crash if you plug the mouse out and back in. So I needed a way to force the pi to reboot, the glorious SDK lacks a handy "pico_reboot()" feature so I had to cheese it with the watchdog feature to force a reboot. At least I didn't have to add a NPN BJT to the mix.

    Using the Logitech driver, the mouse was re-negotiated upon the Picos reboot so that was an non-issue. CTmouse on the other hand just did nothing. It took bit of figuring to find a way to test for a listening CTmouse driver but I got there with it and that now reconnects properly. Huzzah.
  • X axis feeling a lot more sensitive than the Y axis:
    The question I asked above. Yeah that was just the Logitech driver and yeah I mixed up X and Y when I asked that question. My bad.
    I'm debating whether or not to add a jumper header to divide the X axis movement in half, testing showed me that it makes the more sensitive X axis feel a lot better. Let me know what you think.
  • Cleaning Up The Code
    It's getting there.
    C is fairly alien to me so I made a lot of weird mistakes, with some other strangeness with structure. I think I'm getting it to a point where it's getting easier to follow with less messy code and good comments to explain any of the stranger parts.
    It's never going to be perfect but I'll probably upload it to GitHub sooner rather than later.

What I Know Doesn't Work

  • KVM
    I dug out my old KVM (StarTech SV431UADVI) discovered that it's 9v PSU died, made a little box to convert 12V to 9V before it goes into the KVM, the box didn't work, discovered that the original PSU was fine and my Box was fine but the connector on the power cable itself had shorted somehow, remade my step down box with a new connector, KVM booted, the TinyUSB panicked when I plugged it into the KVM.
    Completely out of patience after making a stepdown box, I put the KVM away.
    Maybe another time
  • Hot Plugging the serial connector
    The base work for the code is there but I just haven't gotten around to making it reconnect and go. It's not a priority but I thought it would be handy if you accidentally knocked out the serial connector.

Nothing too much but figuring some things out was quite confusing and time consuming.
I don't think I'll attach a compiled uf2 file, it would be outdated very quickly but if you wanted to try it yourself or test it yourself, just send me a DM until it's on GitHub.

That's all for today I think.
Thank you for reading, your comments and your interest.
-Lime

Be Happy, it's only going to get worse.
- Projects
Limes Strange 3D models
USB-2-232

Reply 4 of 230, by CalamityLime

User metadata
Rank Member
Rank
Member

Hey there.

Here's the code with a compiled uf2 file. https://github.com/LimeProgramming/USB-serial-mouse-adapter

I think the code is to a point where I'm comfortable sharing it so there we go. I'll have to map out a circuit in KiCad or something using the default pins.
The pins used by the program to do whatever are configurable at the top of main.c.
I still have to figure out a nice way to have the alert LED blink out some codes but for the moment it turns on to indicate that there is a serial connection and a usb mouse connection.

Let me know if you find any issues which results in a crash or weird behaviour. I've also been thinking of expanding it to support PS/2 mice as well, should be decently doable but it's not a main goal of the project.

Thank you for reading, your comments and your interest.
-Lime

Be Happy, it's only going to get worse.
- Projects
Limes Strange 3D models
USB-2-232

Reply 5 of 230, by CalamityLime

User metadata
Rank Member
Rank
Member

Hey there.

I decided to try to draw out the circuit I have so far in KiCad.
Here's a picture that should help if you want to start building your own or test it out on a breadboard.

Thanks.

Attachments

Be Happy, it's only going to get worse.
- Projects
Limes Strange 3D models
USB-2-232

Reply 6 of 230, by CalamityLime

User metadata
Rank Member
Rank
Member

Oh, for breadboarding, you can leave out the resistor divider if you want to or use a max3232 instead of a max232 since the pico is not 5v tolerant but it worked for me in all the time it took me to realize that I was pumping 5v into a 3v3 system.

Thanks.

Be Happy, it's only going to get worse.
- Projects
Limes Strange 3D models
USB-2-232

Reply 7 of 230, by CalamityLime

User metadata
Rank Member
Rank
Member

Hey there!

So I have been tinkering with a PCB and how to lay out the board.
I tried a few idea's but I stumbled on a shape I like. Before routing traces and making it look nice. I'd like to ask what ye think and if it's missing anything important.

Just for context, this is the first time I've layed out a PCB in KiCad from scratch.

Information:

  • J2 is a serial out, so the signals come out of that as well as from the serial port on the board.
  • J3/J4 is 5v power in.
  • Switch is a run switch for the pico so you can do a hard reset.
  • Mini USB for power in.
  • JP1 is for switching between 3v3 and 5v supply for the max232. This is to allow the board to take a max232 or a max3232
  • The USB port on the pico points in the opposite direction to the serial port.

While the layout is not final and some bits may shuffle around a little, you can see the shape and rough layout that I had in mind.

The pin headers are to allow you build the thing into a PC or something. Power can be pumped into it via the pin header, the mini USB port or the picos micro USB with certain USB OTG cables.
The bottom of the board is bare.

👍
Danke

Attachments

Be Happy, it's only going to get worse.
- Projects
Limes Strange 3D models
USB-2-232

Reply 8 of 230, by touche112

User metadata
Rank Newbie
Rank
Newbie

Loving this so far. That board layout looks good. I'm happy to build boards for people if needed, when the design is published. I just finished my run of Domesday Duplicators so this will be a good run to start!

Reply 9 of 230, by CalamityLime

User metadata
Rank Member
Rank
Member

I took some feedback from Dosreloaded and this is the version 2 for the moment.

I don't know if I'll have to narrow it further or not too tired to figure that out tonight.
Let me know what you think!

The silk screen still needs doing and if it does need to be narrowed down further then I'll have to replace the Dipswitch with pin headers or something.

Attachments

Be Happy, it's only going to get worse.
- Projects
Limes Strange 3D models
USB-2-232

Reply 10 of 230, by CalamityLime

User metadata
Rank Member
Rank
Member

Forgot to post the list of changes.

  • PCB TP1 == USB D- == TP2 on the underside of the Pico
  • PCB TP2 == USB D+ == TP3 on the underside of the Pico
  • That way the Pico folds on top of the PCB, which should keep the soldering neat and easy to do.
  • J1 is a USB header out, that is compatible with a the headers that plug into a motherboard.
  • J2 is 5v power in
  • J3 is serial out

And yes, you can just plug the mouse into USB1, powering the system using the picos micro usb or J2 or hacked USB cable.
You don't have to solder TP1 and TP2, you can use a USB OTG to plug the mouse into the pico itself.

Be Happy, it's only going to get worse.
- Projects
Limes Strange 3D models
USB-2-232

Reply 11 of 230, by CalamityLime

User metadata
Rank Member
Rank
Member

So today/tonight I worked on the silk screen.
The board is pretty much the same but I tried to refine it a little more. A few traces got moved around to less silly places and I added a taper to on the board towards the serial port.

It needs a name and maybe something for the back then I think it's ready for the first order.

The test point numbers start with 2 for the sake of the pico.
TP2 on the pico goes to TP2 on the PCB.
TP3 on the pico goes to TP3 on the PCB.

I've been soldering long enough to know that that little thing will save a headache down the line.

Attachments

Be Happy, it's only going to get worse.
- Projects
Limes Strange 3D models
USB-2-232

Reply 12 of 230, by CalamityLime

User metadata
Rank Member
Rank
Member

Hey there.

​Placed an order with JLCPCB, including the SMT assembly.
​Had to change the value's of the resistor dividers but that's fine.

I ordered 15 boards with SMT and 5 without, I wanted one for decoration.
​So, here's hoping that I didn't mess up anything stupid!

KiCad Files are on the GitHub if you're interested.

Thank you for reading, your comments and your interest.
-Lime

Be Happy, it's only going to get worse.
- Projects
Limes Strange 3D models
USB-2-232

Reply 13 of 230, by CalamityLime

User metadata
Rank Member
Rank
Member

Hello there

At long last my orders from LCSC and JLC have arrived!

I have assembled one PCB to finish the last of the firmware, so the pin headers pointing up from the pico are just there for printf and the debug port of the pico.
Overall I am very happy with these PCB's, the SMT soldering is fairly good if a bit dry but thats what you get with the lead free rubbish.

As a bit of a confession to make, I may have forgotten that the pico has an LED built in. So I could have just had one on board LED for a PWR and used the built in one for simple alerts. Oh well.

So yeah, hope you like what you see. I have to order some picos before I can sell them at all.

Attachments

Be Happy, it's only going to get worse.
- Projects
Limes Strange 3D models
USB-2-232

Reply 15 of 230, by CalamityLime

User metadata
Rank Member
Rank
Member
douglar wrote on 2021-12-08, 19:43:

Is the PI Pico a more powerful computer than the 486 you are restoring?

Could be.
However, there is no way that I know of to play MS-DOS games on the pico, so there's that.

ಠ_ರೃ

Be Happy, it's only going to get worse.
- Projects
Limes Strange 3D models
USB-2-232

Reply 16 of 230, by douglar

User metadata
Rank Oldbie
Rank
Oldbie
CalamityLime wrote on 2021-12-08, 20:44:

Could be. However, there is no way that I know of to play MS-DOS games on the pico, so there's that.

Just teasing. I'm sure it's a lot less expensive and a lot smaller than the 486, and those are the most important factors for a project like this.

It would be pretty cool if you could mount a device like this on an ISA card, with two rear facing USB ports and present it over the ISA bus as a pair of buffered com ports.

Then you could conceivably:
1) use the first USB port for a pointing device like a mouse
2) use the second USB port to present USB compatible storage via INTERLNK.EXE
3) keep all the circuit boards out of harms way inside the case
4) pull power from the ISA bus (or 4 pin molex if that doesn't work)

How hard would it be to emulate INTERSVR on the PI?

Edit: Rather than reverse engineering INTERSRV, it might be easier to do these steps whenever a USB drive is inserted :
1) spin up a virtual FREDOS session on the PI
2) mount the USB volume and com port in the virtual dos box
3) start run INTERSVR .EXE to present the USB drive to the host PC

Reply 17 of 230, by CalamityLime

User metadata
Rank Member
Rank
Member
douglar wrote on 2021-12-08, 21:53:

Just teasing. I'm sure it's a lot less expensive and a lot smaller than the 486, and those are the most important factors for a project like this.

It would be pretty cool if you could mount a device like this on an ISA card, with two rear facing USB ports and present it over the ISA bus as a pair of buffered com ports.

....

That's a really cool idea.

I did entertain the idea of making an ISA card with the pico mounted that has the serial ports built into it. While that's still a fun idea, I decided against it for a few reasons; namely that I never designed a PCB before and not knowing anything about serial protocols before going into this.

I like the idea but for what you suggested I'd be inclined to go with a teensy over the pico just because of software maturity. While the pico does have hardware support for USB hosting the software for it is TinyUSB which has been posing a massive headache for USB hubs which it claims it works with. It's to the point where I'm tempted to get a Teensy just to test it with USB hubs to potentially make a second mouse USB -> 232 just for KVM support. You could use a Pi Zero which would be cheaper than a teensy, Aviancy's project would be good for that link, only catch is the boot-up time.

Personally I think getting INTERSRV working on the pico is beyond what I can do for a while. I'm not terrible with programming but I'm fairly new to dealing with C.
If someone got INTERSRV working on the pico, it might work with the hardware as it is now but honestly probably easier to do that with a pi zero. I doubt that the boot-up time for the zero would be much of an issue in that use case.

It might be worth mentioning the fact that the pico is a micro controller, not the SBC of the pi 4/zero.

Thanks!

Be Happy, it's only going to get worse.
- Projects
Limes Strange 3D models
USB-2-232