It also supports Digital LEDs such as WS2812 or PL9823. This way you can have as many LEDs as you want and you can also define the color of them with just one Pin.
This software works with LinuxCNC 2.8, 2.9 and 2.10. For 2.8 however you have to change #!/usr/bin/python3.9 in the first line of arduino.py to #!/usr/bin/python2.7.
Just return ```E0:0``` to it. You can now communicate with the Arduino. Further info is in the Chapter [Serial Communication](#serial-communication-over-usb)
[![IMAGE ALT TEXT](https://img.youtube.com/vi/bjKfnLbsvgA/0.jpg)](https://www.youtube.com/watch?v=bjKfnLbsvgA&list=PLdrOU2f3sjtApTdxhmAiXL4lET_ZnntGc "How to set up and test arduino-connector with LinuxCNC")
You can easily modify it to fit your needs. Set Inputs to how many Pins you want to use as Inputs and edit the Array InPinmap by setting the Pin Number that should be set as Input. You can add as many as you want until your Arduino runs out of available Pins.
After you've set your Pin definitions, copy your settings over to the arduino.py file.
The .ino is written in C while the other one is written in Python, hence the Syntax is a little different.
You only need to worry that the contents of the variables match.
Digital Inputs use internal Pullup Resistors. So to trigger them you just short the Pin to Ground. There are two Digital Input Types implemented.
Don't use them for Timing or Safety relevant Stuff like Endstops or Emergency Switches.
1. INPUTS uses the spezified Pins as Inputs. The Value is parsed to LinuxCNC dirketly. There is also a inverted Parameter per Pin.
2. Trigger INPUTS (SINPUTS) are handled like INPUTS, but simulate Latching Buttons. So when you press once, the Pin goes HIGH and stays HIGH, until you press the Button again.
Digital Outputs drive the spezified Arduinos IO's as Output Pins. You can use it however you want, but don't use it for Timing or Safety relevant Stuff like Stepper Motors.
# support of Digital RGB LEDs like WS2812 or PL9823
Digital LED's do skale very easily, you only need one Pin to drive an infinite amount of them.
To make implementation in LinuxCNC easy you can set predefined LED RGB colors.
You can set a color for "on" and "off" State for each LED.
LED colors are set with values 0-255 for Red, Green and Blue. 0 beeing off and 255 beeing full on.
Here are two examples:
1. This LED should be glowing Red when "on" and just turn off when "off".
[![IMAGE ALT TEXT](https://img.youtube.com/vi/L_FBEtP9il0/0.jpg)](https://www.youtube.com/watch?v=L_FBEtP9il0&list=PLdrOU2f3sjtApTdxhmAiXL4lET_ZnntGc&index=2 "using digital RGB LEDs with LinuxCNC")
This is a special Feature for rotary Selector Switches. Instead of loosing one Pin per Selection you can turn your Switch in a Potentiometer by soldering 10K resistors between the Pins and connecting the Selector Pin to an Analog Input.
The Software will divide the Measured Value and create Hal Pins from it. This way you can have Selector Switches with many positions while only needing one Pin for it.
You can adapt the Settings to fit all kinds of Matrix Keyboards. The Software can emulate an Keyboard in Linux. This is useful, because for some Keys you may want to enter Letters or Numbers, for others you may want to set functions in LinuxCNC. To input Text it is neccessary to emulate Keypresses.
In the Config file you can define, which Key should be connected to LinuxCNC as Inputpins and which should be handled like a Keyboard in Linux.
To run Matrix Keyboards requires you to install and test "xdotool".
You can install it by typing "sudo apt install xdotool" in your console. After installing "xdotool type "Hello World" should return "Hello World" in the Terminal.
If it doesn't, something is not working and this program will not work either. Please get xdotool working first.
In the Settings a cheap 4x4 Keyboard is used such as https://theartoftinkering.com/recommends/matrix-keyboard/ (referral link)
[![IMAGE ALT TEXT](https://img.youtube.com/vi/oOhzm7pbvXo/0.jpg)](https://www.youtube.com/watch?v=oOhzm7pbvXo&list=PLdrOU2f3sjtApTdxhmAiXL4lET_ZnntGc&index=4 "connect Matrix Keyboards to LinuxCNC using ArduinoC")
Special mode for Multiplexed LEDs. This mode is experimental and implemented to support Matrix Keyboards with integrated Key LEDs. Please provide feedback if u use this feature.
check out this thread on LinuxCNC Forum for context. https://forum.linuxcnc.org/show-your-stuff/49606-matrix-keyboard-controlling-linuxcnc
for Each LED an Output Pin is generated in LinuxCNC.
If your Keyboard shares pins with the LEDs, you have to check polarity. The Matrix Keyboard uses Pins as such:
rowPins[numRows] = {} are Pullup Inputs
colPins[numCols] = {} are GND Pins
the matrix keyboard described in the thread shares GND Pins between LEDs and KEYs, therefore LedGndPins[] and colPins[numCols] = {} use same Pins, LedVccPins[] are Outputs and drive the LEDs.
Quadrature Encoders require a Library to be installed.
More Info about the used Library can be found here: https://www.pjrc.com/teensy/td_libs_Encoder.html
It can be downloaded here: https://www.arduino.cc/reference/en/libraries/encoder/
This function is made with Rotating encoders in mind but supports all kinds of quadrature Signals.
For easy implementation in LinuxCNC two modes are supported.
1 = Up or Down Signals per Impuls , this is intended for use with Feed or Spindle Speed Override.
2 = Counter Signal, this is intended for the usecase of using the Encoder as MPG for example. Arduino will count Impulses and add them to a counter, which then is send to LinuxCNC.
there you can connect it to x & y yog signals.
If your Encoder can be pressed and there is a button inside, use the Input or Latching Input functionality mentioned above.
[![IMAGE ALT TEXT](https://img.youtube.com/vi/hgKXgRvjwPg/0.jpg)](https://www.youtube.com/watch?v=hgKXgRvjwPg&list=PLdrOU2f3sjtApTdxhmAiXL4lET_ZnntGc&index=3 "How to connect Rotary Encoders and Joysticks for MPG to LinuxCNC using Arduino")
Joysticks use a similar implementation as Quadrature encoders and are implemented with the usecase as MPG in mind.
Connect your X and Y Pin of your Joystick to an Analog Pin of your choice.
Depending of the position of the Joystick it will add or substract from a counter, which then is send to LinuxCNC. The more you move the Joystick from the middle Position to the end of movement the more will be added to the counter, which will increase the speed of motion in Jog mode.
Currently Joysticks will only generate an counter in LinuxCNC.
[![IMAGE ALT TEXT](https://img.youtube.com/vi/hgKXgRvjwPg/0.jpg)](https://youtu.be/hgKXgRvjwPg?si=nVdQgR5Q6rLq4QGQ&t=780 "How to connect Rotary Encoders and Joysticks to LinuxCNC using Arduino")
After Bootup the Arduino will continuously print E0:0 to Serial. Once the Host Python skript runs and connects, it will answer and hence the Arduino knows, the connection is established.
For testing you can still connect to it with your Serial terminal. Send ```E0:0```, afterwards it will listen to your commands and post Input Changes.
Data is always only send once, everytime it changes.
Command 'E0:0' is used for connectivity checks and is send every 5 seconds as keep alive signal. If it is not received in Time, the connection is lost and the arduino begins flashing an LED to alarm the User. It will however work the same and try to send it's Data to the Host.