RobTillaart / PCF8575

Arduino library for PCF8575 - 16 channel I2C IO expander
MIT License
74 stars 10 forks source link

examples including PCF8575.h instead of PCF8575_library.h #30

Closed DennisSchm closed 1 year ago

DennisSchm commented 1 year ago

Hello and thank you for your work,

while reading through the library code I noticed that you introduced include guards in a separate file called PCF8575_library.h. Later the example files omit those guards by including PCF8575.h. This could also happen to other users not having a look at the library at all or following those examples. I think it would be no problem to include the guards directly into PCF8575.h bypassing this problem completely.

Thank you for your time, Dennis

RobTillaart commented 1 year ago

Will look into this one asap.

RobTillaart commented 1 year ago

Labeled as bug for now.

RobTillaart commented 1 year ago

@DennisSchm

Hi Dennis, Did not find any library of me mentioning PCF8575_library.h (except this issue) Can you post a link where you see this line?

Maybe an old version had it - I do not recall - so update to the latest version 0.1.8 should solve this. If you downloaded a fork, then you should create an issue at that fork.

DennisSchm commented 1 year ago

You are right, thats my fault. I confused your library with PCF8575 library by Renzo Mischianti as I was to believe PlatformIO recommends yours first and I was editing it, while I was not. Please excuse the inconvenience. I believe the same thing applies to: #29 . I think both issues can be closed. If I still can be of any service testing for the teensy, I will gladly do so.

RobTillaart commented 1 year ago

Another library could also be a cause.

Worked about two hours on both issues, searching, installing teensy etc. Confirmed that the library compiles for TEENSYDUINO, If you can confirm this with a hardware test time is well spend.


Closed issue #29

DennisSchm commented 1 year ago

I will do so today and get back at you when I'm done.

DennisSchm commented 1 year ago

I tested PCF8575_Wire2.ino using PlatformIO (PIO) (Core 6.1.9, Home 3.4.4) by adding the newest version of this library (0.1.8) through PIOs library browser. The platformio.ini file looks like this:

[env:teensy40]
platform = teensy
board = teensy40
framework = arduino
lib_deps = robtillaart/PCF8575@^0.1.8

I copied PCF8575_Wire2.ino to my main.cpp and edited the example for it to compile in PlatformIO like this:

//
//    FILE: PCF8575_Wire2.ino
//  AUTHOR: Rob Tillaart
//    DATE: 2021-01-03
// PUPROSE: demo

#include "PCF8575.h"

// scanned i2c addresses with following code:
// https://learn.adafruit.com/scanning-i2c-addresses/arduino
// detected 0x21 as default for my specific board 
PCF8575 PCF(0x21, &Wire1); 

// PlatformIO (PIO) by default uses standart C++
// hence methods need to be declared before usage
void doHigh()
{
  // added to see if input was detected correctly
  Serial.print("doHigh() -> ");
  PCF.write(4, HIGH);
  int x = PCF.read16();
  Serial.print("Read ");
  Serial.println(x, HEX);
}

void doLow()
{
  Serial.print("doLow() -> ");
  PCF.write(4, LOW);
  int x = PCF.read16();
  Serial.print("Read ");
  Serial.println(x, HEX);
}

void doToggle()
{
  Serial.print("doToggle() -> ");
  PCF.toggle(4);
  int x = PCF.read16();
  Serial.print("Read ");
  Serial.println(x, HEX);
}

void setup()
{
  Serial.begin(115200);
  Serial.println(__FILE__);
  Serial.print("PCF8575_LIB_VERSION:\t");
  Serial.println(PCF8575_LIB_VERSION);

  if (!PCF.begin())
  {
    Serial.println("could not initialize...");
  }
  if (!PCF.isConnected())
  {
    Serial.println("=> not connected");
    while (1)
      ;
  }

  int x = PCF.read16();
  Serial.print("Read ");
  Serial.println(x, HEX);
  delay(1000);
}

void loop()
{
  Serial.println("HLT");
  while (Serial.available() == 0)
    ;
  switch (Serial.read())
  {
  case 'H':
    doHigh();
    break;
  case 'L':
    doLow();
    break;
  case 'T':
    doToggle();
    break;
  }
}

// -- END OF FILE --

I added comments where I changed things.

I connected LEDs to P03, P04 and P05, to make sure no confusion arises from the weird labelling on my breakout. Also I hooked up the INT Pin which I did not need in this sketch.

Teensy 4.0 PCF8575 Breakout

17 (SDA) --[4.7k PullUp]--> SDA 16 (SCL) --[4.7k PullUp]--> SCL
GND ----------------------> GND 3V -----------------------> VCC

Teensy i2c pins can be looked up here. Please note that SDA and SCL default pins switch order from Wire to Wire1 even though they are right next to each other.

pcm8575_back pcm8575_front pmc8575_to_teensy40

The library itself works flawlessly. The only thing I'd suggest is declaring methods in standard C++ style so the library examples are ready for PlatformIO out of the box. Also my default address seemed to be 0x21, if that is the case with other boards also the default address should be changed.

I hope this helps, Dennis

RobTillaart commented 1 year ago

Super, that is very well tested. Will look into improving platform-io support later. Thanks a lot, really appreciated!

RobTillaart commented 1 year ago

// PlatformIO (PIO) by default uses standart C++ // hence methods need to be declared before usage

This remark affects almost all examples in all my libraries, I might do it coming winter when the long evenings provide plenty of time to do this kind of maintenance.

RobTillaart commented 1 year ago

As this issue in itself is solved I close it for now.