more doku info

This commit is contained in:
Alexander Richter 2023-03-30 23:37:00 +02:00
parent 6df5dba5e2
commit 1092babaaa
2 changed files with 37 additions and 29 deletions

View File

@ -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.

View File

@ -46,45 +46,46 @@ import serial, time, hal
c = hal.component("arduino") #name that we will cal pins from in hal
connection = '/dev/ttyACM0'
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
# 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()