From 6415e4af50e7c85452ceb8b379e8f5747cc72b37 Mon Sep 17 00:00:00 2001 From: Alexander Richter Date: Tue, 28 Mar 2023 18:50:22 +0200 Subject: [PATCH 01/15] Toggle Mode Inputs This Update introduces Toggled Inputs. Pressing a Button once will Toggle the Input HIGH. Pressing it again will Toggle the Input LOW. Toggled Inputs are handled the same as Inputs in LinuxCNC --- LinuxCNC_ArduinoConnector.ino | 69 ++++++++++++++++++++++++++++++----- arduino.py | 17 ++++++++- 2 files changed, 75 insertions(+), 11 deletions(-) diff --git a/LinuxCNC_ArduinoConnector.ino b/LinuxCNC_ArduinoConnector.ino index 3380a26..ae0ea54 100644 --- a/LinuxCNC_ArduinoConnector.ino +++ b/LinuxCNC_ArduinoConnector.ino @@ -20,7 +20,7 @@ To begin Transmitting Ready is send out and expects to receive E: to establish connection. Afterwards Data is exchanged. Data is only send everythime it changes once. - Inputs = 'I' -write only -Pin State: 0,1 + Inputs & Toggle Inputs = 'I' -write only -Pin State: 0,1 Outputs = 'O' -read only -Pin State: 0,1 PWM Outputs = 'P' -read only -Pin State: 0-255 Digital LED Outputs = 'D' -read only -Pin State: 0,1 @@ -51,12 +51,18 @@ //###################################################IO's################################################### -//#define INPUTS //Use Arduino IO's as Inputs. Define how many Inputs you want in total and then which Pins you want to be Inputs. +#define INPUTS //Use Arduino IO's as Inputs. Define how many Inputs you want in total and then which Pins you want to be Inputs. #ifdef INPUTS - const int Inputs = 16; //number of inputs using internal Pullup resistor. (short to ground to trigger) - int InPinmap[] = {32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47}; + const int Inputs = 5; //number of inputs using internal Pullup resistor. (short to ground to trigger) + int InPinmap[] = {37,38,39,40,41}; #endif + //Use Arduino IO's as Toggle Inputs, which means Inputs (Buttons for example) keep HIGH State after Release and Send LOW only after beeing Pressed again. +#define SINPUTS //Define how many Sticky Inputs you want in total and then which Pins you want to be Sticky Inputs. +#ifdef SINPUTS + const int sInputs = 5; //number of inputs using internal Pullup resistor. (short to ground to trigger) + int sInPinmap[] = {32,33,34,35,36}; +#endif //#define OUTPUTS //Use Arduino IO's as Outputs. Define how many Outputs you want in total and then which Pins you want to be Outputs. #ifdef OUTPUTS @@ -180,17 +186,24 @@ Adafruit_NeoPixel strip(DLEDcount, DLEDPin, NEO_GRB + NEO_KHZ800);//Color sequen #endif - +//#define DEBUG //###Misc Settings### const int timeout = 10000; // timeout after 10 sec not receiving Stuff +const int debounceDelay = 50; -//#define DEBUG //Variables for Saving States #ifdef INPUTS int InState[Inputs]; int oldInState[Inputs]; + unsigned long lastInputDebounce[Inputs]; +#endif +#ifdef SINPUTS + int sInState[sInputs]; + int soldInState[sInputs]; + int togglesinputs[sInputs]; + unsigned long lastsInputDebounce[sInputs]; #endif #ifdef OUTPUTS int OutState[Outputs]; @@ -242,6 +255,16 @@ void setup() { oldInState[i] = -1; } #endif + +#ifdef SINPUTS +//setting Inputs with internal Pullup Resistors + for(int i= 0; i debounceDelay){ InState[i] = State; sendData('I',InPinmap[i],InState[i]); + + lastInputDebounce[i] = millis(); } } } #endif +#ifdef SINPUTS +void readsInputs(){ + for(int i= 0;i debounceDelay){ + // Button state has changed and debounce delay has passed + soldInState[i] = sInState[i]; + if (sInState[i] == LOW) { + // Button has been pressed + togglesinputs[i] = !togglesinputs[i]; // Toggle the LED state + + if (togglesinputs[i]) { + sendData('I',sInPinmap[i],togglesinputs[i]); // Turn the LED on + } + else { + sendData('I',sInPinmap[i],togglesinputs[i]); // Turn the LED off + } + } + lastsInputDebounce[i] = millis(); + } + } +} +#endif #ifdef ABSENCODER int readAbsKnob(){ @@ -497,11 +548,11 @@ void commandReceived(char cmd, uint16_t io, uint16_t value){ writePwmOutputs(io,value); } #endif - //#ifdef DLED + #ifdef DLED if(cmd == 'D'){ controlDLED(io,value); } - //#endif + #endif if(cmd == 'E'){ lastcom=millis(); } diff --git a/arduino.py b/arduino.py index 86b499d..243f776 100755 --- a/arduino.py +++ b/arduino.py @@ -50,8 +50,13 @@ connection = '/dev/ttyACM0' # Set how many Inputs you have programmed in Arduino and which pins are Inputs -Inputs = 16 -InPinmap = [32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48] +Inputs = 5 +InPinmap = [37,38,39,40,41] + +# Set how many Toggled Inputs you have programmed in Arduino and which pins are Toggled Inputs +SInputs = 5 +sInPinmap = [32,33,34,35,36] + # Set how many Outputs you have programmed in Arduino and which pins are Outputs Outputs = 9 @@ -84,6 +89,12 @@ Debug = 1 olddOutStates= [0]*Outputs oldPwmOutStates=[0]*PwmOutputs +# Inputs and Toggled Inputs are handled the same. +# For DAU compatiblity we set them up seperately. +# Here we merge the arrays. + +Inputs = Inputs+ SInputs +InPinmap += sInPinmap ######## SetUp of HalPins ######## # setup Input halpins @@ -127,6 +138,8 @@ arduino = serial.Serial(connection, 115200, timeout=1, xonxoff=False, rtscts=Fal firstcom = 0 event = time.time() timeout = 9 #send something after max 9 seconds + + ######## Functions ######## def keepAlive(event): From fa04530a67237dd6a804b1350bc47b99b492ff98 Mon Sep 17 00:00:00 2001 From: Alexander Richter Date: Tue, 28 Mar 2023 18:54:54 +0200 Subject: [PATCH 02/15] tidy up --- LinuxCNC_ArduinoConnector.ino | 2 +- README.md | 2 +- arduino.py | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/LinuxCNC_ArduinoConnector.ino b/LinuxCNC_ArduinoConnector.ino index ae0ea54..e07c15d 100644 --- a/LinuxCNC_ArduinoConnector.ino +++ b/LinuxCNC_ArduinoConnector.ino @@ -58,7 +58,7 @@ #endif //Use Arduino IO's as Toggle Inputs, which means Inputs (Buttons for example) keep HIGH State after Release and Send LOW only after beeing Pressed again. -#define SINPUTS //Define how many Sticky Inputs you want in total and then which Pins you want to be Sticky Inputs. +#define SINPUTS //Define how many Toggle Inputs you want in total and then which Pins you want to be Toggle Inputs. #ifdef SINPUTS const int sInputs = 5; //number of inputs using internal Pullup resistor. (short to ground to trigger) int sInPinmap[] = {32,33,34,35,36}; diff --git a/README.md b/README.md index cfa0940..66a56a6 100644 --- a/README.md +++ b/README.md @@ -67,7 +67,7 @@ The Send and receive Protocol is : To begin Transmitting Ready is send out and expects to receive E: to establish connection. Afterwards Data is exchanged. Data is only send everythime it changes once. - Inputs = 'I' -write only -Pin State: 0,1 + Inputs & Toggle Inputs = 'I' -write only -Pin State: 0,1 Outputs = 'O' -read only -Pin State: 0,1 PWM Outputs = 'P' -read only -Pin State: 0-255 Digital LED Outputs = 'D' -read only -Pin State: 0,1 diff --git a/arduino.py b/arduino.py index 243f776..a366064 100755 --- a/arduino.py +++ b/arduino.py @@ -21,7 +21,7 @@ import serial, time, hal # To begin Transmitting Ready is send out and expects to receive E: to establish connection. Afterwards Data is exchanged. # Data is only send everythime it changes once. -# Inputs = 'I' -write only -Pin State: 0,1 +# Inputs & Toggle Inputs = 'I' -write only -Pin State: 0,1 # Outputs = 'O' -read only -Pin State: 0,1 # PWM Outputs = 'P' -read only -Pin State: 0-255 # Digital LED Outputs = 'D' -read only -Pin State: 0,1 From 81bc5a03c76fee5e595a271d414520da1c27c6ea Mon Sep 17 00:00:00 2001 From: Alexander Richter Date: Tue, 28 Mar 2023 20:01:00 +0200 Subject: [PATCH 03/15] Bugfix couple of tiny stuff & spelling Errors --- .gitignore | 2 +- LinuxCNC_ArduinoConnector.ino | 13 +++++++------ arduino.py | 4 ++-- test.comp | 0 4 files changed, 10 insertions(+), 9 deletions(-) delete mode 100644 test.comp diff --git a/.gitignore b/.gitignore index a8a088e..5fe6e26 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,2 @@ - +.vscode .vscode/arduino.json diff --git a/LinuxCNC_ArduinoConnector.ino b/LinuxCNC_ArduinoConnector.ino index e07c15d..f897afe 100644 --- a/LinuxCNC_ArduinoConnector.ino +++ b/LinuxCNC_ArduinoConnector.ino @@ -64,19 +64,19 @@ int sInPinmap[] = {32,33,34,35,36}; #endif -//#define OUTPUTS //Use Arduino IO's as Outputs. Define how many Outputs you want in total and then which Pins you want to be Outputs. +#define OUTPUTS //Use Arduino IO's as Outputs. Define how many Outputs you want in total and then which Pins you want to be Outputs. #ifdef OUTPUTS const int Outputs = 9; //number of outputs int OutPinmap[] = {10,9,8,7,6,5,4,3,2,21}; #endif -//#define PWMOUTPUTS //Use Arduino PWM Capable IO's as PWM Outputs. Define how many PWM Outputs you want in total and then which Pins you want to be PWM Outputs. +#define PWMOUTPUTS //Use Arduino PWM Capable IO's as PWM Outputs. Define how many PWM Outputs you want in total and then which Pins you want to be PWM Outputs. #ifdef PWMOUTPUTS const int PwmOutputs = 2; //number of outputs int PwmOutPinmap[] = {12,11}; #endif -//#define AINPUTS //Use Arduino ADC's as Analog Inputs. Define how many Analog Inputs you want in total and then which Pins you want to be Analog Inputs. +#define AINPUTS //Use Arduino ADC's as Analog Inputs. Define how many Analog Inputs you want in total and then which Pins you want to be Analog Inputs. //Note that Analog Pin numbering is different to the Print on the PCB. #ifdef AINPUTS const int AInputs = 1; @@ -109,7 +109,7 @@ int margin = 20; //giving it some margin so Numbers dont jitter, make this number smaller if your knob has more than 50 Positions #endif -//#define ABSENCODER //Support of an Rotating Knob that was build in my Machine. It encodes 32 Positions with 5 Pins in Binary. This will generate 32 Pins in LinuxCNC Hal. +#define ABSENCODER //Support of an Rotating Knob that was build in my Machine. It encodes 32 Positions with 5 Pins in Binary. This will generate 32 Pins in LinuxCNC Hal. #ifdef ABSENCODER const int AbsEncPins[] = {27,28,31,29,30}; //1,2,4,8,16 #endif @@ -492,8 +492,8 @@ void readsInputs(){ sInState[i] = digitalRead(sInPinmap[i]); if (sInState[i] != soldInState[i] && millis()- lastsInputDebounce[i] > debounceDelay){ // Button state has changed and debounce delay has passed - soldInState[i] = sInState[i]; - if (sInState[i] == LOW) { + + if (sInState[i] == LOW || soldInState[i]== -1) { // Stuff after || is only there to send States at Startup // Button has been pressed togglesinputs[i] = !togglesinputs[i]; // Toggle the LED state @@ -504,6 +504,7 @@ void readsInputs(){ sendData('I',sInPinmap[i],togglesinputs[i]); // Turn the LED off } } + soldInState[i] = sInState[i]; lastsInputDebounce[i] = millis(); } } diff --git a/arduino.py b/arduino.py index a366064..407beef 100755 --- a/arduino.py +++ b/arduino.py @@ -84,7 +84,7 @@ AbsKnobPos = 32 DLEDcount = 8 -Debug = 1 +Debug = 0 ######## End of Config! ######## olddOutStates= [0]*Outputs oldPwmOutStates=[0]*PwmOutputs @@ -100,7 +100,7 @@ InPinmap += sInPinmap # setup Input halpins for port in range(Inputs): c.newpin("dIn.{}".format(InPinmap[port]), hal.HAL_BIT, hal.HAL_OUT) - c.newparam("dIn.{}-invert".format(InPinmap[port]), hal.HAL_BIT, hal.HAL_OUT) + c.newparam("dIn.{}-invert".format(InPinmap[port]), hal.HAL_BIT, hal.HAL_RW) # setup Output halpins for port in range(Outputs): diff --git a/test.comp b/test.comp deleted file mode 100644 index e69de29..0000000 From d6d2c0d49769320784f7d3a19f8fd40f9b680402 Mon Sep 17 00:00:00 2001 From: Alexander Richter Date: Wed, 29 Mar 2023 12:28:52 +0200 Subject: [PATCH 04/15] Working on better Documentation --- ArduinoChip.svg | 1162 +++++++++++++++++++++++++++++++++++++++++++++++ README.md | 91 +++- 2 files changed, 1235 insertions(+), 18 deletions(-) create mode 100644 ArduinoChip.svg diff --git a/ArduinoChip.svg b/ArduinoChip.svg new file mode 100644 index 0000000..3f61330 --- /dev/null +++ b/ArduinoChip.svg @@ -0,0 +1,1162 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/README.md b/README.md index 66a56a6..d66e336 100644 --- a/README.md +++ b/README.md @@ -1,13 +1,15 @@ # LinuxCNC_ArduinoConnector -By Alexander Richter, info@theartoftinkering.com 2022 + +![Chip loves Arduino.](ArduinoChip.png) +By Alexander Richter, info@theartoftinkering.com 2022 please consider supporting me on Patreon: https://www.patreon.com/theartoftinkering -For my CNC Machine i wanted to include more IO's than my Mesa card was offering. This Projekt enables to connect Arduino to LinuxCNC to include as many IO's as you wish. +This Projekt enables you to connect an Arduino to LinuxCNC and provides as many IO's as you could ever wish for. -This Software is used as IO Expansion for LinuxCNC. Here i am using a Mega 2560. +This Software is used as IO Expansion for LinuxCNC. I am using a Mega 2560. -+++It is NOT intended for timing and security relevant IO's. Don't use it for Emergency Stops or Endstop switches!+++ +**It is NOT intended for timing and security relevant IO's. Don't use it for Emergency Stops or Endstop switches!** You can create as many digital & analog Inputs, Outputs and PWM Outputs as your Arduino can handle. You can also generate "virtual Pins" by using latching Potentiometers, which are connected to one analog Pin, but are read in Hal as individual Pins. @@ -16,7 +18,7 @@ In LinuxCNC each LED is listed as one Output that can be set to HIGH and LOW. Fo This way, you can make them turn on or shut off or have them Change color, from Green to Red for example. -Currently the Software provides: +Currently the Software Supports: - analog Inputs - digital Inputs - digital Outputs @@ -31,23 +33,24 @@ For 2.8 however you have to change #!/usr/bin/python3.9 in the first line of ard # Installation -- configure the Firmware file to your demands and flash it to your arduino -- connect the arduino to your LinuxCNC Computer via USB -- install python-serial - sudo apt-get install python-serial -- edit arduino.py to match your arduino settings. -- also check if the Serial adress is correct for your Arduino. I found it easyest to run "sudo dmesg | grep tty" in Terminal. -- move arduino.py to /usr/bin and make it executable with chmod +x - sudo chmod +x arduino.py - sudo cp arduino.py /usr/bin/arduino - -- add to your hal file: loadusr arduino +1. configure the Firmware file to your demands and flash it to your arduino +2. connect the arduino to your LinuxCNC Computer via USB +3. install python-serial + '''sudo apt-get install python-serial''' +4. edit arduino.py to match your arduino settings. +5. also check if the Serial adress is correct for your Arduino. I found it easyest to run '''sudo dmesg | grep tty''' in Terminal. +6. move arduino.py to /usr/bin and make it executable with chmod +x + ''' + - sudo chmod +x arduino.py + - sudo cp arduino.py /usr/bin/arduino + ''' +7. add to your hal file: loadusr arduino # Testing -To test your Setup, you can run "halrun" in Terminal. +To test your Setup, you can run '''halrun''' in Terminal. Then you will see halcmd: -Enter "loadusr arduino" and then "show pin" +Enter '''loadusr arduino''' and then '''show pin''' All the Arduino generated Pins should now be listed and the State they are in. You can click buttons now and if you run show pin again the state should've changed. @@ -60,7 +63,59 @@ You can now use arduino pins in your hal file. Pin Names are named arduino.[Pin Type]-[Pin Number]. Example: arduino.digital-in-32 for Pin 32 on an Arduino Mega2560 +# analog Inputs +These are used for example to connect Potentiometers. You can add as many as your Arduino has Analog Pins. +The Software has a smoothing parameter, which will remove jitter. +# digital Inputs +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 +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". +The Setting in ARduino is: + int DledOnColors[DLEDcount][3] = { + {255,0,0} + }; + + int DledOffColors[DLEDcount][3] = { + {0,0,0} + }; + + +2. This LED should glow Green when "on" and Red when "off". + int DledOnColors[DLEDcount][3] = { + {0,255,0} + }; + + int DledOffColors[DLEDcount][3] = { + {255,0,0} + }; +Easy right? +# latching Potentiometers +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. + +# 1 absolute encoder input +Some rotary Selector Switches work with Binary Encoded Positions. The Software Supports Encoders with 32 Positions. (this could be more if requested) +For each Bit one Pin is needed. So for all 32 Positions 5 Pins are needed = 1,2,4,8,16 + +# Status LED +The Arduino only works, if LinuxCNC is running and an USB Connection is established. +To give optical Feedback of the State of the connection a Status LED setting is provided. +This can be either an LED connected to an Output Pin or you can select one LED in your Digital LED Chain. +It will flash slowly after startup, when it waits for communication setup by LinuxCNC. +It will glow constantly when everything works. +it Will flash short when Connection was lost. # Serial communication over USB The Send and receive Protocol is : From cd563131ead1cfb0a10ec791f962ee08fed18a10 Mon Sep 17 00:00:00 2001 From: Alexander Richter Date: Wed, 29 Mar 2023 12:33:30 +0200 Subject: [PATCH 05/15] fix some display Bugs --- README.md | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index d66e336..335bbeb 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ # LinuxCNC_ArduinoConnector -![Chip loves Arduino.](ArduinoChip.png) +![Chip loves Arduino.](/ArduinoChip.png) By Alexander Richter, info@theartoftinkering.com 2022 please consider supporting me on Patreon: https://www.patreon.com/theartoftinkering @@ -36,21 +36,20 @@ For 2.8 however you have to change #!/usr/bin/python3.9 in the first line of ard 1. configure the Firmware file to your demands and flash it to your arduino 2. connect the arduino to your LinuxCNC Computer via USB 3. install python-serial - '''sudo apt-get install python-serial''' + ```sudo apt-get install python-serial``` 4. edit arduino.py to match your arduino settings. -5. also check if the Serial adress is correct for your Arduino. I found it easyest to run '''sudo dmesg | grep tty''' in Terminal. +5. also check if the Serial adress is correct for your Arduino. I found it easyest to run ```sudo dmesg | grep tty``` in Terminal. 6. move arduino.py to /usr/bin and make it executable with chmod +x - ''' - - sudo chmod +x arduino.py - - sudo cp arduino.py /usr/bin/arduino - ''' -7. add to your hal file: loadusr arduino + ```sudo chmod +x arduino.py ``` + ```sudo cp arduino.py /usr/bin/arduino ``` + +7. add to your hal file: ```loadusr arduino``` # Testing -To test your Setup, you can run '''halrun''' in Terminal. +To test your Setup, you can run ```halrun``` in Terminal. Then you will see halcmd: -Enter '''loadusr arduino''' and then '''show pin''' +Enter ```loadusr arduino``` and then ```show pin``` All the Arduino generated Pins should now be listed and the State they are in. You can click buttons now and if you run show pin again the state should've changed. From a886d7f15357b92a5dae7e55751aab72ec5eed38 Mon Sep 17 00:00:00 2001 From: Alexander Richter Date: Wed, 29 Mar 2023 12:35:14 +0200 Subject: [PATCH 06/15] try to fix again --- README.md | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 335bbeb..ea42fe6 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ # LinuxCNC_ArduinoConnector -![Chip loves Arduino.](/ArduinoChip.png) +![Chip loves Arduino.](/ArduinoChip.svg) By Alexander Richter, info@theartoftinkering.com 2022 please consider supporting me on Patreon: https://www.patreon.com/theartoftinkering @@ -9,7 +9,8 @@ This Projekt enables you to connect an Arduino to LinuxCNC and provides as many This Software is used as IO Expansion for LinuxCNC. I am using a Mega 2560. -**It is NOT intended for timing and security relevant IO's. Don't use it for Emergency Stops or Endstop switches!** +## It is NOT intended for timing and security relevant IO's. Don't use it for Emergency Stops or Endstop switches! ## + You can create as many digital & analog Inputs, Outputs and PWM Outputs as your Arduino can handle. You can also generate "virtual Pins" by using latching Potentiometers, which are connected to one analog Pin, but are read in Hal as individual Pins. From ec6323e55839d0e65b7a9b182d35124421c7980b Mon Sep 17 00:00:00 2001 From: Alexander Richter Date: Wed, 29 Mar 2023 12:42:47 +0200 Subject: [PATCH 07/15] hopefully final changes to readme.md --- README.md | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index ea42fe6..ec085ef 100644 --- a/README.md +++ b/README.md @@ -1,19 +1,19 @@ # LinuxCNC_ArduinoConnector -![Chip loves Arduino.](/ArduinoChip.svg) +![LinuxCNC Arduino Connector.](/ArduinoChip.svg | width=200) + + By Alexander Richter, info@theartoftinkering.com 2022 please consider supporting me on Patreon: https://www.patreon.com/theartoftinkering This Projekt enables you to connect an Arduino to LinuxCNC and provides as many IO's as you could ever wish for. - -This Software is used as IO Expansion for LinuxCNC. I am using a Mega 2560. +This Software is used as IO Expansion for LinuxCNC. ## It is NOT intended for timing and security relevant IO's. Don't use it for Emergency Stops or Endstop switches! ## You can create as many digital & analog Inputs, Outputs and PWM Outputs as your Arduino can handle. -You can also generate "virtual Pins" by using latching Potentiometers, which are connected to one analog Pin, but are read in Hal as individual Pins. 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. In LinuxCNC each LED is listed as one Output that can be set to HIGH and LOW. For both States you can define a color per LED. This way, you can make them turn on or shut off or have them Change color, from Green to Red for example. @@ -27,6 +27,11 @@ Currently the Software Supports: - latching Potentiometers - 1 absolute encoder input +TODO +-[ ] Matrix Keyboard Support + +Should i add this? +-[ ] RC Servo Support # compatiblity This software works with LinuxCNC 2.8, 2.9 and 2.10. From d6dc005cb8d9c3146e2513749cf6b4074f3fba40 Mon Sep 17 00:00:00 2001 From: Alexander Richter Date: Wed, 29 Mar 2023 12:45:42 +0200 Subject: [PATCH 08/15] fix picture Bug --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index ec085ef..9270179 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ # LinuxCNC_ArduinoConnector -![LinuxCNC Arduino Connector.](/ArduinoChip.svg | width=200) +![LinuxCNC Arduino Connector.](/ArduinoChip.svg | width = "200") By Alexander Richter, info@theartoftinkering.com 2022 @@ -148,4 +148,4 @@ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software -Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA \ No newline at end of file +Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA From 505a44e8e7a97387e05e2c6e0a5690c36c2688f2 Mon Sep 17 00:00:00 2001 From: Alexander Richter Date: Wed, 29 Mar 2023 12:47:36 +0200 Subject: [PATCH 09/15] sick of it, hopefully Image works now --- README.md | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/README.md b/README.md index 9270179..0801002 100644 --- a/README.md +++ b/README.md @@ -1,8 +1,7 @@ # LinuxCNC_ArduinoConnector -![LinuxCNC Arduino Connector.](/ArduinoChip.svg | width = "200") - + By Alexander Richter, info@theartoftinkering.com 2022 please consider supporting me on Patreon: https://www.patreon.com/theartoftinkering From 8334fe49a8f17e5ab2d49566729481cd5bb3b861 Mon Sep 17 00:00:00 2001 From: Alexander Richter Date: Wed, 29 Mar 2023 12:56:43 +0200 Subject: [PATCH 10/15] formating --- README.md | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/README.md b/README.md index 0801002..b7ba670 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ # LinuxCNC_ArduinoConnector - + By Alexander Richter, info@theartoftinkering.com 2022 please consider supporting me on Patreon: https://www.patreon.com/theartoftinkering @@ -117,22 +117,22 @@ For each Bit one Pin is needed. So for all 32 Positions 5 Pins are needed = 1,2, The Arduino only works, if LinuxCNC is running and an USB Connection is established. To give optical Feedback of the State of the connection a Status LED setting is provided. This can be either an LED connected to an Output Pin or you can select one LED in your Digital LED Chain. -It will flash slowly after startup, when it waits for communication setup by LinuxCNC. -It will glow constantly when everything works. -it Will flash short when Connection was lost. +- It will flash slowly after startup, when it waits for communication setup by LinuxCNC. +- It will glow constantly when everything works. +- it Will flash short when Connection was lost. # Serial communication over USB The Send and receive Protocol is : To begin Transmitting Ready is send out and expects to receive E: to establish connection. Afterwards Data is exchanged. Data is only send everythime it changes once. - Inputs & Toggle Inputs = 'I' -write only -Pin State: 0,1 - Outputs = 'O' -read only -Pin State: 0,1 - PWM Outputs = 'P' -read only -Pin State: 0-255 - Digital LED Outputs = 'D' -read only -Pin State: 0,1 - Analog Inputs = 'A' -write only -Pin State: 0-1024 - Latching Potentiometers = 'L' -write only -Pin State: 0-max Position - Absolute Encoder input = 'K' -write only -Pin State: 0-32 + Inputs & Toggle Inputs = 'I' -write only -Pin State: 0,1 + Outputs = 'O' -read only -Pin State: 0,1 + PWM Outputs = 'P' -read only -Pin State: 0-255 + Digital LED Outputs = 'D' -read only -Pin State: 0,1 + Analog Inputs = 'A' -write only -Pin State: 0-1024 + Latching Potentiometers = 'L' -write only -Pin State: 0-max Position + Absolute Encoder input = 'K' -write only -Pin State: 0-32 Command 'E0:0' is used for connectivity checks and is send every 5 seconds as keep alive signal. If connection is lost the arduino begins flashing an LED to alarm the User. From b1915f64209af24935406f30f22031995696df19 Mon Sep 17 00:00:00 2001 From: Alexander Richter Date: Wed, 29 Mar 2023 13:09:58 +0200 Subject: [PATCH 11/15] more finetuning of Readme.md --- README.md | 40 ++++++++++++++++++---------------------- 1 file changed, 18 insertions(+), 22 deletions(-) diff --git a/README.md b/README.md index b7ba670..10e5d91 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ # LinuxCNC_ArduinoConnector - + By Alexander Richter, info@theartoftinkering.com 2022 please consider supporting me on Patreon: https://www.patreon.com/theartoftinkering @@ -86,24 +86,16 @@ LED colors are set with values 0-255 for Red, Green and Blue. 0 beeing off and 2 Here are two examples: 1. This LED should be glowing Red when "on" and just turn off when "off". -The Setting in ARduino is: - int DledOnColors[DLEDcount][3] = { - {255,0,0} - }; +The Setting in Arduino is: + ```int DledOnColors[DLEDcount][3] = {{255,0,0}};``` - int DledOffColors[DLEDcount][3] = { - {0,0,0} - }; + ```int DledOffColors[DLEDcount][3] = {{0,0,0}};``` 2. This LED should glow Green when "on" and Red when "off". - int DledOnColors[DLEDcount][3] = { - {0,255,0} - }; + ```int DledOnColors[DLEDcount][3] = {{0,255,0}};``` - int DledOffColors[DLEDcount][3] = { - {255,0,0} - }; + ```int DledOffColors[DLEDcount][3] = {{255,0,0}};``` Easy right? # latching Potentiometers 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. @@ -125,16 +117,20 @@ This can be either an LED connected to an Output Pin or you can select one LED i The Send and receive Protocol is : To begin Transmitting Ready is send out and expects to receive E: to establish connection. Afterwards Data is exchanged. Data is only send everythime it changes once. +| Signal | Header |direction |Values | +| ------------- | ------------- |------------- |------------- | +| Inputs & Toggle Inputs | I | write only |0,1 | +| Outputs | O | read only |0,1 | +| PWM Outputs | P | read only |0-255 | +| Digital LED Outputs | D | read only |0,1 | +| Analog Inputs | A | write only |0-1024 | +| Latching Potentiometers | L | write only |0-max Position| +| Absolute Encoder input | K | write only |0-32 | +| ------------- | ------------- |------------- |------------- | +| Connection established | E | read/ write |0:0 | - Inputs & Toggle Inputs = 'I' -write only -Pin State: 0,1 - Outputs = 'O' -read only -Pin State: 0,1 - PWM Outputs = 'P' -read only -Pin State: 0-255 - Digital LED Outputs = 'D' -read only -Pin State: 0,1 - Analog Inputs = 'A' -write only -Pin State: 0-1024 - Latching Potentiometers = 'L' -write only -Pin State: 0-max Position - Absolute Encoder input = 'K' -write only -Pin State: 0-32 -Command 'E0:0' is used for connectivity checks and is send every 5 seconds as keep alive signal. If connection is lost the arduino begins flashing an LED to alarm the User. +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. # License This program is free software; you can redistribute it and/or modify From 3fb3aa0cdfe17bf33d85d4f3c707e15e20bd1040 Mon Sep 17 00:00:00 2001 From: Alexander Richter Date: Wed, 29 Mar 2023 13:36:08 +0200 Subject: [PATCH 12/15] final Update for today --- README.md | 30 ++++++++++++++++++++---------- 1 file changed, 20 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index 10e5d91..60d2e0f 100644 --- a/README.md +++ b/README.md @@ -26,16 +26,23 @@ Currently the Software Supports: - latching Potentiometers - 1 absolute encoder input -TODO +TODO -[ ] Matrix Keyboard Support -Should i add this? +Should i add this? -[ ] RC Servo Support -# compatiblity +# Compatiblity 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. +# Configuration +To Install LinuxCNC_ArduinoConnector.ino on your Arduino first work through the settings in the beginning of the file. +The Settings are commented in the file. + +To test you Arduino you can connect to it after flashing with the Arduino IDE. Set your Baudrate to 115200. +In the Beginning the ARduino will Spam ```E0:0``` to the console. This is used to establish connection. +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) # Installation 1. configure the Firmware file to your demands and flash it to your arduino @@ -67,16 +74,16 @@ You can now use arduino pins in your hal file. Pin Names are named arduino.[Pin Type]-[Pin Number]. Example: arduino.digital-in-32 for Pin 32 on an Arduino Mega2560 -# analog Inputs +# Analog Inputs These are used for example to connect Potentiometers. You can add as many as your Arduino has Analog Pins. The Software has a smoothing parameter, which will remove jitter. -# digital Inputs +# Digital Inputs 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 +# Digital Outputs 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. @@ -97,7 +104,7 @@ The Setting in Arduino is: ```int DledOffColors[DLEDcount][3] = {{255,0,0}};``` Easy right? -# latching Potentiometers +# Latching Potentiometers / Selector Switches 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. @@ -115,8 +122,12 @@ This can be either an LED connected to an Output Pin or you can select one LED i # Serial communication over USB The Send and receive Protocol is : -To begin Transmitting Ready is send out and expects to receive E: to establish connection. Afterwards Data is exchanged. -Data is only send everythime it changes once. +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. + | Signal | Header |direction |Values | | ------------- | ------------- |------------- |------------- | | Inputs & Toggle Inputs | I | write only |0,1 | @@ -126,7 +137,6 @@ Data is only send everythime it changes once. | Analog Inputs | A | write only |0-1024 | | Latching Potentiometers | L | write only |0-max Position| | Absolute Encoder input | K | write only |0-32 | -| ------------- | ------------- |------------- |------------- | | Connection established | E | read/ write |0:0 | From a1875bfd153895f310e3228eb785ffa86c3a2071 Mon Sep 17 00:00:00 2001 From: Alexander Richter Date: Wed, 29 Mar 2023 14:17:52 +0200 Subject: [PATCH 13/15] made setttings standart Disabled --- LinuxCNC_ArduinoConnector.ino | 13 ++++++++----- README.md | 19 ++++++++++--------- 2 files changed, 18 insertions(+), 14 deletions(-) diff --git a/LinuxCNC_ArduinoConnector.ino b/LinuxCNC_ArduinoConnector.ino index f897afe..b1d0df6 100644 --- a/LinuxCNC_ArduinoConnector.ino +++ b/LinuxCNC_ArduinoConnector.ino @@ -70,13 +70,13 @@ int OutPinmap[] = {10,9,8,7,6,5,4,3,2,21}; #endif -#define PWMOUTPUTS //Use Arduino PWM Capable IO's as PWM Outputs. Define how many PWM Outputs you want in total and then which Pins you want to be PWM Outputs. +//#define PWMOUTPUTS //Use Arduino PWM Capable IO's as PWM Outputs. Define how many PWM Outputs you want in total and then which Pins you want to be PWM Outputs. #ifdef PWMOUTPUTS const int PwmOutputs = 2; //number of outputs int PwmOutPinmap[] = {12,11}; #endif -#define AINPUTS //Use Arduino ADC's as Analog Inputs. Define how many Analog Inputs you want in total and then which Pins you want to be Analog Inputs. +//#define AINPUTS //Use Arduino ADC's as Analog Inputs. Define how many Analog Inputs you want in total and then which Pins you want to be Analog Inputs. //Note that Analog Pin numbering is different to the Print on the PCB. #ifdef AINPUTS const int AInputs = 1; @@ -109,7 +109,7 @@ int margin = 20; //giving it some margin so Numbers dont jitter, make this number smaller if your knob has more than 50 Positions #endif -#define ABSENCODER //Support of an Rotating Knob that was build in my Machine. It encodes 32 Positions with 5 Pins in Binary. This will generate 32 Pins in LinuxCNC Hal. +//#define ABSENCODER //Support of an Rotating Knob that was build in my Machine. It encodes 32 Positions with 5 Pins in Binary. This will generate 32 Pins in LinuxCNC Hal. #ifdef ABSENCODER const int AbsEncPins[] = {27,28,31,29,30}; //1,2,4,8,16 #endif @@ -158,8 +158,8 @@ const int DLEDBrightness = 70; //Brightness of the LED's 0-100% int DledOnColors[DLEDcount][3] = { + {0,0,255}, {255,0,0}, - {0,255,255}, {0,255,0}, {0,255,0}, {0,255,0}, @@ -170,7 +170,7 @@ int DledOffColors[DLEDcount][3] = { {0,0,0}, - {0,255,0}, + {0,0,0}, {255,0,0}, {255,0,0}, {255,0,0}, @@ -185,6 +185,9 @@ Adafruit_NeoPixel strip(DLEDcount, DLEDPin, NEO_GRB + NEO_KHZ800);//Color sequen #endif +//####################################### END OF CONFIG ########################### + + //#define DEBUG diff --git a/README.md b/README.md index 60d2e0f..1acaa8a 100644 --- a/README.md +++ b/README.md @@ -19,18 +19,19 @@ This way, you can make them turn on or shut off or have them Change color, from Currently the Software Supports: -- analog Inputs -- digital Inputs -- digital Outputs -- support of Digital RGB LEDs like WS2812 or PL9823 -- latching Potentiometers -- 1 absolute encoder input +- Analog Inputs +- Digital Inputs +- Digital Outputs +- PWM Outputs +- Digital RGB LEDs like WS2812 or PL9823 +- latching Potentiometers / Selector Switches +- 1 absolute encoder Selector Switch TODO --[ ] Matrix Keyboard Support +- Matrix Keyboard Support -Should i add this? --[ ] RC Servo Support +Should this be supported? +- RC Servo Support # Compatiblity This software works with LinuxCNC 2.8, 2.9 and 2.10. From 6df5dba5e2cde023ce04af15f63b7b6051b11262 Mon Sep 17 00:00:00 2001 From: Alexander Richter Date: Thu, 30 Mar 2023 00:59:11 +0200 Subject: [PATCH 14/15] small Readme changes --- README.md | 31 ++++++++++++++++++++----------- 1 file changed, 20 insertions(+), 11 deletions(-) diff --git a/README.md b/README.md index 1acaa8a..85aeca4 100644 --- a/README.md +++ b/README.md @@ -4,7 +4,12 @@ By Alexander Richter, info@theartoftinkering.com 2022 -please consider supporting me on Patreon: https://www.patreon.com/theartoftinkering +please consider supporting me on Patreon: +https://www.patreon.com/theartoftinkering + +Website: https://theartoftinkering.com +Youtube: https://youtube.com/@theartoftinkering + This Projekt enables you to connect an Arduino to LinuxCNC and provides as many IO's as you could ever wish for. This Software is used as IO Expansion for LinuxCNC. @@ -29,6 +34,8 @@ Currently the Software Supports: TODO - Matrix Keyboard Support +- Rotary Encoder Input + Should this be supported? - RC Servo Support @@ -53,16 +60,16 @@ Just return ```E0:0``` to it. You can now communicate with the Arduino. Further 4. edit arduino.py to match your arduino settings. 5. also check if the Serial adress is correct for your Arduino. I found it easyest to run ```sudo dmesg | grep tty``` in Terminal. 6. move arduino.py to /usr/bin and make it executable with chmod +x - ```sudo chmod +x arduino.py ``` - ```sudo cp arduino.py /usr/bin/arduino ``` + ```sudo chmod +x arduino.py ``` + ```sudo cp arduino.py /usr/bin/arduino ``` -7. add to your hal file: ```loadusr arduino``` +7. add to your hal file: ```loadusr arduino``` # Testing To test your Setup, you can run ```halrun``` in Terminal. Then you will see halcmd: -Enter ```loadusr arduino``` and then ```show pin``` +Enter ```loadusr arduino``` and then ```show pin``` All the Arduino generated Pins should now be listed and the State they are in. You can click buttons now and if you run show pin again the state should've changed. @@ -94,17 +101,19 @@ LED colors are set with values 0-255 for Red, Green and Blue. 0 beeing off and 2 Here are two examples: 1. This LED should be glowing Red when "on" and just turn off when "off". -The Setting in Arduino is: - ```int DledOnColors[DLEDcount][3] = {{255,0,0}};``` + The Setting in Arduino is: + ```int DledOnColors[DLEDcount][3] = {{255,0,0}};``` - ```int DledOffColors[DLEDcount][3] = {{0,0,0}};``` + ```int DledOffColors[DLEDcount][3] = {{0,0,0}};``` 2. This LED should glow Green when "on" and Red when "off". - ```int DledOnColors[DLEDcount][3] = {{0,255,0}};``` + ```int DledOnColors[DLEDcount][3] = {{0,255,0}};``` + + ```int DledOffColors[DLEDcount][3] = {{255,0,0}};``` + + - ```int DledOffColors[DLEDcount][3] = {{255,0,0}};``` -Easy right? # Latching Potentiometers / Selector Switches 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. From 1092babaaad308ff5be7bd3abc3588ce804a3363 Mon Sep 17 00:00:00 2001 From: Alexander Richter Date: Thu, 30 Mar 2023 23:37:00 +0200 Subject: [PATCH 15/15] more doku info --- README.md | 21 ++++++++++++++------- arduino.py | 45 +++++++++++++++++++++++---------------------- 2 files changed, 37 insertions(+), 29 deletions(-) diff --git a/README.md b/README.md index 85aeca4..d5b5323 100644 --- a/README.md +++ b/README.md @@ -7,7 +7,7 @@ By Alexander Richter, info@theartoftinkering.com 2022 please consider supporting me on Patreon: https://www.patreon.com/theartoftinkering -Website: https://theartoftinkering.com +Website: https://theartoftinkering.com Youtube: https://youtube.com/@theartoftinkering @@ -57,13 +57,17 @@ Just return ```E0:0``` to it. You can now communicate with the Arduino. Further 2. connect the arduino to your LinuxCNC Computer via USB 3. install python-serial ```sudo apt-get install python-serial``` -4. edit arduino.py to match your arduino settings. -5. also check if the Serial adress is correct for your Arduino. I found it easyest to run ```sudo dmesg | grep tty``` in Terminal. -6. move arduino.py to /usr/bin and make it executable with chmod +x +4. edit arduino.py to match your arduino settings. If you're running 2.8 change + #!/usr/bin/python3.9 in the first line of arduino.py to #!/usr/bin/python2.7. +5. also check if the Serial adress is correct for your Arduino. I found it easyest to run + ```sudo dmesg | grep tty``` in Terminal while plugging and unplugging the arduino a couple of times and whatch which entry is changing. +6. make arduino.py executable with chmod +x, delete the suffix .py and copy +it to /usr/bin ```sudo chmod +x arduino.py ``` ```sudo cp arduino.py /usr/bin/arduino ``` -7. add to your hal file: ```loadusr arduino``` +7. add this entry to the end of your hal file: ```loadusr arduino``` + # Testing To test your Setup, you can run ```halrun``` in Terminal. @@ -112,15 +116,18 @@ Here are two examples: ```int DledOffColors[DLEDcount][3] = {{255,0,0}};``` - +Depending on the used LED Chipset, Color sequence can vary. Please try, which value correspons to which color with your LED's. +Typically it should be R G B for WS2812 and G R B for PL9823. +You can mix both in one chain, just modify the color values accordingly. # Latching Potentiometers / Selector Switches 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. -# 1 absolute encoder input +# 1 binary encoded Selector Switch input / absolute encoder Some rotary Selector Switches work with Binary Encoded Positions. The Software Supports Encoders with 32 Positions. (this could be more if requested) For each Bit one Pin is needed. So for all 32 Positions 5 Pins are needed = 1,2,4,8,16 +If this feature is enabled, 32 Hal Pins will be created in LinuxCNC. # Status LED The Arduino only works, if LinuxCNC is running and an USB Connection is established. diff --git a/arduino.py b/arduino.py index 407beef..1e7ffb2 100755 --- a/arduino.py +++ b/arduino.py @@ -45,46 +45,47 @@ import serial, time, hal # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -c = hal.component("arduino") #name that we will cal pins from in hal -connection = '/dev/ttyACM0' +c = hal.component("arduino") #name that we will cal pins from in hal +connection = '/dev/ttyACM0' #this is the port your Arduino is connected to. You can check with ""sudo dmesg | grep tty"" in Terminal -# Set how many Inputs you have programmed in Arduino and which pins are Inputs +# Set how many Inputs you have programmed in Arduino and which pins are Inputs, Set Inputs = 0 to disable Inputs = 5 InPinmap = [37,38,39,40,41] -# Set how many Toggled Inputs you have programmed in Arduino and which pins are Toggled Inputs +# Set how many Toggled ("sticky") Inputs you have programmed in Arduino and which pins are Toggled Inputs , Set SInputs = 0 to disable SInputs = 5 sInPinmap = [32,33,34,35,36] -# Set how many Outputs you have programmed in Arduino and which pins are Outputs -Outputs = 9 -OutPinmap = [10,9,8,7,6,5,4,3,2,21] +# Set how many Outputs you have programmed in Arduino and which pins are Outputs, Set Outputs = 0 to disable +Outputs = 9 #9 Outputs, Set Outputs = 0 to disable +OutPinmap = [10,9,8,7,6,5,4,3,2,21] -# Set how many PWM Outputs you have programmed in Arduino and which pins are PWM Outputs -PwmOutputs = 2 -PwmOutPinmap = [11,12] +# Set how many PWM Outputs you have programmed in Arduino and which pins are PWM Outputs, you can set as many as your Arduino has PWM pins. List the connected pins below. +PwmOutputs = 2 #number of PwmOutputs, Set PwmOutputs = 0 to disable +PwmOutPinmap = [11,12] #PwmPutput connected to Pin 11 & 12 -# Set how many Analog Inputs you have programmed in Arduino and which pins are Analog Inputs -AInputs = 1 -AInPinmap = [1] +# Set how many Analog Inputs you have programmed in Arduino and which pins are Analog Inputs, you can set as many as your Arduino has Analog pins. List the connected pins below. +AInputs = 1 #number of AInputs, Set AInputs = 0 to disable +AInPinmap = [1] #Potentiometer connected to Pin 1 (A0) -# Set how many Latching Analog Inputs you have programmed in Arduino and how many latches there are -LPoti = 2 -LPotiLatches = [[2,9], - [3,4]] +# Set how many Latching Analog Inputs you have programmed in Arduino and how many latches there are, you can set as many as your Arduino has Analog pins. List the connected pins below. +LPoti = 2 #number of LPotis, Set LPoti = 0 to disable +LPotiLatches = [[2,9], #Poti is connected to Pin 2 (A1) and has 9 positions + [3,4]] #Poti is connected to Pin 3 (A2) and has 4 positions # Set if you have an Absolute Encoder Knob and how many positions it has (only one supported, as i don't think they are very common and propably nobody uses these anyway) -AbsKnob = 1 +# Set AbsKnob = 0 to disable +AbsKnob = 0 #1 enable AbsKnobPos = 32 # Set how many Digital LED's you have connected. DLEDcount = 8 -Debug = 0 +Debug = 0 #only works when this script is run from halrun in Terminal. "halrun","loadusr arduino" now Debug info will be displayed. ######## End of Config! ######## olddOutStates= [0]*Outputs oldPwmOutStates=[0]*PwmOutputs @@ -198,7 +199,7 @@ def managageOutputs(): while True: try: - data = arduino.readline().decode('utf-8') + data = arduino.readline().decode('utf-8') #read Data received from Arduino and decode it if (Debug):print ("I received:{}".format(data)) data = data.split(":",1) @@ -273,9 +274,9 @@ while True: if (Debug):print ("I received garbage") arduino.flush() - if firstcom == 1: managageOutputs() + if firstcom == 1: managageOutputs() #if ==1: E0:0 has been exchanged, which means Arduino knows that LinuxCNC is running and starts sending and receiving Data - if keepAlive(event): + if keepAlive(event): #keep com alive. This is send to help Arduino detect connection loss. arduino.write(b"E:\n") if (Debug):print("keepAlive") event = time.time()