Thursday, August 4, 2016

ESP Basic -3 - PCF8574 I2C I/O 8 x independent switches example



8 x Independent switches driver Example :






  
   After doing last time the Mutually exclusive 8x Switch driver example, now is time for a 8 x independent switches implementation .


What we will need: 


      This is how is looking the setup on a breadboard, for a better visibility:





Software implementation:

Something to remember: 

  • PCF8574 can SINK but NOT SOURCE much current - 100uA only (it cannot output high, if you want). Look at the above example how is connected the LED for SINKING current.
  • Each of the 8 GPIOs have a minimum guaranteed sinking current of 10 mA per bit at 5 V.
  • Each pin needs its own limiting resistor to prevent damage to the device!! keep under 25mA/pin.
  • Maximum device limit sink current in about 80mA. If you need more, look after PCA8574 (200mA max sink current!)

For more details please take a look at the PCF8574 Datasheet


ESP8266 Basic code: 
let address = 32 'PCF8574 I2C Address

i2c.begin(address)
ss = 0 xor 255 'XOR - Bit masking for the desired I/O pins
i2c.write(ss)
i2c.end()
button "1", [1]
button "2", [2]
button "3", [3]
button "4", [4]
button "5", [5]
button "6", [6]
button "7", [7]
button "8", [8]
button "OFF", [9]
wait

[9]
i2c.begin(address)
ss = 0 xor 255 'XOR - Bit masking for the desired I/O pins
i2c.write(ss)
i2c.end()
wait

[1]
i2c.begin(address)
ss = ss xor 1   'XOR - Bit masking for the desired I/O pins
i2c.write(ss)
i2c.end()
wait

[2]
i2c.begin(address)
ss = ss xor 2
i2c.write(ss)
i2c.end()
wait

[3]
i2c.begin(address)
ss = ss xor 4
i2c.write(ss)
i2c.end()
wait

[4]
i2c.begin(address)
ss = ss xor 8
i2c.write(ss)
i2c.end()
wait

[5]
i2c.begin(address)
ss = ss xor 16
i2c.write(ss)
i2c.end()
wait

[6]
i2c.begin(address)
ss = ss xor 32
i2c.write(ss)
i2c.end()
wait

[7]
i2c.begin(address)
ss = ss xor 64
i2c.write(ss)
i2c.end()
wait

[8]
i2c.begin(address)
ss = ss xor 128
i2c.write(ss)
i2c.end()
wait

This is how is looking the interface in the Web Browser after running the above program:



PS: credit for the XOR Bit masking goes this time to Forlotto from the esp8266.com forum who posted quicker than me this elegant solution :)

17 comments:

forlotto said...

Thanks for the credit could not have done it as quickly and efficiently without your help. Thank you TrackerJ for the videos excellent work and quality products that introduced me to you. I look forward to seeing some of the things that can be possible with basic with your great knowledge of hardware and quality components. You have shown me some large differences in quality while I admit I am sometimes skeptical I am not going to argue with a guy that has your years of experience as an Electronic Engineer. The AN1 is an interesting piece of hardware as well as your dimmer board and it appears to work with all esp based boards I prefer the espbasic implementation as it is more readable for the average user and a little less cumbersome to write with than LUA. But to each their own either can be made to be equally as effective.

Hema said...

This content creates a new hope and inspiration with in me. Thanks for sharing article like this. The way you have stated everything above is quite awesome. Keep blogging like this. Thanks.
Digital marketing company
Digital marketing services

Thanu Abi said...

This is really a great post. Thank you for taking time to provide us some of the useful and exclusive information with us. Keep on blogging!!

Seo Training in Chennai

Thanu Abi said...

This is really a great post. Thank you for taking time to provide us some of the useful and exclusive information with us. Keep on blogging!!

Seo Training in Chennai

Hema said...

This content creates a new hope and inspiration with in me. Thanks for sharing article like this. The way you have stated everything above is quite awesome. Keep blogging like this. Thanks.
Seo Web design company

Arthur Mac said...

Thanks for your informative article on digital marketing trends. I hardly stick with SEO techniques in boosting my online presence as its cost efficient and deliver long term results.
SEO Training in Chennai | SEO course in Chennai | SEO Training Institute in Chennai

San Jairaj said...

Great post!!Thank you for sharing this excellent blog of content.
Seo Course in Chennai | Seo Training in Chennai

Jhon anderson said...

Thanks for taking time to share this information to my vision. It is really great and useful. Continue is sharing more like this.
Digital Marketing Training in Chennai | Digital Marketing course in Chennai | Digital Marketing Chennai

Amirtha rao said...

Digital Marketing is a kind of marketing strategy that relies on electronic medium like television, internet and mobile in promoting a product. It delivers incredible result to the business owners to boost their business online presence and enjoy maximum leads. Digital Marketing Training in Chennai | Digital Marketing Course in Chennai

Melisa said...

Nice Post, keep blogging :)
Regards,
SEO Training Chennai|SEO Training in Chennai

charles said...

I was pinning away for such type of blogs, thanks for posting this for us.
Backlink

SKARtec SEO said...

Thanks for sharing this with us it is a worth read. xcellent post!!! Our Digital Marketing Course is tailored for beginners who want to learn how to stand out digitally, whether it is for their own business or a personal brand.

Digital Marketing Training in Chennai | Digital Marketing Course in Chennai | Digital Marketing Course | SEO Training in Chennai | Google Analytics Course | Social Media Marketing Course

sivanesan said...

Nice blog. Thank you for sharing. The information you shared is very effective for learners I have got some important suggestions from it. erp in chennai.

Brave Technologies said...

The information you shared is very effective for learners I have got some important suggestions from it. cloud erp in chennai.

anitha a said...

I’m really impressed with your article, such great & usefull knowledge you mentioned here.
Best institute chennai

Siva Nesan said...

Thank you for your nice post. It is really useful. cashew nuts supplier in india | suppliers & exporters in india

Chandu said...

Digital Marketing Intensive program in Chennai provides the best suppliers of SEO Training in Chennai with Search Engine Optimization Experts.
Seo training in Chennai

Post a Comment