This version of UnoJoy! (created by Alam Chatham) allows you to use optical encoders or incremental
encoders in place of a potentiometer, still allowing you to easily turn an Arduino Uno or Mega into a
PS3-compatible USB game controller. It's still in BETA phase, but its stable to use if correctly configured.
THERE IS NO SUPPORT TO FORCE FEEDBACK ON THIS BRANCH, IF FORCE FEEDBACK IS DESIRED PLEASE SEARCH FOR AN
ARDUINO LEONARDO OR PRO MICRO BOARD AND THE "EMC SOFTWARE", OR OTHER STM32-BASED PROJECTS.
Hi there! Welcome to using UnoJoy! - Encoder Version
Using this branch of UnoJoy! means that you already know about the original branch and (probably) know how
to install it.
But to be sure about it, here it is a small tutorial for this.
To download the files, just click in the menu Code, then download zip.
Then unpack it on the desktop.
For installation and source of Arduino IDE, Atmel/Microchip FLIP files, just follow the links on the
original branch.
To connect the encoder, VCC (usually red, check on your encoder to be sure) goes on 5V, GND (usually black,
check on your encoder to be sure) on GND, the last two wires (usually white and green, check on your encoder
to be sure) are the data pins and goes into digital pins 2 and 3 (always leave digital pins 0 and 1 empty,
they're used by UnoJoy!'s communication).
Compatible encoders are quadratic encoders that are 5V-compliant, some models can be salvaged from broken
printers on the rollers, and multifunctional printers can also have an extra (and smaller) encoder already
coupled in a small brushed motor, these encoders/motors are quite useful in small projects. But compatible
encoders can be bought on Aliexpress. (The model used on testing is a LPD3806-600BM-G5-24V)
First, open the Arduino IDE, and using the menu Sketch > Include Library > Manage Libraries (or the
shortcut Ctrl + Shift + I), in the "Filter your search" box you're gonna write "Encoder" and press Enter.
The correct library is called "Encoder by Paul Stoffregen", version 1.4.2, then click in Install, it should
install automatically.
Now open the "testRotation" sketch, select the board you have (Arduino Uno and Arduino MEGA 2560 are both
compatible with this program without any problems), then click Upload (or the shortcut Ctrl + U). After
compiling and uploading, click on the "Serial Plotter" button and spin the encoder. If the graphic on the
screen moves in the same rhythm as you're spinning the encoder, it worked succesfully, if not, the encoder
and its wiring needs to be checked (or depending on the encoder model, pull-up resistors can be needed in
the data lines).
After making sure that the encoder is working succesfully, the encoder must be mounted in the structure,
and the next part can only be completed after the steering wheel is physically finished, because it's time
to calibrate the encoder's range. After finishing the structure, connect the wires to the Arduino, plug
the Arduino in the PC, open the Arduino IDE, and open the Serial Plotter again. Now spin the wheel to the
max angle that was set in the wheel's construction, then save the max number that the Plotter shows, then
spin it to the opposite side until the max angle is hit again, then save the second number.
With both of the numbers collected, now open the "MegaJoyEncoderSample" sketch, and in the line 61, you
will swap the first two numbers in the part "map(newPosition, XXX, XXX, 0, 1023);" with the numbers you
collected in the other sketch, then upload this sketch to the desired Arduino board. After finishing the
upload, you'll need to put the Arduino in DFU mode by touching a small metallic object in the 2 closest
pins to the USB port on the 6-pin block near the USB port. If the process is succesful, the Arduino will
reboot and a new device notification should appear. Now go into the main folder and open the file "MegaJoy
- Attack!.bat" and let it finish automatically. If it finds an error, it will show you what happened, if
not encountering an error, it will show a warning to unplug and re-plug the Arduino, then remove and
reinstall the Arduino on the USB port and it should work now as a DirectInput joystick that works on most
games (games that are only compatible with Xbox controllers and similar products need another piece of
software that is out of this project's scope).
If you need to make the arduino return back to normal, just do the DFU mode trick again and use the
"TurnIntoAnArduino.bat" file. Follow the instructions there and unplug/re-plug the Arduino only when
asked to.
The sketch is pre-configured for only two axes (the encoder-based steering and one analog pin for an
potentiometer or hall sensor. If you need more analog pins to be active, and the Arduino is in UnoJoy!
mode, do the DFU mode trick and use the file "TurnIntoAnArduino.bat" to return it to edit mode. Open
the "MegaJoyEncoderSample" sketch, and you will make the changes in the lines 62-72, allowing 11 more
analog pins to be read in the Arduino MEGA 2560 (but physically only 5 more in the Arduino Uno). To
activate an analog pin, you need to first know how many extra pins are needed, then modify the lines
"controllerData.analogAxisArray[X] = 0;" where X is the now-disabled pin, deleting the 0 and writing
"analogRead(A*)", keeping the ";" symbol at the end, and changing the "*" symbol in the desired
analog pin number (A1-A5 on Arduino Uno and A1-A11 on Arduino MEGA 2560).
Also, the line 62 ("controllerData.analogAxisArray[1] = 512;") is partially locked at 512 since it's
the default vertical control for analog joysticks, so if the axis is actually needed but is used in a
way that it doesn't return to the center, it could cause issues with drifting controls into up or
down positions, so please keep this limitation in mind.
The sketch divides the analog pins into two groups of 6 available axes, A0-A5 and A6-A11 (Arduino Uno
only does have physical access to A0-A5) and the digital pins in two groups, digital 4-35 and 36-53
(Arduino Uno only does have access to 4-13 pins)