jfedor2 / magellan-spacemouse

Adapter to use RS-232 Magellan/SpaceMouse with modern software
38 stars 8 forks source link

Cheap replacement for the Pololu 23201a Serial Adapter #5

Open TinkerTob opened 6 months ago

TinkerTob commented 6 months ago

Hi,

currently, the Pololu 23201a Serial Adapter would cost me about 15€, which would make this project more expensive than the old Spacemouse itself.

Is it possible to replace it with a cheaper alternative, like the Waveshare RS232 Board, or is there anything that specifically requires the 23201a?

Thank you!

jfedor2 commented 6 months ago

I'm not sure, I think you might be good? With serial devices the issue is sometimes how they get power from the serial port, for example serial mice expect voltage on the DTR line, which the simpler RS232 boards don't have.

But for the Magellan it seems we're only using TX/RX/CTS/RTS so maybe it's fine. I'll get the Waveshare board and let you know in a few days.

Allcrafter1 commented 6 months ago

I have an adapter from Aliexpress with the same Chip as the waveshare one and it sadly does not provide power on the DTR Line. The board looks slightly different so maybe you will have luck but mine does not work. A cheap replacement from Aliexpress would be nice. With that the whole project could be like 20€.

TinkerTob commented 6 months ago

Wow, I wasn't expecting such an immediate response, let alone two... Thank you both!

@jfedor2 that would be very much appreciated, if it's not too much of a hazzle. I would have done so myself, but if it didn't work I'd have no way of knowing if the problem was caused by the RS232 board or by something else. Testing it in a working setup would be ideal. @Allcrafter1 did you try it with this project? As far as I can see, the DTR pin is unused here, so unless the Pololu board has taken it upon itself to short it to the 5V line, there shouldn't be any power on it. The main problem I see with most cheap RS232 boards is that they don't expose CTS and RTS, even if their ICs support it.

In the meantime, I've taken a closer look at the datasheet for the SP3232E that's used on the Waveshare board. The operating circuit looks pretty simple to me - just the IC itself (0,99€), five 0.1µF capacitors (5x0.02€) and a DB9 terminal (0.36€).

If @jfedor2 confirms that the IC works, I might even try to create my own circuit board, featuring pin sockets for the Pi and a female DB9 socket that would let me get rid of the adapters.

That would allow me one-stop shopping at http://reichelt.de and put the whole project below 15€ incl. shipping: Article Description Amount Price Total
RASP PI PICO H Raspberry Pi Pico, RP2040, Cortex-M0+, microUSB, Header 1 4,80  € 4,80  €
SP 3232 EEYL RS232, 2 Driver / 2 Receiver, TSSOP-16 1 0,99  € 0,99  €
BB SOP16 SMD Breakout Adapter, SOP16 / SSOP16 / TSSOP16 1 0,77  € 0,77  €
D-SUB ST 09US D-SUB-Plug, DB9, angled 1 0,36  € 0,36  €
KERKO 100N Ceramic Capacitor, 100 nF, -20...+80 %, Y5V, 50/100 V, RM 5 5 0,030  € 0,15  €
LR-DS-37 Stripboard, 70 x 30 mm 1 0,44  € 0,44  €
BL 1X20G8 2,54 20pol. pin sockets, straight, RM 2,54, H: 8,5mm 2 0,30  € 0,60  €
MPE 087-1-008 pin headers, 2,54 mm, 1X08, straight 2 0,21 € 0,42 €
8,53
Shipping Fees 1 5,95 € 5,95 €
14.48
Allcrafter1 commented 6 months ago

Please don't buy the original Pi Pico. I got a clone version from AliExpress for only 2€ including shipping. It also has the advantage of USB C and an RGB LED. Maybe @jfedor2 can provide another firmware so the LED does some nice color transitions to make it look cool. The clone seems to work fine. The spacemouse is listed on the computer. Unfortunately nothing happens. Yes, I tried it with this project. That's why I bought an adapter from AliExpress, also with the sp3232. I assume you're also from Germany? The Polulu board apparently provides 5v on DTR, otherwise the mouse will not turn on, as @jfedor2 and the mouse manual said. I have actually ordered 5 Polulu boards from the Netherlands (I hope they arrive) so if you want one I can send it to you for 15€. I also want to try to integrate this into the Spacemouse itself, so no DB9 connectors would be needed.

TinkerTob commented 6 months ago

@Allcrafter1 it's not about saving three Euros on the Pi... It's about the relatively simple RS232 board being more expensive than the rest of the project, and about not having to pay shipping fees to three different suppliers. Accordingly, I'll have to decline your offer of sending me a Polulu board for 15€ - I'm not willing to spend that money if I don't absolutely have to.

5€ for the Pi on the other hand is a fair enough price and I prefer ordering from local suppliers (yes, I'm from Germany) whenever it makes sense to do so. Once this thing works, it will be stuck into a box and vanish under my desk, so neither USB C nor the LED would bring me any significant advantage.

Halfway back to topic: If I get this right, all you got working is the USB part, right? IMO, that proves nothing.

The Pi clone you got probably differs from the original Pi pico in several ways, possibly including the pin assignment. (Highly probable, since the LED you mentioned must be attached to some pin.) That usually requires adjusting the firmware, which you probably haven't done since you're asking the developer to include LED support which you could've easily done yourself at that point. Even then, compatibility isn't guaranteed, since there could still be differences in other components (e.g. cheap ESP32 knockoffs often have issues with the flash memory). Many of these problems would not stop you from flashing the firmware and having the spacemouse show up on the PC, so that alone proves nothing.

Until you have a fully working setup, I'm gonna assume that yours is not working at all. The only way to really verify which components work and which don't is having a working setup and then swapping them out one by one.

Back to the actual topic:

for example serial mice expect voltage on the DTR line, which the simpler RS232 boards don't have. But for the Magellan it seems we're only using TX/RX/CTS/RTS so maybe it's fine.

For me, this soulds like other (normal) mice expect voltage on the DTR line, but the Magellan does not. (Should be easy enough for anyone with a working setup to verify.) Even if it does: If it's only about shorting DTR to 5V, that would be easy enough to do with a soldering iron.

jfedor2 commented 6 months ago

I can't get it to work with the Waveshare adapter. The Magellan makes a weird constant sound instead of the familiar two beeps on startup.

So I guess it does need voltage on the DTR line and the Pololu adapter does provide it, even when nothing is wired to it on the microcontroller side. At least that's what it looks like.

Allcrafter1 commented 6 months ago

Hi @TinkerTob,

It is true that the boards can be different. The pin assignment, however, isn't changed. I remember researching this before and looked it up again. See: YouTube Video. The Neopixel LED is connected to GPIO23, which is unused here. Compared to the original, the clone board also has an extra button, but also on an unused GPIO pin. So, in my opinion and theory, no firmware changes are needed.

No, it is not easy for me to add LED support as I am a programming novice. But I agree that it still COULD be the Pico clone. The Pololu boards arrive tomorrow, which will be the ultimate test. However, as you pointed out, verifying each component one by one in a known working setup is crucial.

As mentioned before and as experimentally discovered by @jfedor2, the Magellan mouse needs 5V on DTR and another pin. See also the attached manual of the mouse on page 18. Magellan Manual.

I also tried shorting 5V to DTR, but although it beeped, still nothing worked. Maybe my connections are not good enough, so I will check again after I try it with the Pololu boards.

Off topic, but I felt that your comment seemed somewhat dismissive, particularly regarding the functionality of my setup and the validity of my findings. You focused heavily on the potential differences in the Pi clone and its firmware, and seemed to discount my experiences with the RS232 board and the Pi clone without giving them much consideration. I wish for that to improve. However I'm keen to continue working on this together and welcome any further input or suggestions you have.

Best, Allcrafter1

Allcrafter1 commented 5 months ago

It definitely works with the Polulu Adapter. So it's 100% not the fake Pi. I will try soon to get it working with the fake one.

TinkerTob commented 5 months ago

Hi again,

Spoiler: @Allcrafter1 It wasn't my intention to offend. However, please try reading your [comment](https://github.com/jfedor2/magellan-spacemouse/issues/5#issuecomment-2120557672) from my perspective: First, you're trying to sell me on a clone pi for 2€ savings and a chance of fancy LED effects, then you're trying to sell me the Pololu board for more than you probably spent on it yourself (since you've bought them in bulk), and only by reading between the lines it became clear that (since you had only just ordered the Pololu boards) you didn't even have a working setup at that point. What was I supposed to make of that? Your last two comments however were much more helpful: Well structured, well reasoned, including sources and details. I really appreciate that, and since you've now proven that you actually do know what youre doing and not just throwing in opinions, I'd like to apoligize for the mistrust I've shown you. I too would like to continue working together to find a solution. Now, let's return to the topic.

Thank you both for your experiments.

The manual provided by @Allcrafter1 is extremely helpful - I admit that I had not yet looked it up, since I've never in my live seen a manufacturer give such detailed information about the signal protocol. Thank you for providing the link!

After pondering this further and looking at the datasheets, I'm pretty sure I have figured it out. However, I'm not an electrical engineer, so it's still more of an educated guess. In contrast to the SP3232, the MAX2328 on the Pololu board has all DB9 lines connected to the IC. Since the unused lines are floating (not pulled down to ground), it's conceivable that the space mouse is able to draw current directly from the IC on these lines, even if they're not actively set to high. However, this is more of a lucky accident and typically not something that should be relied upon.

The right way to go would be to actively supply power on the DTR line. However, when using a null modem adapter, the DTR line should actually be switched with the DSR (and possibly CDC) lines, so putting power on it would actually power the DSR (+CDC) on the mouse, which should have no effect.

@Allcrafter1 did you consider this in your experiment? If I'm right, that would mean that if you:

It would be really interesting to know which of these you tried.

(All of this is assuming you're using a SP3232 board with a female DB9 connector. If it has a male connector, it might already be already wired as a DTE, meaning that power on DTR without a null modem adapter should be the right configuration. And assuming that the null modem adapter actually uses full handshaking, not partial handshaking. For Partial handshaking null modems, I don't see any way for the spacemouse to be powered at all (at least on the waveshare board - it might still draw power from the IC via DSR on the Pololu) or for the RTS/CTS connection to work.

In summary, I'm pretty sure that the SP3232 should work, but with no real way to trace the lines through the RS232 board and the adapters, it's all pretty confusing. I still think a custom circuit board, wired as DTE with power supplied directly to DTR, is the way to go. Cheap, simple, no need for adapters. I've ordered the parts from reichelt last week and will try it once they arrive (though I have no idea when this might be... So far, they haven't even confirmed my order.) I've also ordered a MAX2328 IC from china, in case it really doesn't work with the SP3232.

Allcrafter1 commented 5 months ago

Hi @TinkerTob,

Thank you for your thoughtful response and for clarifying your perspective. I appreciate the detailed technical analysis and your willingness to continue working together.

Addressing Previous Comments:

Power Issue with the Pi:

Experiment Setup:

Visual Documentation:

Your detailed analysis of the SP3232 and MAX2328 ICs is highly insightful. The idea of a custom circuit board wired as DTE with power supplied directly to DTR sounds promising and could simplify the setup.

Looking forward to your thoughts and any further suggestions you might have.

Best regards, Allcrafter1

TinkerTob commented 5 months ago

Thank you for that detailed information! Since my order still hasn't arrived, all I can do right now is speculate. But there are a few things that come to mind.

Voltage Supply Problem: One significant issue I've encountered is that my Pi only outputs 4.6V, which is insufficient for the Spacemouse. The Spacemouse requires a full 5V to beep and operate correctly, as I discovered by using an external power supply. This alone is a critical issue, as it means an additional board is necessary to provide adequate voltage.

A 0.4 V voltage drop in itself is usually well within tolerances for this kind of application, so I would be very disappointed if the spacemouse couldn't handle it. Either way, it shouldn't be caused by the Pi. The Pi outputs either 3.3V, or the USB input current, which should be pretty close to 5V, at least on a USB 2.0 port. However, the voltage can drop significantly if you're using a long USB cable or a passive Hub, which both seem to be the case on picture 8. Considering the voltage loss caused by the long serial cable on the spacemouse, this might contribute to what you're describing. To verify, maybe try attaching the Pi directly to a high-powered USB port using a short, high-quality cable?

(Besides, it might be important to consider that both ICs seem to boost the RS232 output voltage to 5V from the 3.3V provided by the Pi. Maybe it's an issue if the DTR input voltage differs too much from the voltage on the RTS line?)

Maybe it's worth a try to just short RTS and DTR and see what happens... From what I've read, this might be exactly what the Spacemouse expects: That the PC sets both lines to high after the initial handshake.

I noticed that some pins were only needed during the initial connection of the Pi, suggesting a possible startup sequence that the SP3232 chip might not initiate.

I guess that's the RTS / CTS handshaking... After that, RTS repurposed is repurposed as a power line and CTS is not needed any more. IMO, this should be handled by the Pi, the IC just transmits the signals. If I'm right, you need GND, TX, RX, CTS, RTS and DTR at startup and can disconnect CTS later (altough there's no reason to do so). The other lines shouldn't be required.

Photos: The entire experimental setup, including wiring and connections, has been documented in the attached photos. Spacemouseexperiment1.pdf

That was a great idea, thank you! I don't have the time right now to follow all the steps you took, but I think i discovered something critical on pages 6+7 grafik

Looks to me like there's a trace connecting 1, 4 and 6 aka DCD, DTR and DSR. I see two problems here:

I've tried to verify the second point by tracing the connections on your board, but I wasn't able to follow them all the way. Seems to me that the RS232-side RTS/CTS IC pins are connected to some part of the connector via traces on the back of the PCB, so you're probably fine? However, the silkscreen is conspiciously lacking in that regard, so it looks to me like they added these connections to the design retroactively. You might want to verify that they actually connect to the correct DB9 pins and that there's no short between 7 and 8.

grafik

Allcrafter1 commented 5 months ago

Hi @TinkerTob,

Thank you for your detailed and thoughtful response! I appreciate your insights and suggestions.

Voltage Supply Problem

I tested the voltage issue, and indeed, 4.6V is not enough for the Spacemouse. It's true that I use a hub and a long USB cable, so the voltage drop is expected at this length. With the Pololu adapter, this voltage drop is not an issue.

RTS and DTR Shorting

I tried shorting the RTS and DTR lines as suggested, but the Spacemouse did not beep or work.

PCB Traces and Connections

There is a trace on the PCB, but it connects pins 2, 5, and 9. I cut this trace, but the setup still doesn't work, whether powered by the PSU or with RTS shorted to DTR. Additionally, the Spacemouse does not send any data, as verified by the oscilloscope.

DCD and DSR Connections

DCD and DSR are not connected, so there can't be any voltage issues from those lines.

CTS and RTS Connections

The CTS and RTS lines are not shorted.

Pin Connections

On the RS232 side, pin 7 is connected to pin 8 of the chip, and pin 8 is connected to pin 7 of the chip.

At this point, I'm not sure how to proceed. Do you have any suggestions? Perhaps we need to determine what specific signals the Spacemouse requires to start up and send data, and why these signals are not being send.

Best regards, Allcrafter1

TinkerTob commented 5 months ago

There is a trace on the PCB, but it connects pins 2, 5, and 9.

Nope, that can't be. Pin 2 is a data line (RXD in male and TXD in female pinout) while pin 5 is GND. Shortening one of the main signal lines to ground would very effectively prevent any communication, such a board could never work. You definitely have your pin numbers wrong here.

If you've soldered the wires to the wrong headers, that would explain why nothing is working. Please refer to https://www.amsamotion.store/2022/02/db9-connector.html for the correct pinout. It must be one of the following: grafik

(You can trace the RX and TX lines from the IC to find out wether it's supposed to be male or female. RX-2 / TX-3 = male, vice versa female. I'm pretty sure it's the latter, since the silkscreen clearly indicates a DCE configuration.)

I hope I'll get around to trying a custom circuit tomorrow.

TinkerTob commented 5 months ago

Got it working with the SP3232 🥳

However, it's still a mess on a breadboard. Took a lot of tinkering and I'm not quite sure what exactly what made it work. grafik

I will submit proper instructions for a low cost build once I figured out all the details, but that might take some time.

Basic changes:

And what got me in the end: Press * + 1 and * + 2 after turning on the Space Mouse, because for whatever reason, Translation and Rotation seem to be turned off by default, despite what the manual and the sticker on the bottom say!? (Until I did this, I couldn't see a signal in the logic analyzer when touching the knob. However, the buttons already worked.)

PS: Hand soldering TSSOP-16 is a massive PITA. Do not recommend. PPS: Cheap jumper cables where the tips break off when trying to pull them from the breadboard are even more of a PITA. Especially when you start running out of colors. PPPS: Those 24AWG ferrules are a perfect fit for the female DB9 connector. I mean, like, perfect. Better friction fit than any USB connector. I'm seriously considering just leaving them there and wrapping them up in some electrical tape (or putting a little 3D printed box around them) instead of using the male plug I bought for the purpose.

TwinRacer850 commented 2 months ago

Hi! Thank you very much for the hard work. I've got the same problem: here in Germany you can't find a cheap version of the Pololu Adapter or some other with the MAX3238. I'm realy good in soldering but not yet good in programming or understanding everything in digital-technics. So I would be really glad if you could give us some schematics of your work.

I saw these modules at Amazon : link

Would they work?

... I'm very exited on your next post...

Simmsey commented 2 months ago

Hi TwinRacer850, I have not tried a SP3232 module but tried one of these micro pcb's with a smt MAX3232 IC and found that the voltage output by it is lower than RS232 spec which is usually fine these days for serial communication but was insufficient to power my space mouse.

I looked for a version these micro smt pcb's which output higher voltages I could fit within the case I had already designed but couldn't find one. I worked around this by providing 12V to RTS pin of serial port. This provides suitable voltage to power the space mouse and the MAX3232 works fine for the TX/RX and CTS lines. All works great. To keep it all compact and USB powered I added a small boost regulator PCB (also available cheaply on amazon/ebay etc)
20240908_134834 20240908_135019 20240908_135039

Very happy with the end result. Thanks for all the good work that has gone into developing this.

TwinRacer850 commented 2 months ago

Thank You very much! I just orderd exactly these boards, because i like your housing very much!

Can you scribble down some schematics? Than it will be easier to rebuild it. For all others: I ordered these things at Amazon.

link one

link two

...when I'm finished I can link some Housing to print...

Simmsey commented 2 months ago

Here's a quick wiring diagram I have drawn up: spacemouse interface wiring

Note: Edited 11/9/2024 to correct RTS and CTS DSUB pin number error Note: DSUB connector is male.