How to adapt the extended IO?

More
19 Jul 2022 08:15 #247752 by chen1234
hi guys,
i have a raspberry pi but it doesn't have enough pins,
i have an IO expansion module, i can control the expanded IO,
but i don't know how to give this expanded IO to my axis (x, y,z...),
where should I look at this section?

please,chen

I want to give the extended IO to my axis like this:
[code]net home-x joint.0.home-sw-in <= parport.0.pin-11-in
[/code]

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

More
21 Jul 2022 18:32 #247978 by andypugh
What sort of expansion module? I2C? SPI? something else?

You might need to write a HAL driver.

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

More
22 Jul 2022 02:50 #248001 by chen1234
thanks,and
My expansion device is IIC expansion (PCF8574), so how do I configure this hal driver and where can I see this?

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

More
22 Jul 2022 08:13 #248014 by andypugh
Do you need this IO to be realtime?

There are tutorials on the web about enabling I2C on the Pi (for example learn.adafruit.com/adafruits-raspberry-p...etup/configuring-i2c )

For non-realtime access you can use the built-in drivers. I think that for realtime use you would need to mmap the device. I suggest looking at the i2C kernel driver tutorials out there (but don't follow them) and look at the hal_pi_gpio LinuxCNC driver and try to combine the two.

You can probably write this driver using halcompile.
The following user(s) said Thank You: chen1234

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

More
22 Jul 2022 10:10 #248017 by chen1234
thanks andy,
I configured the Raspberry Pi to enable I2C,
I used python-smbus to test this expansion device, and I can control the high and low levels of this IO pin very well.
However, I don't know how to configure this io to my hal, thank you for your reply, I'll go and try to write this driver.
hope it won't be difficult .

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

More
22 Jul 2022 10:39 #248019 by andypugh
If you can find a way to read / write to the board using inb() and outb() then it is easy to write the HAL driver. (That is how the paralell port driver on x86 works)

hal_pi_gpio wrks somewhat similarly, except that it uses mmap to allow it to read the port data from (virtual?) memory locations:
github.com/LinuxCNC/linuxcnc/blob/master...rivers/hal_pi_gpio.c

I think that googling for Pi I2C and mmap might get you the required info.

It might well be as easy as changing the /dev/gpiomem here:
github.com/LinuxCNC/linuxcnc/blob/master...s/hal_pi_gpio.c#L164

to /dev/i2c-1 (or i2c-0)
raspberry-projects.com/pi/programming-in...ng-the-i2c-interface

I think that I would suggest starting with a _very_ simple HAL component written with halcompile that first of all reads the data into a single u32 HAL pin using the sample code above, then look at memory-mapping that port, and only then worry about setting individual bit-type HAL pins and configuring port directions.
The following user(s) said Thank You: chen1234

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

More
09 Aug 2022 23:30 - 09 Aug 2022 23:33 #249435 by cakeslob
Last edit: 09 Aug 2022 23:33 by cakeslob.
The following user(s) said Thank You: chen1234

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

Time to create page: 0.087 seconds
Powered by Kunena Forum