diff options
| -rw-r--r-- | MCP23017/MCP23017.ino | 45 | ||||
| -rw-r--r-- | MCP23017/mcp20317_schemss.jpg | bin | 0 -> 21944 bytes | |||
| -rw-r--r-- | MCP23017/with_lib/with_lib.ino | 28 | ||||
| -rw-r--r-- | pcb_boven/pcb_boven.sch | 46 | ||||
| -rw-r--r-- | pcb_boven/pcb_boven.sch-bak | 38 |
5 files changed, 148 insertions, 9 deletions
diff --git a/MCP23017/MCP23017.ino b/MCP23017/MCP23017.ino new file mode 100644 index 0000000..30c75bc --- /dev/null +++ b/MCP23017/MCP23017.ino @@ -0,0 +1,45 @@ +//https://tronixstuff.com/2011/08/26/arduino-mcp23017-tutorial/ +//https://www.circuitbasics.com/how-to-use-an-mpc23017-port-expander-on-the-arduino/ +//https://ww1.microchip.com/downloads/en/devicedoc/20001952c.pdf + + + +#include <Wire.h> +byte BbyteVal=0; +byte AbyteVal=0; +byte chipAddr = 0x20; +byte GPIOA = 0x12; // PortA reg addr +byte GPIOB = 0x13; // PortB reg addr +byte IODIRA = 0x00; // PortA direction reg addr +byte IODIRB = 0x01; // PortB direction reg addr + +void setup(){ + Serial.begin(9600); + Wire.begin(); + + Wire.beginTransmission(chipAddr); + Wire.write(IODIRA); // IODIRA dir register + Wire.write(0xff); // set entire PORT A as output + Wire.endTransmission(); + + Wire.beginTransmission(chipAddr); + Wire.write(IODIRB); // IODIRB dir register + Wire.write(0xff); // set entire PORT B as input + Wire.endTransmission(); + } + +void loop(){ + Wire.beginTransmission(chipAddr); + Wire.write(GPIOB); // read the inputs off PORT B + Wire.requestFrom(chipAddr, 1); // ask for 1 byte + BbyteVal = Wire.read(); // read it + Wire.endTransmission(); + Serial.println(BbyteVal); + + Wire.beginTransmission(chipAddr); + Wire.write(GPIOB); // read the inputs off PORT B + Wire.requestFrom(chipAddr, 1); // ask for 1 byte + AbyteVal = Wire.read(); // read it + Wire.endTransmission(); + Serial.println(AbyteVal); +} diff --git a/MCP23017/mcp20317_schemss.jpg b/MCP23017/mcp20317_schemss.jpg Binary files differnew file mode 100644 index 0000000..5231394 --- /dev/null +++ b/MCP23017/mcp20317_schemss.jpg diff --git a/MCP23017/with_lib/with_lib.ino b/MCP23017/with_lib/with_lib.ino new file mode 100644 index 0000000..f99065a --- /dev/null +++ b/MCP23017/with_lib/with_lib.ino @@ -0,0 +1,28 @@ +/** Inputs.ino + * Sets port 7 on bank B to INPUT_PULLUP and copies its + * state to the built-in LED on the board + * https://github.com/ndomx/MCP23017-Arduino-Library + */ + +#include <mcp23017.h> + +#define MCP_ADDR (0) + +MCP23017 mcp(MCP_ADDR); + +void setup(void) +{ + Serial.begin(9600); + pinMode(LED_BUILTIN, OUTPUT); + + mcp.start(); + mcp.pinMode(GPB7, INPUT_PULLUP); +} + +void loop(void) +{ + byte mcp_input = mcp.digitalRead(GPB7); + digitalWrite(LED_BUILTIN, mcp_input); + Serial.println(mcp_input); + delay(500); +} diff --git a/pcb_boven/pcb_boven.sch b/pcb_boven/pcb_boven.sch index a5d5ec3..c537fa1 100644 --- a/pcb_boven/pcb_boven.sch +++ b/pcb_boven/pcb_boven.sch @@ -854,16 +854,12 @@ Wire Wire Line 7425 6175 7425 7400 Connection ~ 7425 7400 Wire Wire Line - 7425 7400 8075 7400 -Wire Wire Line 7350 7300 7350 6250 Wire Wire Line 7350 6250 6950 6250 Wire Wire Line 6950 6250 6950 5250 Connection ~ 7350 7300 -Wire Wire Line - 7350 7300 8100 7300 Text GLabel 1300 10175 0 50 Input ~ 0 A Text GLabel 1300 10075 0 50 Input ~ 0 @@ -881,8 +877,6 @@ Wire Wire Line Wire Wire Line 8125 6700 8350 6700 Wire Wire Line - 8625 6700 8625 6975 -Wire Wire Line 8625 6975 10025 6975 Connection ~ 8125 6700 Wire Wire Line @@ -931,4 +925,44 @@ Wire Wire Line 8475 8600 8475 5325 Wire Wire Line 8475 5325 8750 5325 +Wire Wire Line + 7350 7300 8100 7300 +Wire Wire Line + 8625 5525 8625 6700 +Connection ~ 8625 6700 +Wire Wire Line + 8625 6700 8625 6975 +Connection ~ 8625 6975 +Wire Wire Line + 8625 6975 8625 7300 +Connection ~ 8100 7300 +Wire Wire Line + 8100 7300 8625 7300 +Wire Wire Line + 8650 5625 8650 7400 +Wire Wire Line + 7425 7400 8075 7400 +Connection ~ 8075 7400 +Wire Wire Line + 8075 7400 8650 7400 +Wire Wire Line + 8750 5525 8625 5525 +Wire Wire Line + 8625 5525 5000 5525 +Wire Wire Line + 5000 5525 5000 6700 +Wire Wire Line + 5000 6700 5025 6700 +Connection ~ 8625 5525 +Wire Wire Line + 5025 6800 5025 6750 +Wire Wire Line + 5025 6750 5050 6750 +Wire Wire Line + 5050 6750 5050 5625 +Wire Wire Line + 5050 5625 8650 5625 +Connection ~ 8650 5625 +Wire Wire Line + 8650 5625 8750 5625 $EndSCHEMATC diff --git a/pcb_boven/pcb_boven.sch-bak b/pcb_boven/pcb_boven.sch-bak index 874e36b..a5d5ec3 100644 --- a/pcb_boven/pcb_boven.sch-bak +++ b/pcb_boven/pcb_boven.sch-bak @@ -869,11 +869,9 @@ A Text GLabel 1300 10075 0 50 Input ~ 0 B Wire Wire Line - 4800 7700 5025 7700 -Wire Wire Line 950 10175 4800 10175 Wire Wire Line - 4800 10175 4800 7700 + 4800 10175 4800 8100 Wire Wire Line 5025 7600 4775 7600 Wire Wire Line @@ -899,4 +897,38 @@ Wire Wire Line 8200 5825 8700 5825 Connection ~ 8200 2375 Connection ~ 8700 5825 +Wire Wire Line + 8750 5425 4975 5425 +Wire Wire Line + 4975 5425 4975 7700 +Wire Wire Line + 4975 7700 5025 7700 +Wire Wire Line + 5025 8100 4800 8100 +Wire Wire Line + 5025 7800 4950 7800 +Wire Wire Line + 4950 7800 4950 5300 +Wire Wire Line + 4950 5300 8275 5300 +Wire Wire Line + 8275 5300 8275 5125 +Wire Wire Line + 8275 5125 8750 5125 +Wire Wire Line + 8750 5225 8325 5225 +Wire Wire Line + 8325 5225 8325 5350 +Wire Wire Line + 8325 5350 4925 5350 +Wire Wire Line + 4925 5350 4925 7900 +Wire Wire Line + 4925 7900 5025 7900 +Wire Wire Line + 7225 8600 8475 8600 +Wire Wire Line + 8475 8600 8475 5325 +Wire Wire Line + 8475 5325 8750 5325 $EndSCHEMATC |
