mirror of
https://github.com/RobTillaart/Arduino.git
synced 2024-10-03 18:09:02 -04:00
0.2.0 MCP23008
This commit is contained in:
parent
84bc647931
commit
07b2dc2d3e
@ -6,11 +6,18 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/)
|
||||
and this project adheres to [Semantic Versioning](http://semver.org/).
|
||||
|
||||
|
||||
## [0.2.0] - 2023-12-10
|
||||
- refactor API, begin()
|
||||
- update readme.md
|
||||
- add **uint8_t getAddress()**
|
||||
- update examples
|
||||
|
||||
----
|
||||
|
||||
## [0.1.5] - 2023-09-23
|
||||
- add Wire1 support for ESP32
|
||||
- update readme.md
|
||||
|
||||
|
||||
## [0.1.4] - 2023-06-20
|
||||
- add CMakeLists.txt #8
|
||||
- add debug function **uint8_t getPinMode8()**
|
||||
|
@ -1,7 +1,7 @@
|
||||
//
|
||||
// FILE: MCP23008.cpp
|
||||
// AUTHOR: Rob Tillaart
|
||||
// VERSION: 0.1.5
|
||||
// VERSION: 0.2.0
|
||||
// PURPOSE: Arduino library for I2C MCP23008 8 channel port expander
|
||||
// DATE: 2019-10-12
|
||||
// URL: https://github.com/RobTillaart/MCP23008
|
||||
@ -32,24 +32,8 @@ MCP23008::MCP23008(uint8_t address, TwoWire *wire)
|
||||
}
|
||||
|
||||
|
||||
#if defined(ESP8266) || defined(ESP32)
|
||||
bool MCP23008::begin(const uint8_t dataPin, const uint8_t clockPin)
|
||||
{
|
||||
_wire->begin(dataPin, clockPin);
|
||||
// check connected
|
||||
if (! isConnected()) return false;
|
||||
// disable address increment (datasheet)
|
||||
if (! writeReg(MCP23008_IOCR, 0b00100000)) return false;
|
||||
// Force INPUT_PULLUP
|
||||
if (! writeReg(MCP23008_PUR_A, 0xFF)) return false;
|
||||
return true;
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
bool MCP23008::begin()
|
||||
{
|
||||
_wire->begin();
|
||||
// check connected
|
||||
if (! isConnected()) return false;
|
||||
// disable address increment (datasheet)
|
||||
@ -73,6 +57,12 @@ bool MCP23008::isConnected()
|
||||
}
|
||||
|
||||
|
||||
uint8_t MCP23008::getAddress()
|
||||
{
|
||||
return _address;
|
||||
}
|
||||
|
||||
|
||||
// single pin interface
|
||||
// pin = 0..7
|
||||
// mode = INPUT, OUTPUT, INPUT_PULLUP (= same as INPUT)
|
||||
@ -173,7 +163,7 @@ uint8_t MCP23008::digitalRead(uint8_t pin)
|
||||
}
|
||||
|
||||
|
||||
// pin = 0..7
|
||||
// pin = 0..7
|
||||
// reverse = true or false
|
||||
bool MCP23008::setPolarity(uint8_t pin, bool reversed)
|
||||
{
|
||||
|
@ -2,7 +2,7 @@
|
||||
//
|
||||
// FILE: MCP23008.h
|
||||
// AUTHOR: Rob Tillaart
|
||||
// VERSION: 0.1.5
|
||||
// VERSION: 0.2.0
|
||||
// PURPOSE: Arduino library for I2C MCP23008 8 channel port expander
|
||||
// DATE: 2022-01-10
|
||||
// URL: https://github.com/RobTillaart/MCP23008
|
||||
@ -12,7 +12,7 @@
|
||||
#include "Wire.h"
|
||||
|
||||
|
||||
#define MCP23008_LIB_VERSION (F("0.1.5"))
|
||||
#define MCP23008_LIB_VERSION (F("0.2.0"))
|
||||
|
||||
#define MCP23008_OK 0x00
|
||||
#define MCP23008_PIN_ERROR 0x81
|
||||
@ -29,11 +29,9 @@ class MCP23008
|
||||
public:
|
||||
MCP23008(uint8_t address, TwoWire *wire = &Wire);
|
||||
|
||||
#if defined(ESP8266) || defined(ESP32)
|
||||
bool begin(const uint8_t dataPin, const uint8_t clockPin);
|
||||
#endif
|
||||
bool begin();
|
||||
bool isConnected();
|
||||
uint8_t getAddress();
|
||||
|
||||
|
||||
// single pin interface
|
||||
@ -62,7 +60,7 @@ public:
|
||||
|
||||
int lastError();
|
||||
|
||||
// DEBUG functions
|
||||
// DEBUG functions
|
||||
uint8_t getPinMode8();
|
||||
|
||||
|
||||
|
@ -25,6 +25,15 @@ Since 0.1.1 the **digitalWrite(pin, value)** is optimized.
|
||||
If a pin is not changed it will not be written again to save time.
|
||||
|
||||
|
||||
#### 0.2.0 Breaking change
|
||||
|
||||
Version 0.2.0 introduced a breaking change.
|
||||
You cannot set the pins in **begin()** any more.
|
||||
This reduces the dependency of processor dependent Wire implementations.
|
||||
The user has to call **Wire.begin()** and can optionally set the Wire pins
|
||||
before calling **begin()**.
|
||||
|
||||
|
||||
#### Related
|
||||
|
||||
16 bit port expanders
|
||||
@ -32,6 +41,7 @@ If a pin is not changed it will not be written again to save time.
|
||||
- https://github.com/RobTillaart/MCP23017_RT
|
||||
- https://github.com/RobTillaart/MCP23S17
|
||||
- https://github.com/RobTillaart/PCF8575
|
||||
- https://github.com/RobTillaart/TCA9555
|
||||
|
||||
|
||||
8 bit port expanders
|
||||
@ -51,9 +61,9 @@ If a pin is not changed it will not be written again to save time.
|
||||
|
||||
- **MCP23008(uint8_t address, TwoWire \*wire = &Wire)** constructor, with default Wire interface.
|
||||
Can be overruled with Wire0..WireN.
|
||||
- **bool begin()** for UNO, returns true if successful.
|
||||
- **bool begin(uint8_t sda, uint8_t scl)** for ESP32, returns true if successful.
|
||||
- **bool begin()** initializes library. Returns true upon success.
|
||||
- **bool isConnected()** returns true if connected, false otherwise.
|
||||
- **uint8_t getAddress()** returns address set in the constructor.
|
||||
|
||||
|
||||
### Single pin interface
|
||||
@ -111,7 +121,6 @@ See examples.
|
||||
|
||||
- keep in sync with MCP23017
|
||||
|
||||
|
||||
#### Could
|
||||
|
||||
|
||||
|
@ -1,9 +1,8 @@
|
||||
|
||||
//
|
||||
// FILE: MCP23008_I2C_Keypad_4x4_read.ino
|
||||
// AUTHOR: François Longchamp
|
||||
// DATE: 2022-09-27
|
||||
// PUPROSE: Keypad MCP23008 library
|
||||
// PURPOSE: Keypad MCP23008 library
|
||||
//
|
||||
// Tested with Seeed Studio XIAO RP2040
|
||||
// Keypad used https://fr.aliexpress.com/item/1005003176287473.html
|
||||
@ -15,8 +14,10 @@
|
||||
|
||||
MCP23008 MCP(0x20);
|
||||
|
||||
|
||||
const byte ROWS_OF_KEYPAD = 4; //four rows
|
||||
const byte COLS_OF_KEYPAD = 4; //four columns
|
||||
|
||||
byte keys_of_keypad[ROWS_OF_KEYPAD][COLS_OF_KEYPAD] = {
|
||||
{1, 2, 3, 4},
|
||||
{5, 6, 7, 8},
|
||||
@ -28,19 +29,22 @@ byte keys_of_keypad[ROWS_OF_KEYPAD][COLS_OF_KEYPAD] = {
|
||||
void setup()
|
||||
{
|
||||
Serial.begin(115200);
|
||||
Serial.print("MCP23008 version: ");
|
||||
Serial.println(__FILE__);
|
||||
Serial.print("MCP23008_LIB_VERSION: ");
|
||||
Serial.println(MCP23008_LIB_VERSION);
|
||||
Serial.println();
|
||||
delay(100);
|
||||
|
||||
Wire.begin();
|
||||
MCP.begin();
|
||||
|
||||
}
|
||||
|
||||
|
||||
void loop()
|
||||
{
|
||||
bool val;
|
||||
|
||||
// rows pinMode (0 or false = pressed)
|
||||
// rows pinMode (0 or false = pressed)
|
||||
MCP.pinMode8(0x0f);
|
||||
for (int pin = 0; pin < 4; pin++)
|
||||
{
|
||||
@ -50,7 +54,7 @@ void loop()
|
||||
Serial.print(' ');
|
||||
}
|
||||
|
||||
// columns pinMode (0 or false = pressed)
|
||||
// columns pinMode (0 or false = pressed)
|
||||
MCP.pinMode8(0xf0);
|
||||
for (int pin = 4; pin < 8; pin++)
|
||||
{
|
||||
@ -60,7 +64,7 @@ void loop()
|
||||
Serial.print(' ');
|
||||
}
|
||||
|
||||
// digital pressed from referer keys_of_keypad
|
||||
// digital pressed from referer keys_of_keypad
|
||||
MCP.pinMode8(0x0f);
|
||||
for (int r = 0; r < ROWS_OF_KEYPAD; r++)
|
||||
{
|
||||
|
@ -11,11 +11,15 @@
|
||||
|
||||
MCP23008 MCP(0x27);
|
||||
|
||||
|
||||
void setup()
|
||||
{
|
||||
Serial.begin(230400);
|
||||
Serial.print("MCP23008_test version: ");
|
||||
Serial.begin(115200);
|
||||
Serial.println(__FILE__);
|
||||
Serial.print("MCP23008_LIB_VERSION: ");
|
||||
Serial.println(MCP23008_LIB_VERSION);
|
||||
Serial.println();
|
||||
delay(100);
|
||||
|
||||
Wire.begin();
|
||||
MCP.begin();
|
||||
|
@ -14,9 +14,12 @@ MCP23008 MCP(0x27);
|
||||
|
||||
void setup()
|
||||
{
|
||||
Serial.begin(230400);
|
||||
Serial.print("MCP23008_test version: ");
|
||||
Serial.begin(115200);
|
||||
Serial.println(__FILE__);
|
||||
Serial.print("MCP23008_LIB_VERSION: ");
|
||||
Serial.println(MCP23008_LIB_VERSION);
|
||||
Serial.println();
|
||||
delay(100);
|
||||
|
||||
Wire.begin();
|
||||
|
||||
|
@ -2,7 +2,7 @@
|
||||
// FILE: MCP23008_performance.ino
|
||||
// AUTHOR: Rob Tillaart
|
||||
// DATE: 2022-01-09
|
||||
// PUPROSE: test MCP23008 library
|
||||
// PURPOSE: test MCP23008 library
|
||||
|
||||
|
||||
#include "MCP23008.h"
|
||||
@ -16,7 +16,7 @@ uint32_t start, stop;
|
||||
void setup()
|
||||
{
|
||||
Serial.begin(115200);
|
||||
Serial.println();
|
||||
Serial.println(__FILE__);
|
||||
Serial.print("MCP23008_LIB_VERSION: ");
|
||||
Serial.println(MCP23008_LIB_VERSION);
|
||||
Serial.println();
|
||||
|
@ -2,7 +2,7 @@
|
||||
// FILE: MCP23008_test.ino
|
||||
// AUTHOR: Rob Tillaart
|
||||
// DATE: 2023-06-20
|
||||
// PUPROSE: test MCP23008 library
|
||||
// PURPOSE: test MCP23008 library
|
||||
|
||||
|
||||
#include "MCP23008.h"
|
||||
@ -10,11 +10,15 @@
|
||||
|
||||
MCP23008 MCP(0x22);
|
||||
|
||||
|
||||
void setup()
|
||||
{
|
||||
Serial.begin(115200);
|
||||
Serial.print("MCP23008_test version: ");
|
||||
Serial.println(__FILE__);
|
||||
Serial.print("MCP23008_LIB_VERSION: ");
|
||||
Serial.println(MCP23008_LIB_VERSION);
|
||||
Serial.println();
|
||||
delay(100);
|
||||
|
||||
Wire.begin();
|
||||
MCP.begin();
|
||||
@ -26,7 +30,7 @@ void setup()
|
||||
|
||||
void test_pin_mode()
|
||||
{
|
||||
MCP.pinMode8(0x00); // 0 = output , 1 = input
|
||||
MCP.pinMode8(0x00); // bit = 0 => output 1 => input
|
||||
uint8_t value = MCP.getPinMode8();
|
||||
Serial.println(value, HEX);
|
||||
|
||||
@ -72,7 +76,7 @@ void test_pin_mode()
|
||||
|
||||
void test_digital_read()
|
||||
{
|
||||
// set all lines to input
|
||||
// set all lines to input
|
||||
MCP.pinMode8(0xFF);
|
||||
uint8_t value = MCP.getPinMode8();
|
||||
Serial.println(value, HEX);
|
||||
@ -96,4 +100,4 @@ void loop()
|
||||
}
|
||||
|
||||
|
||||
// -- END OF FILE --
|
||||
// -- END OF FILE --
|
||||
|
@ -7,6 +7,7 @@ MCP23008 KEYWORD1
|
||||
# Methods and Functions (KEYWORD2)
|
||||
begin KEYWORD2
|
||||
isConnected KEYWORD2
|
||||
getAddress KEYWORD2
|
||||
|
||||
pinMode KEYWORD2
|
||||
digitalWrite KEYWORD2
|
||||
|
@ -15,7 +15,7 @@
|
||||
"type": "git",
|
||||
"url": "https://github.com/RobTillaart/MCP23008.git"
|
||||
},
|
||||
"version": "0.1.5",
|
||||
"version": "0.2.0",
|
||||
"license": "MIT",
|
||||
"frameworks": "*",
|
||||
"platforms": "*",
|
||||
|
@ -1,5 +1,5 @@
|
||||
name=MCP23008
|
||||
version=0.1.5
|
||||
version=0.2.0
|
||||
author=Rob Tillaart <rob.tillaart@gmail.com>
|
||||
maintainer=Rob Tillaart <rob.tillaart@gmail.com>
|
||||
sentence=Arduino library for I2C MCP23008 8 channel port expander 8 IO-lines
|
||||
|
@ -66,7 +66,10 @@ unittest(test_constructor)
|
||||
MCP23008 MCP(0x27);
|
||||
|
||||
assertFalse(Wire.didBegin());
|
||||
|
||||
Wire.begin();
|
||||
MCP.begin();
|
||||
|
||||
// in fact invalid ...
|
||||
assertTrue(Wire.didBegin());
|
||||
assertTrue(MCP.isConnected());
|
||||
@ -78,6 +81,8 @@ unittest(test_lastError)
|
||||
Wire.resetMocks();
|
||||
|
||||
MCP23008 MCP(0x27);
|
||||
|
||||
Wire.begin();
|
||||
MCP.begin();
|
||||
assertEqual(MCP23008_OK, MCP.lastError());
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user