Emulate a SpaceMouse Pro with a SpaceBall 4000

arpruss
Mon Aug 27, 2018 3:38 am
I acquired an old serial SpaceBall 4000 3d-mouse on ebay, with the hope of using a max3232 to connect it to a black/blue pill, which would then emulate communicate with the SpaceBall via serial on one side, and with a PC via USB HID, emulating a newer SpaceMouse model.

Unfortunately, I ended up damaging my max3232 breakout board in the process. Fortunately, I had an rs232 to USB adapter, and so I ended up using a python script on my laptop in place of the max3232. I.e., I hooked the SpaceBall to my Win10 laptop via the rs232-to-USB-adapter, and hooked a black pill running a SpaceBall-to-SpaceMouse emulation script with a USB Composite Serial+HID profile to another USB port on the laptop, and then used a python script on the laptop to bridge between the two serial connections. Here is my code: https://github.com/arpruss/mouse3d_stm32f1

It’s interesting that one can actually get some use out of an STM32F1 board without attaching any extra electronics, just by plugging the STM32F1 into a PC and running a script. (The Soft Joystick example in the USB Composite library does something similar. It lets you have much of the functionality of vJoy without installing any drivers.)

That said, I’m waiting for a new max3232 unit, so I can have a less awkward setup.

Image


ag123
Tue Aug 28, 2018 1:45 pm
interesting ! hope your max3232 would arrive sooner :)

arpruss
Wed Aug 29, 2018 6:22 pm
It turns out that a lot of the cheap max3232 units (mine was $0.29 shipped) are fake, and eventually they fail and overheat. That matches what happened to my unit.

Yesterday, I managed to do the USB emulation all on Windows, using USB/IP (a cool project, but alas the latest drivers are not signed). My code is here: https://github.com/arpruss/USB-Emulation


ag123
Wed Aug 29, 2018 7:05 pm
i’ve some ‘cheap’ ebay/aliexpress ics, many of them i’ve not yet tested them, but it’d look like some of those might literally be *fake*
i noted that certain ICs some of which i bought on aliexpress seemed cheaper than what it would cost to buy direct from a manufacturer’s web e.g. TI, STM etc. those that ‘worked’ so happened to be blue pills / maple minis which some how they seem to be able to source at costs lower than the ‘retail’ prices on STM’s or TI’s web.
i’ve literally heard that some of the components are recovered from junk just that i’m not sure how true that is.

as for max3232, i’ve been wondering if it would be worth it to simply use some ULN2003 in its place
https://en.wikipedia.org/wiki/ULN2003A
apparently there are chinese local fabs which makes ICs that are ‘similar’ to ULN2003, it is more likely ‘real’ as those are simply darlington transistor arrays. Just that again the capacity could be suspect, e.g. the ‘cheap’ chinese ICs may not deliver on the 500mA load currents.
chinese uln2003 are going for prices like 10 pieces a dollar or even 20 pieces a dollar shipped
given that there are ‘chinese local fabs’ i suspect some of the ‘chinese local fabs’ may try to ‘fake’ brand name ICs, mainly the simpler ones
they may try to achieve the same pinouts and label the ICs as such, but the chip itself may simply be a bunch of transistors arranged like those uln2003
and they label them after the brand name SKUs. well all these are just speculation

but i think using ULN2003 in place of max3232 may work though it does not comply with the specs. that’d make it rather easy to simply pull up the output pins to VCC with a resistor and hook them up as TX or other outbound signal lines. As for inbound, e.g. RX it is mainly to protect stm32 from the excessive voltages and perhaps some resistor dividers or zener diodes may do the trick, but that would cost some extra hardware and pins on the board, i.e. the resistors. the voltages would be one of a bummer which a max3232 handles, if one don’t have a source for V+ at rs232 levels, it may be easier to just get max3232

oh some additional google turns this up one could make do with 2 transistors and resistors as well
https://www.sparkfun.com/tutorials/215


ag123
Wed Aug 29, 2018 7:07 pm
usb ip is indeed an interesting project
http://usbip.sourceforge.net/
it is a little unusual to bridge usb this way, but nevertheless it is an interesting use case.
for one thing, this would make it possible to use usb devices ‘remotely’, one could use a keyboard for a computer half a world away

nice article from you
http://breaking-the-system.blogspot.com … th-no.html
i think i’d try it out soon, but i do agree that using a VM is a safer / better way to try all these things out
we’d be able to even simulate a usb device to the host os running in the VM in python before doing all that code on stm32


arpruss
Thu Aug 30, 2018 12:57 pm
I ended up ordering an sp2323 unit including a DB-9 male port from ebay for $3. At least it won’t be a fake *Max*3232, and if it’s wired correctly, it’ll save on soldering.

It’s easier for me to prototype a USB device on stm using the USBComposite library than using USBIP on Windows, but perhaps that’s just because of familiarity. And it’s really unfortunate that the USBIP library comes in two varieties: (a) official release which is signed but crashes when a device disconnects, and (b) unofficial patched version which doesn’t crash but isn’t signed and required me to turn off SecureBoot.


arpruss
Fri Sep 21, 2018 7:28 pm
I got my sp3232, and am having a really weird problem.

I’ve tested with a simple USB-to-serial bridge sketch on a black pill, together with the sp3232 board. When I send “M<cr>” to the SpaceBall via Serial1, which is supposed to turn periodic axis report mode, the SpaceBall reboots as if I had sent it a “Z<cr>” (reboot). When I send it “Z<cr>”, it does nothing. The “%” command which echoes things works well, and “%M<cr>” echoes an M. Other commands I tried work, too.

On the other hand, if I connect to the SpaceBall via a cheap USB-to-serial adapter, everything works fine. Same laptop, same terminal emulator (e.g., the one in the Arduino IDE).

Off-hand, does anyone have any ideas as to why some transmissions, like “M<cr>”, might be getting garbled (I tried many times — this is not a one-off), but others, like “%M<cr>” work fine?

I’m doing this at 9600 8N1, so definitely within the capabilities of the STM32F1 UART.


madias
Fri Sep 21, 2018 8:12 pm
If I guess right, you are in a 3.3V / 5V conflict.
Do you have some level shifters, like this? https://www.aliexpress.com/item/10pcs-l … 66582.html I’ve done every project successfully with this little things.
You can also test you code with a 5V device like Uno, Micro, Mini…
Edit: You did the wiring like this? https://os.mbed.com/teams/OpenMoCo/code … Connection Maybe this circuit ist too much simplified? –> https://www.google.at/search?q=max3232+ … 058#imgrc=_

arpruss
Fri Sep 21, 2018 9:52 pm
I got it: It was underpowered when powered off the 3.3V port of the black pill, so it reset when it tried to measure the ball position. It works fine when I hold the SR2323 unit’s VCC line to 5V on the pill. So I’ll just have to carefully solder a wire to the black pill’s power input diode (it works when I hand-hold a jumper to it). This is one time when the black pill’s lack of a 5V pin is bad for me.

arpruss
Mon Sep 24, 2018 2:50 am
I actually got this all working with one of the probably-fake max3232 units. (I thought I had got a sp3232 in the mail, but I didn’t look at the packaging carefully enough.)

It turned out to to be really tricky. Here is what finally worked to avoid the latch-up overcurrent problem with the fakes.

1. Add 10K pull-ups to both of the “max”3232 inputs. This reduced the frequency of the latch-up problems from one in three boots to one in ten or fewer.

2. Put a 50 ohm resistor between USB +V and “max”3232 VCC. This reduced the voltage to somewhere around 4V, as well as protecting against overcurrent. The real max3232 works at 3-5.5V but it looks like the fake suffers from latch-up at higher voltages. I couldn’t just run at 3.3V, as then the output voltage was too low to power the SpaceBall.


arpruss
Sat Sep 29, 2018 2:11 am
I just tried an SP3232 based board that looks like this: https://www.ebay.com/itm/RS232-SP3232-T … 2608133090
It worked beautifully with no changes and no soldering, powered by the pill’s 3.3V.

arpruss
Sat Sep 29, 2018 10:08 pm
Finally, here’s the Instructable for the project: https://www.instructables.com/id/SpaceB … B-Adapter/

Leave a Reply

Your email address will not be published. Required fields are marked *