mirror of
https://github.com/RobTillaart/Arduino.git
synced 2024-10-03 18:09:02 -04:00
0.1.4 MCP23008
This commit is contained in:
parent
7ec2215aa4
commit
6003fc96cc
@ -6,13 +6,19 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/)
|
||||
and this project adheres to [Semantic Versioning](http://semver.org/).
|
||||
|
||||
|
||||
## [0.1.4] - 2023-06-20
|
||||
- add CMakeLists.txt #8
|
||||
- add debug function **uint8_t getPinMode8()**
|
||||
- add keywords.txt
|
||||
- update examples
|
||||
|
||||
|
||||
## [0.1.3] - 2023-02-04
|
||||
- update readme.md
|
||||
- update GitHub actions
|
||||
- update license 2023
|
||||
- minor edits
|
||||
|
||||
|
||||
## [0.1.2] - 2022-11-17
|
||||
- add RP2040 in build-CI
|
||||
- add changelog.md
|
||||
|
10
libraries/MCP23008/CMakeLists.txt
Normal file
10
libraries/MCP23008/CMakeLists.txt
Normal file
@ -0,0 +1,10 @@
|
||||
# Allows for use with ESP-IDF and Arduino as component
|
||||
# Tested with ESP-IDF v4.4.4
|
||||
|
||||
cmake_minimum_required(VERSION 3.5)
|
||||
|
||||
idf_component_register(SRCS "MCP23008.cpp"
|
||||
INCLUDE_DIRS "."
|
||||
REQUIRES arduino)
|
||||
|
||||
project(MCP23008)
|
@ -1,7 +1,7 @@
|
||||
//
|
||||
// FILE: MCP23008.cpp
|
||||
// AUTHOR: Rob Tillaart
|
||||
// VERSION: 0.1.3
|
||||
// VERSION: 0.1.4
|
||||
// PURPOSE: Arduino library for I2C MCP23008 8 channel port expander
|
||||
// DATE: 2019-10-12
|
||||
// URL: https://github.com/RobTillaart/MCP23008
|
||||
@ -360,6 +360,17 @@ int MCP23008::lastError()
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////
|
||||
//
|
||||
// DEBUG
|
||||
//
|
||||
|
||||
uint8_t MCP23008::getPinMode8()
|
||||
{
|
||||
return readReg(0);
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////
|
||||
//
|
||||
// PRIVATE
|
||||
|
@ -2,7 +2,7 @@
|
||||
//
|
||||
// FILE: MCP23008.h
|
||||
// AUTHOR: Rob Tillaart
|
||||
// VERSION: 0.1.3
|
||||
// VERSION: 0.1.4
|
||||
// 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.3"))
|
||||
#define MCP23008_LIB_VERSION (F("0.1.4"))
|
||||
|
||||
#define MCP23008_OK 0x00
|
||||
#define MCP23008_PIN_ERROR 0x81
|
||||
@ -62,6 +62,10 @@ public:
|
||||
|
||||
int lastError();
|
||||
|
||||
// DEBUG functions
|
||||
uint8_t getPinMode8();
|
||||
|
||||
|
||||
private:
|
||||
bool writeReg(uint8_t reg, uint8_t value);
|
||||
uint8_t readReg(uint8_t reg);
|
||||
|
@ -20,9 +20,21 @@ void setup()
|
||||
Wire.begin();
|
||||
MCP.begin();
|
||||
|
||||
MCP.pinMode8(0xFF);
|
||||
Serial.print("Connect: ");
|
||||
Serial.println(MCP.isConnected());
|
||||
|
||||
// all at once.
|
||||
// MCP.pinMode8(0xFF);
|
||||
// set individual pins
|
||||
for (int pin = 0; pin < 8; pin++)
|
||||
{
|
||||
MCP.pinMode(pin, INPUT);
|
||||
}
|
||||
Serial.println("TEST digitalRead(pin)");
|
||||
}
|
||||
|
||||
void loop()
|
||||
{
|
||||
for (int pin = 0; pin < 8; pin++)
|
||||
{
|
||||
int val = MCP.digitalRead(pin);
|
||||
@ -30,10 +42,7 @@ void setup()
|
||||
Serial.print('\t');
|
||||
}
|
||||
Serial.println();
|
||||
}
|
||||
|
||||
void loop()
|
||||
{
|
||||
delay(1000);
|
||||
}
|
||||
|
||||
|
||||
|
@ -22,21 +22,39 @@ void setup()
|
||||
|
||||
MCP.begin();
|
||||
|
||||
MCP.pinMode8(0x00); // 0 = output , 1 = input
|
||||
pinMode(8, INPUT); // use pin8 to read back MCP.pin0
|
||||
|
||||
MCP.pinMode8(0x00); // 0 = output, 1 = input
|
||||
MCP.write8(0xFF);
|
||||
Wire.setClock(100000);
|
||||
|
||||
Serial.println("TEST digitalWrite(0)");
|
||||
Serial.println("TEST digitalWrite(0) - note bitorder");
|
||||
for (int i = 0; i < 8; i++)
|
||||
{
|
||||
MCP.digitalWrite(0, i % 2); // alternating HIGH/LOW
|
||||
MCP.digitalWrite(0, i % 2); // alternating HIGH/LOW
|
||||
Serial.print(i % 2);
|
||||
Serial.print(digitalRead(8)); // read back status.
|
||||
Serial.print('\t');
|
||||
delay(250);
|
||||
}
|
||||
MCP.digitalWrite(0, LOW);
|
||||
Serial.println();
|
||||
Serial.println();
|
||||
|
||||
Serial.println("TEST digitalWrite(pin)");
|
||||
|
||||
Serial.println("TEST read back");
|
||||
for (int pin = 0; pin < 8; pin++)
|
||||
{
|
||||
int val = MCP.digitalRead(pin);
|
||||
Serial.print(val);
|
||||
Serial.print('\t');
|
||||
}
|
||||
Serial.println();
|
||||
Serial.println(MCP.read8(), HEX);
|
||||
Serial.println();
|
||||
|
||||
|
||||
Serial.println("TEST digitalWrite(pin) - note bitorder");
|
||||
for (int pin = 0; pin < 8; pin++)
|
||||
{
|
||||
MCP.digitalWrite(pin, 1 - pin % 2); // alternating HIGH/LOW
|
||||
@ -46,8 +64,9 @@ void setup()
|
||||
Serial.println();
|
||||
Serial.println();
|
||||
|
||||
Serial.println("TEST read back");
|
||||
|
||||
Serial.println("TEST read back");
|
||||
Serial.println(digitalRead(8));
|
||||
for (int pin = 0; pin < 8; pin++)
|
||||
{
|
||||
int val = MCP.digitalRead(pin);
|
||||
@ -55,6 +74,7 @@ void setup()
|
||||
Serial.print('\t');
|
||||
}
|
||||
Serial.println();
|
||||
Serial.println(MCP.read8(), HEX);
|
||||
Serial.println();
|
||||
}
|
||||
|
||||
|
99
libraries/MCP23008/examples/MCP23008_test/MCP23008_test.ino
Normal file
99
libraries/MCP23008/examples/MCP23008_test/MCP23008_test.ino
Normal file
@ -0,0 +1,99 @@
|
||||
//
|
||||
// FILE: MCP23008_test.ino
|
||||
// AUTHOR: Rob Tillaart
|
||||
// DATE: 2023-06-20
|
||||
// PUPROSE: test MCP23008 library
|
||||
|
||||
|
||||
#include "MCP23008.h"
|
||||
#include "Wire.h"
|
||||
|
||||
MCP23008 MCP(0x22);
|
||||
|
||||
void setup()
|
||||
{
|
||||
Serial.begin(115200);
|
||||
Serial.print("MCP23008_test version: ");
|
||||
Serial.println(MCP23008_LIB_VERSION);
|
||||
|
||||
Wire.begin();
|
||||
MCP.begin();
|
||||
|
||||
test_pin_mode();
|
||||
test_digital_read();
|
||||
}
|
||||
|
||||
|
||||
void test_pin_mode()
|
||||
{
|
||||
MCP.pinMode8(0x00); // 0 = output , 1 = input
|
||||
uint8_t value = MCP.getPinMode8();
|
||||
Serial.println(value, HEX);
|
||||
|
||||
MCP.pinMode8(0xFF);
|
||||
value = MCP.getPinMode8();
|
||||
Serial.println(value, HEX);
|
||||
|
||||
Serial.println();
|
||||
for (int i = 0; i < 8; i++)
|
||||
{
|
||||
MCP.pinMode(i, OUTPUT);
|
||||
value = MCP.getPinMode8();
|
||||
Serial.println(value, HEX);
|
||||
}
|
||||
|
||||
Serial.println();
|
||||
for (int i = 0; i < 8; i++)
|
||||
{
|
||||
MCP.pinMode(i, INPUT);
|
||||
value = MCP.getPinMode8();
|
||||
Serial.println(value, HEX);
|
||||
}
|
||||
|
||||
Serial.println();
|
||||
for (int i = 0; i < 8; i++)
|
||||
{
|
||||
MCP.pinMode(i, OUTPUT);
|
||||
value = MCP.getPinMode8();
|
||||
Serial.println(value, HEX);
|
||||
}
|
||||
|
||||
Serial.println();
|
||||
for (int i = 0; i < 8; i++)
|
||||
{
|
||||
MCP.pinMode(i, INPUT_PULLUP);
|
||||
value = MCP.getPinMode8();
|
||||
Serial.println(value, HEX);
|
||||
}
|
||||
|
||||
Serial.println();
|
||||
}
|
||||
|
||||
|
||||
void test_digital_read()
|
||||
{
|
||||
// set all lines to input
|
||||
MCP.pinMode8(0xFF);
|
||||
uint8_t value = MCP.getPinMode8();
|
||||
Serial.println(value, HEX);
|
||||
|
||||
uint32_t start = millis();
|
||||
while (millis() - start < 60000)
|
||||
{
|
||||
for (int i = 0; i < 8; i++)
|
||||
{
|
||||
value = MCP.digitalRead(i);
|
||||
Serial.print(value, HEX);
|
||||
}
|
||||
Serial.println();
|
||||
delay(1000);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void loop()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
// -- END OF FILE --
|
44
libraries/MCP23008/keywords.txt
Normal file
44
libraries/MCP23008/keywords.txt
Normal file
@ -0,0 +1,44 @@
|
||||
# Syntax Colouring Map For MCP23008
|
||||
|
||||
# Data types (KEYWORD1)
|
||||
MCP23008 KEYWORD1
|
||||
|
||||
|
||||
# Methods and Functions (KEYWORD2)
|
||||
begin KEYWORD2
|
||||
isConnected KEYWORD2
|
||||
|
||||
pinMode KEYWORD2
|
||||
digitalWrite KEYWORD2
|
||||
digitalRead KEYWORD2
|
||||
|
||||
setPolarity KEYWORD2
|
||||
getPolarity KEYWORD2
|
||||
setPullup KEYWORD2
|
||||
getPullup KEYWORD2
|
||||
|
||||
pinMode8 KEYWORD2
|
||||
write8 KEYWORD2
|
||||
read8 KEYWORD2
|
||||
|
||||
setPolarity8 KEYWORD2
|
||||
getPolarity8 KEYWORD2
|
||||
setPullup8 KEYWORD2
|
||||
getPullup8 KEYWORD2
|
||||
|
||||
lastError KEYWORD2
|
||||
|
||||
getPinMode8 KEYWORD2
|
||||
|
||||
|
||||
# Instances (KEYWORD2)
|
||||
|
||||
|
||||
# Constants (LITERAL1)
|
||||
MCP23008_LIB_VERSION LITERAL1
|
||||
|
||||
MCP23008_OK LITERAL1
|
||||
MCP23008_PIN_ERROR LITERAL1
|
||||
MCP23008_I2C_ERROR LITERAL1
|
||||
MCP23008_VALUE_ERROR LITERAL1
|
||||
MCP23008_PORT_ERROR LITERAL1
|
@ -15,7 +15,7 @@
|
||||
"type": "git",
|
||||
"url": "https://github.com/RobTillaart/MCP23008.git"
|
||||
},
|
||||
"version": "0.1.3",
|
||||
"version": "0.1.4",
|
||||
"license": "MIT",
|
||||
"frameworks": "arduino",
|
||||
"platforms": "*",
|
||||
|
@ -1,5 +1,5 @@
|
||||
name=MCP23008
|
||||
version=0.1.3
|
||||
version=0.1.4
|
||||
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
|
||||
|
Loading…
Reference in New Issue
Block a user