From 2bf2dfba4f75d23c3cf79e8b98e95643fa9313dc Mon Sep 17 00:00:00 2001 From: Alexander Richter Date: Tue, 2 May 2023 19:16:06 +0200 Subject: [PATCH] renamed Absolute Encoder to Binary Selector Switch --- LinuxCNC_ArduinoConnector.ino | 40 ++++++++++++++++++----------------- README.md | 10 ++++----- arduino.py | 28 ++++++++++++------------ 3 files changed, 40 insertions(+), 38 deletions(-) diff --git a/LinuxCNC_ArduinoConnector.ino b/LinuxCNC_ArduinoConnector.ino index e6d08ab..94df787 100644 --- a/LinuxCNC_ArduinoConnector.ino +++ b/LinuxCNC_ArduinoConnector.ino @@ -12,10 +12,12 @@ Currently the Software provides: - analog Inputs - latching Potentiometers - - 1 absolute encoder input + - 1 binary encoded selector Switch - digital Inputs - digital Outputs + - Matrix Keypad + 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. @@ -26,7 +28,7 @@ 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 + binary encoded Selector = 'K' -write only -Pin State: 0-32 Keyboard Input: Matrix Keypad = 'M' -write only -Pin State: Number of Matrix Key. @@ -118,9 +120,9 @@ Note that Analog Pin numbering is different to the Print on the PCB. 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. -#ifdef ABSENCODER - const int AbsEncPins[] = {27,28,31,29,30}; //1,2,4,8,16 +//#define BINSEL //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 BINSEL + const int BinSelKnobPins[] = {27,28,31,29,30}; //1,2,4,8,16 #endif @@ -257,7 +259,7 @@ const int debounceDelay = 50; int Lpoti[LPotis]; int oldLpoti[LPotis]; #endif -#ifdef ABSENCODER +#ifdef BINSEL int oldAbsEncState; #endif #ifdef KEYPAD @@ -328,12 +330,12 @@ void setup() { pinMode(StatLedPin, OUTPUT); #endif -#ifdef ABSENCODER - pinMode(AbsEncPins[0], INPUT_PULLUP); - pinMode(AbsEncPins[1], INPUT_PULLUP); - pinMode(AbsEncPins[2], INPUT_PULLUP); - pinMode(AbsEncPins[3], INPUT_PULLUP); - pinMode(AbsEncPins[4], INPUT_PULLUP); +#ifdef BINSEL + pinMode(BinSelKnobPins[0], INPUT_PULLUP); + pinMode(BinSelKnobPins[1], INPUT_PULLUP); + pinMode(BinSelKnobPins[2], INPUT_PULLUP); + pinMode(BinSelKnobPins[3], INPUT_PULLUP); + pinMode(BinSelKnobPins[4], INPUT_PULLUP); #endif #ifdef DLED @@ -380,7 +382,7 @@ void loop() { #ifdef LPOTIS readLPoti(); //read LPotis & send data #endif -#ifdef ABSENCODER +#ifdef BINSEL readAbsKnob(); //read ABS Encoder & send data #endif @@ -561,22 +563,22 @@ void readsInputs(){ } #endif -#ifdef ABSENCODER +#ifdef BINSEL int readAbsKnob(){ int var = 0; - if(digitalRead(AbsEncPins[0])==1){ + if(digitalRead(BinSelKnobPins[0])==1){ var += 1; } - if(digitalRead(AbsEncPins[1])==1){ + if(digitalRead(BinSelKnobPins[1])==1){ var += 2; } - if(digitalRead(AbsEncPins[2])==1){ + if(digitalRead(BinSelKnobPins[2])==1){ var += 4; } - if(digitalRead(AbsEncPins[3])==1){ + if(digitalRead(BinSelKnobPins[3])==1){ var += 8; } - if(digitalRead(AbsEncPins[4])==1){ + if(digitalRead(BinSelKnobPins[4])==1){ var += 16; } if(var != oldAbsEncState){ diff --git a/README.md b/README.md index 4632083..acd4de3 100644 --- a/README.md +++ b/README.md @@ -24,19 +24,19 @@ This way, you can make them turn on or shut off or have them Change color, from Currently the Software Supports: -- Analog Inputs +- Analog Inputs - Digital Inputs - Digital Outputs - PWM Outputs - Digital RGB LEDs like WS2812 or PL9823 - latching Potentiometers / Selector Switches -- 1 absolute encoder Selector Switch +- 1 binary encoded Selector Switch +- Matrix Keyboard Support + TODO -- Matrix Keyboard Support - Rotary Encoder Input - Should this be supported? - RC Servo Support @@ -124,7 +124,7 @@ You can mix both in one chain, just modify the color values accordingly. 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 binary encoded Selector Switch input / absolute encoder +# 1 binary encoded Selector Switch 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 If this feature is enabled, 32 Hal Pins will be created in LinuxCNC. diff --git a/arduino.py b/arduino.py index fa9ba9b..d93c94b 100644 --- a/arduino.py +++ b/arduino.py @@ -13,7 +13,7 @@ import serial, time, hal # Currently the Software provides: # - analog Inputs # - latching Potentiometers -# - 1 absolute encoder input +# - 1 binary encoded Selector Switch # - digital Inputs # - digital Outputs @@ -27,7 +27,7 @@ import serial, time, hal # 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 +# binary encoded Selector = 'K' -write only -Pin State: 0-32 # Matrix Keypad = 'M' -write only -Pin State: 0,1 @@ -77,10 +77,10 @@ LPoti = 0 #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) -# Set AbsKnob = 0 to disable -AbsKnob = 0 #1 enable -AbsKnobPos = 32 +# Set if you have an binary encoded Selector Switch and how many positions it has (only one supported, as i don't think they are very common and propably nobody uses these anyway) +# Set BinSelKnob = 0 to disable +BinSelKnob = 0 #1 enable +BinSelKnobPos = 32 # Set how many Digital LED's you have connected. DLEDcount = 0 @@ -169,9 +169,9 @@ for Poti in range(LPoti): c.newpin("LPoti.{}.{}" .format(LPotiLatches[Poti][0],Pin), hal.HAL_BIT, hal.HAL_OUT) # setup Absolute Encoder Knob halpins -if AbsKnob: - for port in range(AbsKnobPos): - c.newpin("AbsKnob.{}".format(port), hal.HAL_BIT, hal.HAL_OUT) +if BinSelKnob: + for port in range(BinSelKnobPos): + c.newpin("BinSelKnob.{}".format(port), hal.HAL_BIT, hal.HAL_OUT) # setup Digital LED halpins if DLEDcount > 0: @@ -304,13 +304,13 @@ while True: elif cmd == "K": firstcom = 1 - for port in range(AbsKnobPos): + for port in range(BinSelKnobPos): if port == value: - c["AbsKnob.{}".format(port)] = 1 - if(Debug):print("AbsKnob.{}:{}".format(port,1)) + c["BinSelKnob.{}".format(port)] = 1 + if(Debug):print("BinSelKnob.{}:{}".format(port,1)) else: - c["AbsKnob.{}".format(port)] = 0 - if(Debug):print("AbsKnob.{}:{}".format(port,0)) + c["BinSelKnob.{}".format(port)] = 0 + if(Debug):print("BinSelKnob.{}:{}".format(port,0)) elif cmd == "M": firstcom = 1