Thursday, January 10, 2013

I2C 16bit IO extender

The PCA9555 is a 16 bit IO chip which interfaces with I2C. Each of the 16 bits can be individually configured as a digital input or digital output.

PCA9555 demo board. GPIO pins are on the top.


I will be using this to control a bank of relays from my Raspberry Pi. If you are not familiar with I2C on the RPI you might want to look at my posts about the PCA8591.

This time I bought the chip mounted to a board from ebay. I had to solder the header pins to the board so I could connect all the inputs & outputs.

jnewbigin@raspberrypi:~$ i2cdetect 1
WARNING! This program can confuse your I2C bus, cause data loss and worse!
I will probe file /dev/i2c-1.
I will probe address range 0x03-0x77.
Continue? [Y/n]
     0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f
00:          -- -- -- -- -- -- -- -- -- -- -- -- --
10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
20: 20 -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
40: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
50: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
60: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
70: -- -- -- -- -- -- -- --          

As expected, the chip shows up at address 0x20. The PCA9555 is programmed by a set of registers. The registers are split up into ports or banks which operate on 8 bits at a time. The registers are:

  • 0x00 Select Input values for bank 0
  • 0x01 Select Input values for bank 1
  • 0x02 Select Output values for bank 0
  • 0x03 Select Output values for bank 1
  • 0x04 Select Polarity Inversion for bank 0
  • 0x05 Select Polarity Inversion for bank 1
  • 0x06 Select IO Configuration for bank 0
    (set/1 = input (default), clear/0 = output)
  • 0x07 Select IO Configuration for bank 1
    (set/1 = input (default), clear/0 = output)

To read the first 8 inputs
i2cset -y 1 0x20 0x00
i2cget -y 1 0x20


To read the next 8 inputs
i2cset -y 1 0x20 0x01
i2cget -y 1 0x20

To set the first 8 bits to be outputs
i2cset -y 1 0x20 0x06 0x00
And to turn all the outputs on
i2cset -y 1 0x20 0x02 0xff

My next job is to hook up the relay boards but that requires setting up a more permanent power supply which can run the Raspberry Pi, drive the relays and power the relay devices. Hopefully photos to come soon.

14 comments:

  1. how to control the pins by a c - code

    ReplyDelete
  2. Hi. I have some sample code which I am almost ready to post. I got a bit distracted with hardware things but I am back on track now.

    ReplyDelete
  3. Hello ,I'm working on this IC PCA9555 with esp8266 for i/o expander but I found one issue like one port as inputs and other one as output whereas in one input apply socket with switch
    My problem is when plug in and plug out from socket in that case pca9555 is reset again and again.
    we are set the value of register through code but still have problem .

    Please resolve my problem......

    ReplyDelete
  4. It is necessary to read more such messages. Tina

    ReplyDelete
  5. Thanks for the helpful information you shared with us.
    scary maze game

    ReplyDelete
  6. Thanks for the valuable information and insights you have so provided here. bloxorz

    ReplyDelete
  7. Indonesian single ladies are a delight to be around because of their positive natures and bubbly personalities. The typical Indonesian woman has tanned skin, dark hair, and even darker eyes. The modern Indonesian woman looks especially indonesian brides feminine with her petite body usually adorned with in fashionable wardrobe. She wears make up and her hair is usually carefully arranged. Perfect looks go along with a lovely character.

    ReplyDelete

  8. نظافة وجمال منزلك خير دليل على نظافة الجدران حيث ينكشف بسرعة أكبر قدر من الأوساخ والغبار والأوساخ ، كما نقوم بتنظيف الجدران بالطلاء والمواد الحافظة للجدران وتنظيفها بكفاءة عالية. تستخدمين أفضل وأقوى وأسلم المنظفات لصحتك ، والتي تحتوي أيضًا على عطر ذكي يعزز جمال المكان. يبدأ التنظيف بغسل جميع أنواع الجدران سواء كانت دهانات أو دريوال أو جميع أنواع ورق الحائط.
    غالبًا ما تحتاج الأماكن الأكثر استخدامًا والأوساخ في المنزل إلى تنظيف الرخام والأرضيات والجدران وإزالة الزيت عن الجدران والأرضيات وتنظيف المطبخ سواء كان من الألمنيوم أو الخشب وتلميعه. ضعها وأعدها بأمان ، ويقوم الفريق بتنظيف الحوائط بمنظفات خاصة ، سواء كانت رخامية أو سيراميك ، أرضيات وأحواض مختلفة ، لإزالة الدهون والبقع والزيوت والأتربة ، وتلميعها جيدًا لجعلها تبدو جديدة كما هي ، مع منعها تلف
    شركة تنظيف منازل بالرياض
    الحشرات الضارة هي الحشرات التي تلحق الضرر بالإنسان وممتلكاتهم ومحاصيلهم ومواشيهم ، وهي منتشرة في جميع أنحاء العالم ، وقد تسبب الحشرات أضرارًا مباشرة ، أي بامتصاص دماء الكائنات الحية ، أو أكل أنسجتها ، أو بشكل غير مباشر ، عن طريق إزالتها. تنتقل مسببات الأمراض أو الطفيليات إلى الكائنات الحية ، وغالبًا ما يكون الضرر هو البالغين. وأحيانًا يكون الضرر في البالغين ويرقاتهم. قد تعمل هذه الحشرات بمفردها أو قد تهاجم في مجموعات. في أي حال ، يجب مكافحة الآفات والقضاء عليها لتجنب التسبب في ضرر

    شركة مكافحة حشرات بالرياض

    ReplyDelete
  9. You have a great blog here! would you like to make some invite posts on my blog?

    Bikepacking.quebect
    Information
    Click Here
    Visit Web

    ReplyDelete
  10. I think this is among the most vital info for me. And i’m glad
    reading your article. But should remark on few general things, The
    web site style is wonderful, the articles is really great.
    온라인섯다

    ReplyDelete
  11. Hey, I just hopped over to your site via StumbleUpon. Not something
    I would normally read, but I liked your thoughts none the less.
    Thanks for making something worth reading.
    안전놀이터

    ReplyDelete
  12. Nice post. I learn something more challenging on distinct blogs
    everyday. It will always be stimulating to read content off their
    writers and practice a little something from their store. I’d choose
    to use some with all the content in my small weblog whether you do
    not mind.
    성인웹툰

    ReplyDelete
  13. Wow, such an awesome blog you have written there and you and I get exactly what information I am looking for, in the third paragraph you put amazing effort to explain the theme of the content. 토토사이트

    ReplyDelete