configuring GPIO for a Raspberry Pi 4B

More
14 Aug 2024 18:55 #307730 by dave.franchino@gmail.com
Hey kind folks,

I am working to configure a Raspberry pi 4B to run LinuxCNC for a two-axis machine I'm building.  I am using the HAL driver for Raspberrry PI GPIO pins (hal_pi_gpio).

I am proposing to use the following pins:

net Xdir => hal_pi_gpio.pin-15-out
net Xstep => hal_pi_gpio.pin-16-out
net Ydir => hal_pi_gpio.pin-18-out
net Ystep => hal_pi_gpio.pin-22-out

When I start LinuxCNC the HAL file appears to be loading properly.

But if I go to a terminal and say Halcmd show pins  - it appears to be showing my pins configured as INPUTS - not outputs?
(I'm assuming that's what the direction column in the show pins command means).

nc@raspberrypi:~/Desktop$ halcmd show pin
Component Pins:
Owner   Type  Dir         Value  Name
 
    28  bit   IN          FALSE  hal_pi_gpio.pin-15-out <== Xdir
    28  bit   IN          FALSE  hal_pi_gpio.pin-16-out <== Xstep
    28  bit   IN          FALSE  hal_pi_gpio.pin-18-out <== Ydir
    28  bit   IN          FALSE  hal_pi_gpio.pin-22-out <== Ystep

I'm pretty sure I did the math on the mask right although I could be wrong. To confirm, I just tried masking for one output and it still shows up as IN.

The documentation says I should add up the hex values for all pins that should be configured as an output which I think is what I've done.  

Anyone see what I'm missing?  Thanks!!!!

my full .hal file follows:


# Generated by stepconf 1.1 at Fri Nov 17 17:18:50 2023
# If you make changes to this file, they will be
# overwritten when you run stepconf again
loadrt [KINS]KINEMATICS
loadrt [EMCMOT]EMCMOT base_period_nsec=[EMCMOT]BASE_PERIOD servo_period_nsec=[EMCMOT]SERVO_PERIOD num_joints=[KINS]JOINTS

# Load the Raspberry Pi GPIO driver
loadrt hal_pi_gpio dir=0x00F00040


loadrt stepgen step_type=0,0


# Add to the base thread

addf hal_pi_gpio.read base-thread  
addf stepgen.make-pulses base-thread
addf hal_pi_gpio.write base-thread

addf stepgen.capture-position servo-thread
addf motion-command-handler servo-thread
addf motion-controller servo-thread
addf stepgen.update-freq servo-thread


# Configure output pins
net Xdir => hal_pi_gpio.pin-15-out
net Xstep => hal_pi_gpio.pin-16-out
net Ydir => hal_pi_gpio.pin-18-out
net Ystep => hal_pi_gpio.pin-22-out


setp stepgen.0.position-scale [JOINT_0]SCALE
setp stepgen.0.steplen 1
setp stepgen.0.stepspace 0
setp stepgen.0.dirhold 35000
setp stepgen.0.dirsetup 35000
setp stepgen.0.maxaccel [JOINT_0]STEPGEN_MAXACCEL
net xpos-cmd joint.0.motor-pos-cmd => stepgen.0.position-cmd
net xpos-fb stepgen.0.position-fb => joint.0.motor-pos-fb
net xstep <= stepgen.0.step
net xdir <= stepgen.0.dir
net xenable joint.0.amp-enable-out => stepgen.0.enable

setp stepgen.1.position-scale [JOINT_1]SCALE
setp stepgen.1.steplen 1
setp stepgen.1.stepspace 0
setp stepgen.1.dirhold 35000
setp stepgen.1.dirsetup 35000
setp stepgen.1.maxaccel [JOINT_1]STEPGEN_MAXACCEL
net ypos-cmd joint.1.motor-pos-cmd => stepgen.1.position-cmd
net ypos-fb stepgen.1.position-fb => joint.1.motor-pos-fb
net ystep <= stepgen.1.step
net ydir <= stepgen.1.dir
net yenable joint.1.amp-enable-out => stepgen.1.enable

net estop-out <= iocontrol.0.user-enable-out
net estop-out => iocontrol.0.emc-enable-in

loadusr -W hal_manualtoolchange
net tool-change iocontrol.0.tool-change => hal_manualtoolchange.change
net tool-changed iocontrol.0.tool-changed <= hal_manualtoolchange.changed
net tool-number iocontrol.0.tool-prep-number => hal_manualtoolchange.number
net tool-prepare-loopback iocontrol.0.tool-prepare => iocontrol.0.tool-prepared


 

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

More
15 Aug 2024 07:35 #307780 by elovalvo
you will surely find what you need in this link

linuxcnc.org/docs/html/drivers/hal_pi_gpio.html

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

More
16 Aug 2024 15:12 #307928 by dave.franchino@gmail.com
That is exactly the document I have been using. As a test I tried to configure just one GPIO pin as an output - but when I run Halcmd Show Pins in a terminal that pin is showing up with direction set to "in"

Is there any chance that I don't understand what "Show Pins" is reporting. What does "direction" mean in this context - is there any chance that I do want direction to be "in" for an output? That seems unlikely.

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

More
16 Aug 2024 15:29 #307931 by elovalvo
and everything is right!
The fact is that the pin outs of the Raspberry are inputs for the LinuxCNC and vice versa...

You will see that if you configure input pins with hal_pi_gpio, in the halcmd show pin command they will be shown as OUT

 

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

More
16 Aug 2024 15:37 #307932 by dave.franchino@gmail.com
Oh thank you so very much! I thought I was going crazy. Your explanation makes a lot of sense.

Might be nice to add a note to that document to clarify this as it's not incredibly obvious. I'm a LinuxCNC newby and I'm not sure of the protocol for making changes like this but if it's something I can or should do I'm happy to try adding a note. Thanks again!

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

Time to create page: 0.096 seconds
Powered by Kunena Forum