Arduino Joystick Library, LinuxCNC joypad and hal_input

29 Jun 2020 18:52 #173124 by muntzieman
I’ve searched through the forums and could not find any reference to this so I’m passing on the information. Recently I’ve been working with an Arduino Micro on a project. While doing research I came across a Arduino library that can change a Micro to act as joystick.

The author states that you can create a joystick with the following features.

Buttons (default: 32)
Up to 2 Hat Switches
X, Y, and/or Z Axis (up to 16-bit precision)
X, Y, and/or Z Axis Rotation (up to 16-bit precision)
Rudder (up to 16-bit precision)
Throttle (up to 16-bit precision)
Accelerator (up to 16-bit precision)
Brake (up to 16-bit precision)
Steering (up to 16-bit precision)

I currently use a joystick (joypad) on my CNC mill and was curious if I could get the Arduino Micro working with hal_input on my mill. I loaded one of the example sketches for the joystick library and ran “less /proc/bus/input/devices” and got the following results:

I: Bus=0003 Vendor=2341 Product=8037 Version=0101
N: Name="Arduino LLC Arduino Micro"
P: Phys=usb-0000:00:14.0-8/input2
S: Sysfs=/devices/pci0000:00/0000:00:14.0/usb2/2-8/2-8:1.2/0003:2341:8037.0004/input/input19
H: Handlers=event15 js1
B: EV=1b
B: KEY=ffff 0 0 0 0
B: ABS=7ff
B: MSC=10

I followed with


loadusr -W hal_input -KRAL Micro

Connected with no errors. Running “show all” revealed several pins. Here’s a partial list.

Component Pins:
Owner Type Dir Value Name
6 s32 IN 4095 input.0.abs-x-flat
6 s32 IN 255 input.0.abs-x-fuzz
6 bit OUT TRUE input.0.abs-x-is-neg
6 bit OUT FALSE input.0.abs-x-is-pos
6 float IN 0 input.0.abs-x-offset
6 float OUT -1 input.0.abs-x-position
6 float IN 32767 input.0.abs-x-scale
6 s32 OUT -32767 input.0.abs-y-counts
6 s32 IN 4095 input.0.abs-y-flat
6 s32 IN 255 input.0.abs-y-fuzz
6 bit OUT TRUE input.0.abs-y-is-neg
6 bit OUT FALSE input.0.abs-y-is-pos
6 float IN 0 input.0.abs-y-offset
6 float OUT -1 input.0.abs-y-position
6 float IN 32767 input.0.abs-y-scale
6 s32 OUT -32767 input.0.abs-z-counts
6 s32 IN 4095 input.0.abs-z-flat
6 s32 IN 255 input.0.abs-z-fuzz
6 bit OUT TRUE input.0.abs-z-is-neg
6 bit OUT FALSE input.0.abs-z-is-pos

I then verified with halmeter that I was getting input pins to work, which was successful.

From there I breadboarded a membrane keypad, a cheap rotary encoder and frankensteined some code from various web sites to create an arduino sketch. Again, I verified that buttons and the rotary encoder worked with halmeter. I have not tried to move my mill with the encoder. I’m not sure what settings I would need to get it to work in a hal file but I will continue to work with it.

My hope is the someone will find this useful. Please let me know if you do.
The following user(s) said Thank You: tommylight

Please Log in or Create an account to join the conversation.

29 Jun 2020 19:27 #173129 by tommylight
Nice, thank you.
I am sure i have several arduinos and ESP32 around here, but i also have 2 of Mesa 7i73, had no time to do something useful with them yet. I did make an RPM counter with one of the ESP32 as it has a display and battery.

Please Log in or Create an account to join the conversation.

Time to create page: 0.100 seconds
Powered by Kunena Forum