Reply to topic  [ 13 posts ]  Go to page Previous  1, 2
PCF8574 I2C to 8-bit digital port expander (HCMODU0120) 
Author Message

Joined: Tue Oct 31, 2017 4:32 pm
Posts: 7
Post Re: PCF8574 I2C to 8-bit digital port expander (HCMODU0120)
Would be great if this issue can be solved.
I too checked the library and neither do I see any explanation why the order makes any difference.

Of course knowing the issue is also the way to get around. But I included this Port Expander in a course for my students.
And it is difficult to explain to them that in an Arduino program ledpinA=1; ledpinB=0; is wrong while ledpinA=0; ledpinB=1; is correct.

Edit: I tested also lines like
Port.pinMode(4, OUTPUT);
Port.pinMode(3, OUTPUT);

Gives the same result.


Sun Nov 26, 2017 2:23 pm
Profile
Site Admin

Joined: Sun Aug 05, 2012 4:15 pm
Posts: 708
Post Re: PCF8574 I2C to 8-bit digital port expander (HCMODU0120)
I've now been able to test the code which allowed me to understand the issue better. I've fixed the problem and uploaded a new version (V0.2) of the library to the software section of the forum. If you just want to fix your current library rather than downloading the new one just open the HCPCF8574.cpp file in a text editor (don't use Windows Notepad as it messes up the formatting) and change this line:

Code:
_Dir = (_Dir & ~(1 << Pin)) | (~Mode << Pin);


to this:

Code:
_Dir = (_Dir & ~(1 << Pin)) | (!Mode << Pin);


Edit: if you can confirm it's fixed your issue I'll move these posts to the library HCPCF8574 thread what with it being an issue with the library not the module.

_________________
Comments made by this poster do not necessarily reflect the views of Hobby Components Ltd.


Mon Nov 27, 2017 11:04 am
Profile

Joined: Tue Oct 31, 2017 4:32 pm
Posts: 7
Post Re: PCF8574 I2C to 8-bit digital port expander (HCMODU0120)
Hi Andrew,

Many thanks. Now it works as a charm.
I and my friends completely overlooked that Mode is a Boolean, not a byte, so the bit manipulation in the previous .cpp were not allowed.
A small but important difference. (It would be great if the Arduino compiler would have complained..)
My sincere compliments!


Mon Nov 27, 2017 3:54 pm
Profile
Display posts from previous:  Sort by  
Reply to topic   [ 13 posts ]  Go to page Previous  1, 2

Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Thank you to phpBB.com & phpBB.ro.
Design created by Florea Cosmin Ionut.
© 2011 All contents of this site are © Hobby Components LTD