Support Forum

Share your projects and post your questions

Register   or   Sign In
The Forum

IO Pi Performance

The IO Pi Plus is a 32 channel MCP23017 GPIO expander for the Raspberry Pi

30/12/2016

Posted by:
voodoo_dev

voodoo_dev Avatar

Recently received my IO Pi Plus, all setup with no issues at all on RPi 3 running Jessie. Thought I'd test the performance to see the maximum speed I can toggle an IO line. Using the provided tutorials, I removed the 'sleep' calls and measured the IO line with an oscilloscope. I tested with Python 2 (tutorial1) and C code (demo-iopiwrite). To my surprise, Python performed better giving approx 1KHz toggle frequency. C code only gave around 400Hz.Now, given that I want to use C code, this is problematic for me. Any reason why the C code performance is so poor?

30/12/2016

Posted by:
andrew

andrew Avatar

The main reason for the decreased performance with the C version of the IO Pi library is due to the way the write_pin function works.

With the python library, each instance of the iopi is stored as an object which contains variables for the status of the pins on the IO Pi. When you write to a single pin the python library updates the variable and then writes that to the IO Pi.

As C is not an object-orientated language we wrote the C version of the library so the write_pin function reads the values from the port before updating a single bit and writing the value back to the port. This is more reliable if you have more than one program writing to the IO Pi as it will always check the status of the port before updating it. The downside is it requires two I2C packets to be sent to the IO Pi whereas the python library only needs one which is why the C library is half the speed of the python library.

One way of improving the performance would be to use the write_port function instead of write_pin. write_port updates all 8 pins on the port at the same time so it does not need to read the status of the pins first. This means it only has to send a single I2C packet to the IO Pi so performance should be the same as the python version.

Sign in to post your reply


Note: documents in Portable Document Format (PDF) require Adobe Acrobat Reader 5.0 or higher to view.
Download Adobe Acrobat Reader or other PDF reading software for your computer or mobile device.

Home

Shop

Learn

Forum

FAQ

Contact

0 item

Your cart is empty

Please browse our shop to order from the wide range of Raspberry Pi boards and accessories.

Subtotal:£0.00
View Basket Continue to Checkout