December 2024 Update: Support for LED rings like a neopixel!
The adafruit neopixel led ring with an inner diameter of 52.3 mm fits well.
Filming the LEDs "in action" is very hard, maybe you can get an idea:
Repository for a 3D mouse, which emulates a 3Dconnexion "Space Mouse Pro wireless". (This repository is NOT affiliated with 3Dconnexion. We just reverse-engineered the USB protocoll.)
It is based on four joysticks with additional keys or an encoder.
This repository for the source code is based on the work by TeachingTech and many other contributors, as seen in the history.
To see all features in place, like the buttons and the encoder, check out the different versions by Jose L. González, like the ErgonoMouse MK XX - 6DOF Controller Knob & Joystick with Wheel, Buttons & Keys:
- Source code for an Arduino Pro Micro to read four joysticks and calculate the kinematics
- Emulation of the USB identification and the HID interface to behave like an original space mouse
- Advanced USB settings for linux users: Implemented jiggling or declaring the HID reports as relative or absolute values
- Semi-Automatic calibration methods to find the correct pin outs and measurement ranges
- Debug outputs can be requested over the serial interface during run time, see config_sample.h
- Over ten keys may be reported to the PC via USB and may be evaluated by the original driver software
- "Kill-Keys" may disable translation or rotation directly in the mouse
- An encoder wheel can be used to replace one axis and allow e.g. zooming
- Check out the config_sample.h for more informations about configurable elements and extensive debug outputs
- LED can be enabled by the PC driver
- Support for a LED ring, as supported by the FastLED library
Wanted features:
- Reverse Direction and Speed options in 3dConnexion Software is not working, because our spacemouse is not accepting this settings.
Purchasing the electronics and printing some parts is not scope of this repository. We start with the software. Feel free to read a build report in the Wiki: Building an Ergonomouse
The original 3Dconnexion windows driver is very elegant to detect which programm you are running and offering custom actions for the keys on a space mouse. You can utilize this behavior and build a space mouse with keys, just without the central part, the space mouse itself. You are left with keys, that you can assign to actions for your CAD programm. This comes handy, if your original spacemouse doesn't have enough keys. In this case your PC will see an additional mouse where only the keystrokes are send and evaluated.
You can use PlatformIO to flash the board with this fast steps. PlatformIO is easier than ArduinoIDE, because you don't need to change the board.txt files there.
- Install PlatformIO.
- Clone this repo and open a terminal in the cloned directory.
- Copy
src/config_sample.h
tosrc/config.h
and change the values to whatever suits. - Run
pio run -t upload
or click on the upload arrow in the IDE. - Assign the pins of the joysticks and go through the calibration
- Use your space mouse
- Done!
- Create a custom board in your Arduino IDE, that emulates the original space mouse
- Download or clone this github repository
- Rename the config_sample.h to config.h
- Try to compile and flash your board
- Assign the pins of the joysticks and go through the calibration
- Use your space mouse
- Done!
The boards.txt file needs an additional board definition, which tells the microprocessor to report the USB identifiers correctly and emulate the 3dconnexion space-mouse. Please follow the detailled instructions on the wiki page about custom board definition.
Clone the github repo to your computer: Scroll-Up to the green "<> Code" Button and select, if you wish to clone or just download the code.
Copy the config_sample.h and rename it to config.h. This is done to avoid the personal config file being overwritten when pulling new updates from this repository. You probably have to update the config.h file with new additions from the config_sample.h, but your pin assignment will not stay.
- Open the Arduino IDE (1.8.19 and 2.3.2 are tested on Ubuntu).
- Open spacemouse-keys.ino
- Select Tools -> Board -> SparkFun AVR Boards -> Spacemouse.
- (If you followed another boards.txt instructions, which also allow 3.3V with 8 Mhz: Make sure to select the proper processor: 5V 16MHz)
- Select the correct port (see troubleshooting section, which might be necessary for first upload)
- Compile the firmware
Troubleshooting for uploading is explained in detail here:
Uploading firmware to the Pro Micro
After compiling and uploading the programm to your hardware, you can connect via the serial monitor. In the upper line, you can send the desired debug mode to the board and observe the output. "-1" stops the debug output.
Read and follow the instructions throughout the config.h file and write down your results. Recompile after every step.
This calibration is supported by various debug outputs which can toggle on or off before compiling or during run time by sending the corresponding number via the serial interface. All debug outputs are described at the top of your config_sample.h.
- Check and correct your pin out -> Refer to the pictures in the Electronics section below.
- Tune dead zone to avoid jittering
- Getting min and max values for your joysticks
- There is a semi-automatic approach, which returns you the minimum and maximum values seen within 15s.
- Adjust sensitivity
- Choose modifier function:
Choose a modifier function with the help of the following picture. Note, that the Squared, Squared Tan and Cubed Tan function act like a deadzone filter, because small inputs are resulting in nearly zero output, which may reduced unwanted movements. Also note, that some of those functions are already at their maximum output (and therefore limited), before the input reaches 350.
You will also need to download and install the 3DConnexion software
If all goes well, the 3DConnexion software will show a SpaceMouse Pro wireless when the Arduino is connected.
Checkout https://wiki.freecad.org/3Dconnexion_input_devices and https://github.com/FreeSpacenav/spacenavd.
- The software reads the eight ADC values of the four joy sticks
- During start-up the zero-position of the joystick is measured and subtracted from the adc-value. -> The values now range from e.g. -500 to +500
- A dead zone in the middle is applied to avoid small noisy movements. (E.g. every value between +/- 3 is fixed to zero)
- The movement of the joysticks is mapped from the original about ca. +/- 500 digits to exactly +/- 350. (Therefore the real min and max values will be calibrated) Now all further calculations can be done with this normalized values between +/-350.
- We calculate the translation and rotation based on this.
- Applying the modifiers to minimize very small rotations or translations.
- Kill, swap or invert movements
- Sending the velocities and keys to the PC, see also SpaceNavigator.md for further details about the emulated USB HID.
There are many parts and remixes available. A very good starting point is the Part Open source SpaceMouse - Space Mushroom remix by Teaching Tech. Check out the many remixes, especially if you want to use other joysticks modules!
Here are some of the remixes or additions that are used with this software:
- ErgonoMouse MK XX - 6DOF Controller Knob & Joystick with Wheel, Buttons & Keys by Jose L. González (Free and premium version available)
- Lid with mounting for 4 MX Switch adapter by LivingTheDream
- SpaceMouse Mini - Slim profile, with easier assembly and various improvements - v3 by Doug Joseph
- Hall Effect Joysticks For the Space Mouse by Kempy
The spacemouse is connected to an arduino Pro Micro 16 Mhz. Check out the wiring diagram by TeachingTech or with this added keys and the added neopixel ring.
The calculations in the program expect AX to be the vertical joystick in front of you and AY the horizontal in front of you. B, C and D are clockwise around the spacemouse. Maybe your joystick axis are named X and Y in an other orientation. That doesn't matter. Connect them and use the config.h file to put the pin the vertical joystick in front of you (=AX) to the first position. In teaching techs example, this is A1, even though his joystick is labeled "y". See also the wiki for some additional pictures.
The calculation in this programm results in X, Y and Z calculated as shown in the middle of the picture. If this doesn't suit your programm change it by using the INVX or SWITCHYZ afterwards.
With the axis defined as shown in the picture above, the calculations for translation and rotation are as follows:
TRANSX = -CY + AY
TRANSY = -BY + DY
TRANSZ = -AX - BX - CX - DX
ROTX = -CX + AX
ROTY = -BX + DX
ROTZ = AY + BY + CY + DY
Here are some other projects with regard to space mice. The arrow indicates what is emulated.
- This repository itself -> space mouse
- DIY SpaceMouse Profiles -> User interface to tune e.g. sensitivity of the mouse
- A 6 degrees of freedom mouse for CAD programs using cheap linear Hall Effect sensors for position measurement -> space mouse
- DIY Spacemouse for Fusion 360 -> Mouse and Keyboard
- spacemouse with an esp32 -> work in progress -> space mouse pro
- Space Fox -> Joystick based on potentiometers
- Orbion The OpenSource 3D Space Mouse -> Mouse and Keyboard
This code is the combination of multiple works by others. This list summarizes what happened before this github repository was started:
- Original code for the Space Mushroom by Shiura on Thingiverse: https://www.thingiverse.com/thing:5739462
- The next two from the comments on the instructables page: https://www.instructables.com/Space-Mushroom-Full-6-DOFs-Controller-for-CAD-Appl/
- and the comments of Thingiverse: https://www.thingiverse.com/thing:5739462/comments
- Code to emulate a 3DConnexion Space Mouse by jfedor: https://pastebin.com/gQxUrScV
- This code was then remixed by BennyBWalker to include the above two sketches: https://pastebin.com/erhTgRBH
- Four joystick remix code by fdmakara: https://www.thingiverse.com/thing:5817728
- Teaching Techs work involves mixing all of these: The basis is fdmakara's four joystick movement logic, with jfedor/BennyBWalker's HID SpaceMouse emulation. The four joystick logic sketch was setup for the joystick library instead of HID, so elements of this were omitted where not needed. The outputs were jumbled no matter how Teaching Tech plugged them in, so Teaching Tech spent a lot of time adding debugging code to track exactly what was happening. On top of this, Teching Tech has added more control of speed/direction and comments/links to informative resources to try and explain what is happening in each phase.
- Code to include meassured min and max values for each Joystick by Daniel_1284580 (In Software Version V1 and newer)
- Improved code to make it more userfriendly by Daniel_1284580 (In Software Version V2 and newer)
- Improved Code, improved comments and added written tutorials in comments, by LivingTheDream Implemented new algorithm "modifier function" for better motioncontrol by Daniel_1284580 (In Software Version V3)
- Moved the Deadzone detection into the inital ADC conversion and calculate every value everytime and use the modifier for better seperation between the access, By Andun_HH.
- Added two additional buttons integrated into the knob to kill either translation or rotation at will and prevent unintended movements, by JoseLuisGZA and AndunHH.
- Added Encoder to use with a wheel on top of the main knob an simulate pulls on any of the axis (main use is simulating zoom like the mouse wheel), by JoseLuizGZA and rewritten by AndunHH.
Because TeachingTech published his source code on Printables under this license, it also applies here:
This work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License.