Skip to content

Commit

Permalink
update library.json, license, readme, minor edits (#31)
Browse files Browse the repository at this point in the history
  • Loading branch information
RobTillaart authored Dec 23, 2021
1 parent 8f67e26 commit fd39055
Show file tree
Hide file tree
Showing 15 changed files with 52 additions and 50 deletions.
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2013-2021 Rob Tillaart
Copyright (c) 2013-2022 Rob Tillaart

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
32 changes: 17 additions & 15 deletions PCF8574.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,14 @@
// FILE: PCF8574.cpp
// AUTHOR: Rob Tillaart
// DATE: 02-febr-2013
// VERSION: 0.3.2
// VERSION: 0.3.3
// PURPOSE: Arduino library for PCF8574 - 8 channel I2C IO expander
// URL: https://github.com/RobTillaart/PCF8574
// http://forum.arduino.cc/index.php?topic=184800
//
// HISTORY:
//
//
// 0.3.3 2021-12-23 update library.json, license, readme, minor edits
// 0.3.2 2021-07-04 fix #25 add setAddress()
// 0.3.1 2021-04-23 Fix for platformIO compatibility
// 0.3.0 2021-01-03 multiWire support - inspired by mattbue - issue #14
Expand All @@ -20,9 +21,9 @@
// removed pre 1.0 support
// added begin(dsa, scl) for ESP32
// added reverse()
//
//
// 0.1.9 2017-02-27 fix warning about return in readButton8()
// 0.1.08 2016-05-20 Merged work of Septillion
// 0.1.08 2016-05-20 Merged work of Septillion
// Fix/refactor ButtonRead8() - see https://github.com/RobTillaart/Arduino/issues/38
// missing begin() => mask parameter
// 0.1.07 2016-05-02 (manually merged) Septillion
Expand Down Expand Up @@ -60,7 +61,7 @@ PCF8574::PCF8574(const uint8_t deviceAddress, TwoWire *wire)


#if defined (ESP8266) || defined(ESP32)
bool PCF8574::begin(uint8_t dataPin, uint8_t clockPin, uint8_t val)
bool PCF8574::begin(uint8_t dataPin, uint8_t clockPin, uint8_t value)
{
_wire = &Wire;
if ((dataPin < 255) && (clockPin < 255))
Expand All @@ -70,17 +71,17 @@ bool PCF8574::begin(uint8_t dataPin, uint8_t clockPin, uint8_t val)
_wire->begin();
}
if (! isConnected()) return false;
PCF8574::write8(val);
PCF8574::write8(value);
return true;
}
#endif


bool PCF8574::begin(uint8_t val)
bool PCF8574::begin(uint8_t value)
{
_wire->begin();
if (! isConnected()) return false;
PCF8574::write8(val);
PCF8574::write8(value);
return true;
}

Expand All @@ -105,11 +106,11 @@ uint8_t PCF8574::getAddress()
}


// removed _wire->beginTransmission(addr);
// with @100KHz -> 265 micros()
// without @100KHz -> 132 micros()
// without @400KHz -> 52 micros()
// TODO @800KHz -> ??
// removed _wire->beginTransmission(_address);
// with @100 KHz -> 265 micros()
// without @100 KHz -> 132 micros()
// without @400 KHz -> 52 micros()
// TODO @800 KHz -> ??
uint8_t PCF8574::read8()
{
if (_wire->requestFrom(_address, (uint8_t)1) != 1)
Expand Down Expand Up @@ -253,10 +254,11 @@ uint8_t PCF8574::readButton(const uint8_t pin)

uint8_t temp = _dataOut;
PCF8574::write(pin, HIGH);
uint8_t rtn = PCF8574::read(pin);
uint8_t value = PCF8574::read(pin);
PCF8574::write8(temp);
return rtn;
return value;
}


// -- END OF FILE --

21 changes: 11 additions & 10 deletions PCF8574.h
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
#pragma once
//
// FILE: PCF8574.H
// FILE: PCF8574.h
// AUTHOR: Rob Tillaart
// DATE: 02-febr-2013
// VERSION: 0.3.2
// VERSION: 0.3.3
// PURPOSE: Arduino library for PCF8574 - 8 channel I2C IO expander
// URL: https://github.com/RobTillaart/PCF8574
// http://forum.arduino.cc/index.php?topic=184800
Expand All @@ -17,26 +17,26 @@
#include "Wire.h"


#define PCF8574_LIB_VERSION (F("0.3.2"))
#define PCF8574_LIB_VERSION (F("0.3.3"))

#ifndef PCF8574_INITIAL_VALUE
#define PCF8574_INITIAL_VALUE 0xFF
#define PCF8574_INITIAL_VALUE 0xFF
#endif

#define PCF8574_OK 0x00
#define PCF8574_PIN_ERROR 0x81
#define PCF8574_I2C_ERROR 0x82
#define PCF8574_OK 0x00
#define PCF8574_PIN_ERROR 0x81
#define PCF8574_I2C_ERROR 0x82


class PCF8574
{
public:
explicit PCF8574(const uint8_t deviceAddress, TwoWire *wire = &Wire);
explicit PCF8574(const uint8_t deviceAddress = 0x20, TwoWire *wire = &Wire);

#if defined (ESP8266) || defined(ESP32)
bool begin(uint8_t sda, uint8_t scl, uint8_t val = PCF8574_INITIAL_VALUE);
bool begin(uint8_t sda, uint8_t scl, uint8_t value = PCF8574_INITIAL_VALUE);
#endif
bool begin(uint8_t val = PCF8574_INITIAL_VALUE);
bool begin(uint8_t value = PCF8574_INITIAL_VALUE);
bool isConnected();


Expand Down Expand Up @@ -89,3 +89,4 @@ class PCF8574


// -- END OF FILE --

8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,10 @@ the include of "pcf8574.h" to overrule the default value used with the **begin()

### Constructor

- **PCF8574(deviceAddress, TwoWire \*wire = &Wire)** Constructor with device address,
and optional the Wire interface as parameter.
- **bool begin(uint8_t val = PCF8574_INITIAL_VALUE)** set the initial value for the pins and masks.
- **bool begin(uint8_t sda, uint8_t scl, uint8_t val = PCF8574_INITIAL_VALUE)** idem, for the ESP32 where one can choose the I2C pins.
- **PCF8574(uint8_t deviceAddress = 0x20, TwoWire \*wire = &Wire)** Constructor with optional device address, default 0x20,
and the optional Wire interface as parameter.
- **bool begin(uint8_t value = PCF8574_INITIAL_VALUE)** set the initial value for the pins and masks.
- **bool begin(uint8_t sda, uint8_t scl, uint8_t value = PCF8574_INITIAL_VALUE)** idem, for the ESP32 where one can choose the I2C pins.
- **bool isConnected()** checks if the address set in the constructor or by **setAddress()** is visible on the I2C bus.
- **bool setAddress(const uint8_t deviceAddress)** sets the device address after construction.
Can be used to switch between PCF8574 modules runtime. Note this corrupts internal buffered values,
Expand Down
3 changes: 1 addition & 2 deletions examples/PCF8574_Wire2/PCF8574_Wire2.ino
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@
// FILE: PCF8574_Wire2.ino
// AUTHOR: Rob Tillaart
// DATE: 2016-04-30
// PUPROSE: demo
//
// PUPROSE: demo


#include "PCF8574.h"
Expand Down
10 changes: 5 additions & 5 deletions examples/PCF8574_interrupt/PCF8574_interrupt.ino
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,12 @@
// DATE: 2020-12-07
// PUPROSE: test PCF8574 library
//

// TEST SETUP
// Connect INT pin of the PCF8574 to UNO pin 2
// Connect INT pin of the PCF8574 to UNO pin 2
//
// (from figure 4 datasheet
// Place a pull up resistor 4K7 between pin and 5V
// Place a capacitor 10-400pF between pin and GND
// (from figure 4 datasheet
// Place a pull up resistor 4K7 between pin and 5V
// Place a capacitor 10-400pF between pin and GND


#include "PCF8574.h"
Expand Down Expand Up @@ -69,3 +68,4 @@ void loop()


// -- END OF FILE --

2 changes: 1 addition & 1 deletion examples/PCF8574_isConnected/PCF8574_isConnected.ino
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
// AUTHOR: Rob Tillaart
// DATE: 2021-01-03
// PUPROSE: demo isConnected function
//


#include "PCF8574.h"
Expand Down Expand Up @@ -40,3 +39,4 @@ void loop()


// -- END OF FILE --

4 changes: 2 additions & 2 deletions examples/PCF8574_rotaryEncoder/PCF8574_rotaryEncoder.ino
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@
// FILE: PCF8574_rotaryEncoder.ino
// AUTHOR: Rob Tillaart
// DATE: 2021-05-08
//
// PUPROSE: demo PCF8574 as rotary encoder reader.

//
//
// RotaryEncoder PCF8574 UNO
// --------------------------------------
Expand Down Expand Up @@ -132,3 +131,4 @@ void updateRotaryDecoder()


// -- END OF FILE --

2 changes: 0 additions & 2 deletions examples/PCF8574_test/PCF8574_test.ino
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@

//
// FILE: PCF8574_test.ino
// AUTHOR: Rob Tillaart
// DATE: 7-febr-2013
// PUPROSE: test PCF8574 library
//


#include "PCF8574.h"
Expand Down
4 changes: 2 additions & 2 deletions examples/PCF8574_test1/PCF8574_test1.ino
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
//
// FILE: pcf8574_test.ino
// FILE: PCF8574_test.ino
// AUTHOR: Rob Tillaart
// DATE: 27-08-2013
// PUPROSE: demo
//


#include "PCF8574.h"

Expand Down
1 change: 0 additions & 1 deletion examples/PCF8574_test2/PCF8574_test2.ino
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
// AUTHOR: Rob Tillaart
// DATE: 2016-04-30
// PUPROSE: demo rotateLeft, -Right and toggleMask
//


#include "PCF8574.h"
Expand Down
3 changes: 2 additions & 1 deletion keywords.txt
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,5 @@ lastError KEYWORD2
PCF8574_LIB_VERSION LITERAL1
PCF8574_OK LITERAL1
PCF8574_PIN_ERROR LITERAL1
PCF8574_I2C_ERROR LITERAL1
PCF8574_I2C_ERROR LITERAL1

2 changes: 1 addition & 1 deletion library.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"type": "git",
"url": "https://github.com/RobTillaart/PCF8574.git"
},
"version": "0.3.2",
"version": "0.3.3",
"license": "MIT",
"frameworks": "arduino",
"platforms": "*",
Expand Down
2 changes: 1 addition & 1 deletion library.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name=PCF8574
version=0.3.2
version=0.3.3
author=Rob Tillaart <rob.tillaart@gmail.com>
maintainer=Rob Tillaart <rob.tillaart@gmail.com>
sentence=Arduino library for PCF8574 - 8 channel I2C IO expander
Expand Down
6 changes: 4 additions & 2 deletions test/unit_test_001.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,16 +42,17 @@ PCF8574 PCF(0x38);

unittest_setup()
{
fprintf(stderr, "PCF8574_LIB_VERSION: %s\n", (char *) PCF8574_LIB_VERSION);
}


unittest_teardown()
{
}


unittest(test_begin)
{
fprintf(stderr, "VERSION: %s\n", PCF8574_LIB_VERSION);

PCF8574 PCF(0x38);

PCF.begin();
Expand Down Expand Up @@ -103,4 +104,5 @@ unittest(test_address)

unittest_main()


// --------

0 comments on commit fd39055

Please sign in to comment.