IP Configuration
This commit is contained in:
46
lib/Adafruit-MCP23008/.github/ISSUE_TEMPLATE.md
vendored
Normal file
46
lib/Adafruit-MCP23008/.github/ISSUE_TEMPLATE.md
vendored
Normal file
@@ -0,0 +1,46 @@
|
||||
Thank you for opening an issue on an Adafruit Arduino library repository. To
|
||||
improve the speed of resolution please review the following guidelines and
|
||||
common troubleshooting steps below before creating the issue:
|
||||
|
||||
- **Do not use GitHub issues for troubleshooting projects and issues.** Instead use
|
||||
the forums at http://forums.adafruit.com to ask questions and troubleshoot why
|
||||
something isn't working as expected. In many cases the problem is a common issue
|
||||
that you will more quickly receive help from the forum community. GitHub issues
|
||||
are meant for known defects in the code. If you don't know if there is a defect
|
||||
in the code then start with troubleshooting on the forum first.
|
||||
|
||||
- **If following a tutorial or guide be sure you didn't miss a step.** Carefully
|
||||
check all of the steps and commands to run have been followed. Consult the
|
||||
forum if you're unsure or have questions about steps in a guide/tutorial.
|
||||
|
||||
- **For Arduino projects check these very common issues to ensure they don't apply**:
|
||||
|
||||
- For uploading sketches or communicating with the board make sure you're using
|
||||
a **USB data cable** and **not** a **USB charge-only cable**. It is sometimes
|
||||
very hard to tell the difference between a data and charge cable! Try using the
|
||||
cable with other devices or swapping to another cable to confirm it is not
|
||||
the problem.
|
||||
|
||||
- **Be sure you are supplying adequate power to the board.** Check the specs of
|
||||
your board and plug in an external power supply. In many cases just
|
||||
plugging a board into your computer is not enough to power it and other
|
||||
peripherals.
|
||||
|
||||
- **Double check all soldering joints and connections.** Flakey connections
|
||||
cause many mysterious problems. See the [guide to excellent soldering](https://learn.adafruit.com/adafruit-guide-excellent-soldering/tools) for examples of good solder joints.
|
||||
|
||||
- **Ensure you are using an official Arduino or Adafruit board.** We can't
|
||||
guarantee a clone board will have the same functionality and work as expected
|
||||
with this code and don't support them.
|
||||
|
||||
If you're sure this issue is a defect in the code and checked the steps above
|
||||
please fill in the following fields to provide enough troubleshooting information.
|
||||
You may delete the guideline and text above to just leave the following details:
|
||||
|
||||
- Arduino board: **INSERT ARDUINO BOARD NAME/TYPE HERE**
|
||||
|
||||
- Arduino IDE version (found in Arduino -> About Arduino menu): **INSERT ARDUINO
|
||||
VERSION HERE**
|
||||
|
||||
- List the steps to reproduce the problem below (if possible attach a sketch or
|
||||
copy the sketch code in too): **LIST REPRO STEPS BELOW**
|
||||
26
lib/Adafruit-MCP23008/.github/PULL_REQUEST_TEMPLATE.md
vendored
Normal file
26
lib/Adafruit-MCP23008/.github/PULL_REQUEST_TEMPLATE.md
vendored
Normal file
@@ -0,0 +1,26 @@
|
||||
Thank you for creating a pull request to contribute to Adafruit's GitHub code!
|
||||
Before you open the request please review the following guidelines and tips to
|
||||
help it be more easily integrated:
|
||||
|
||||
- **Describe the scope of your change--i.e. what the change does and what parts
|
||||
of the code were modified.** This will help us understand any risks of integrating
|
||||
the code.
|
||||
|
||||
- **Describe any known limitations with your change.** For example if the change
|
||||
doesn't apply to a supported platform of the library please mention it.
|
||||
|
||||
- **Please run any tests or examples that can exercise your modified code.** We
|
||||
strive to not break users of the code and running tests/examples helps with this
|
||||
process.
|
||||
|
||||
Thank you again for contributing! We will try to test and integrate the change
|
||||
as soon as we can, but be aware we have many GitHub repositories to manage and
|
||||
can't immediately respond to every request. There is no need to bump or check in
|
||||
on a pull request (it will clutter the discussion of the request).
|
||||
|
||||
Also don't be worried if the request is closed or not integrated--sometimes the
|
||||
priorities of Adafruit's GitHub code (education, ease of use) might not match the
|
||||
priorities of the pull request. Don't fret, the open source community thrives on
|
||||
forks and GitHub makes it easy to keep your changes in a forked repo.
|
||||
|
||||
After reviewing the guidelines above you can delete this text from the pull request.
|
||||
187
lib/Adafruit-MCP23008/Adafruit_MCP23008.cpp
Normal file
187
lib/Adafruit-MCP23008/Adafruit_MCP23008.cpp
Normal file
@@ -0,0 +1,187 @@
|
||||
/***************************************************
|
||||
This is a library for the MCP23008 i2c port expander
|
||||
|
||||
These displays use I2C to communicate, 2 pins are required to
|
||||
interface
|
||||
Adafruit invests time and resources providing this open source code,
|
||||
please support Adafruit and open-source hardware by purchasing
|
||||
products from Adafruit!
|
||||
|
||||
Written by Limor Fried/Ladyada for Adafruit Industries.
|
||||
BSD license, all text above must be included in any redistribution
|
||||
****************************************************/
|
||||
|
||||
#if ARDUINO >= 100
|
||||
#include "Arduino.h"
|
||||
#else
|
||||
#include "WProgram.h"
|
||||
#endif
|
||||
#ifdef __AVR_ATtiny85__
|
||||
#include <TinyWireM.h>
|
||||
#define Wire TinyWireM
|
||||
#else
|
||||
#include <Wire.h>
|
||||
#endif
|
||||
|
||||
#ifdef __AVR
|
||||
#include <avr/pgmspace.h>
|
||||
#elif defined(ESP8266)
|
||||
#include <pgmspace.h>
|
||||
#endif
|
||||
#include "Adafruit_MCP23008.h"
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// RTC_DS1307 implementation
|
||||
|
||||
void Adafruit_MCP23008::begin(uint8_t addr) {
|
||||
if (addr > 7) {
|
||||
addr = 7;
|
||||
}
|
||||
i2caddr = addr;
|
||||
|
||||
Wire.begin();
|
||||
|
||||
// set defaults!
|
||||
Wire.beginTransmission(MCP23008_ADDRESS | i2caddr);
|
||||
#if ARDUINO >= 100
|
||||
Wire.write((byte)MCP23008_IODIR);
|
||||
Wire.write((byte)0xFF); // all inputs
|
||||
Wire.write((byte)0x00);
|
||||
Wire.write((byte)0x00);
|
||||
Wire.write((byte)0x00);
|
||||
Wire.write((byte)0x00);
|
||||
Wire.write((byte)0x00);
|
||||
Wire.write((byte)0x00);
|
||||
Wire.write((byte)0x00);
|
||||
Wire.write((byte)0x00);
|
||||
Wire.write((byte)0x00);
|
||||
#else
|
||||
Wire.send(MCP23008_IODIR);
|
||||
Wire.send(0xFF); // all inputs
|
||||
Wire.send(0x00);
|
||||
Wire.send(0x00);
|
||||
Wire.send(0x00);
|
||||
Wire.send(0x00);
|
||||
Wire.send(0x00);
|
||||
Wire.send(0x00);
|
||||
Wire.send(0x00);
|
||||
Wire.send(0x00);
|
||||
Wire.send(0x00);
|
||||
#endif
|
||||
Wire.endTransmission();
|
||||
|
||||
}
|
||||
|
||||
void Adafruit_MCP23008::begin(void) {
|
||||
begin(0);
|
||||
}
|
||||
|
||||
void Adafruit_MCP23008::pinMode(uint8_t p, uint8_t d) {
|
||||
uint8_t iodir;
|
||||
|
||||
|
||||
// only 8 bits!
|
||||
if (p > 7)
|
||||
return;
|
||||
|
||||
iodir = read8(MCP23008_IODIR);
|
||||
|
||||
// set the pin and direction
|
||||
if (d == INPUT) {
|
||||
iodir |= 1 << p;
|
||||
} else {
|
||||
iodir &= ~(1 << p);
|
||||
}
|
||||
|
||||
// write the new IODIR
|
||||
write8(MCP23008_IODIR, iodir);
|
||||
}
|
||||
|
||||
uint8_t Adafruit_MCP23008::readGPIO(void) {
|
||||
// read the current GPIO input
|
||||
return read8(MCP23008_GPIO);
|
||||
}
|
||||
|
||||
void Adafruit_MCP23008::writeGPIO(uint8_t gpio) {
|
||||
write8(MCP23008_GPIO, gpio);
|
||||
}
|
||||
|
||||
|
||||
void Adafruit_MCP23008::digitalWrite(uint8_t p, uint8_t d) {
|
||||
uint8_t gpio;
|
||||
|
||||
// only 8 bits!
|
||||
if (p > 7)
|
||||
return;
|
||||
|
||||
// read the current GPIO output latches
|
||||
gpio = readGPIO();
|
||||
|
||||
// set the pin and direction
|
||||
if (d == HIGH) {
|
||||
gpio |= 1 << p;
|
||||
} else {
|
||||
gpio &= ~(1 << p);
|
||||
}
|
||||
|
||||
// write the new GPIO
|
||||
writeGPIO(gpio);
|
||||
}
|
||||
|
||||
void Adafruit_MCP23008::pullUp(uint8_t p, uint8_t d) {
|
||||
uint8_t gppu;
|
||||
|
||||
// only 8 bits!
|
||||
if (p > 7)
|
||||
return;
|
||||
|
||||
gppu = read8(MCP23008_GPPU);
|
||||
// set the pin and direction
|
||||
if (d == HIGH) {
|
||||
gppu |= 1 << p;
|
||||
} else {
|
||||
gppu &= ~(1 << p);
|
||||
}
|
||||
// write the new GPIO
|
||||
write8(MCP23008_GPPU, gppu);
|
||||
}
|
||||
|
||||
uint8_t Adafruit_MCP23008::digitalRead(uint8_t p) {
|
||||
// only 8 bits!
|
||||
if (p > 7)
|
||||
return 0;
|
||||
|
||||
// read the current GPIO
|
||||
return (readGPIO() >> p) & 0x1;
|
||||
}
|
||||
|
||||
uint8_t Adafruit_MCP23008::read8(uint8_t addr) {
|
||||
Wire.beginTransmission(MCP23008_ADDRESS | i2caddr);
|
||||
#if ARDUINO >= 100
|
||||
Wire.write((byte)addr);
|
||||
#else
|
||||
Wire.send(addr);
|
||||
#endif
|
||||
Wire.endTransmission();
|
||||
Wire.requestFrom(MCP23008_ADDRESS | i2caddr, 1);
|
||||
|
||||
#if ARDUINO >= 100
|
||||
return Wire.read();
|
||||
#else
|
||||
return Wire.receive();
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
void Adafruit_MCP23008::write8(uint8_t addr, uint8_t data) {
|
||||
Wire.beginTransmission(MCP23008_ADDRESS | i2caddr);
|
||||
#if ARDUINO >= 100
|
||||
Wire.write((byte)addr);
|
||||
Wire.write((byte)data);
|
||||
#else
|
||||
Wire.send(addr);
|
||||
Wire.send(data);
|
||||
#endif
|
||||
Wire.endTransmission();
|
||||
}
|
||||
56
lib/Adafruit-MCP23008/Adafruit_MCP23008.h
Normal file
56
lib/Adafruit-MCP23008/Adafruit_MCP23008.h
Normal file
@@ -0,0 +1,56 @@
|
||||
/***************************************************
|
||||
This is a library for the MCP23008 i2c port expander
|
||||
|
||||
These displays use I2C to communicate, 2 pins are required to
|
||||
interface
|
||||
Adafruit invests time and resources providing this open source code,
|
||||
please support Adafruit and open-source hardware by purchasing
|
||||
products from Adafruit!
|
||||
|
||||
Written by Limor Fried/Ladyada for Adafruit Industries.
|
||||
BSD license, all text above must be included in any redistribution
|
||||
****************************************************/
|
||||
|
||||
#ifndef _ADAFRUIT_MCP23008_H
|
||||
#define _ADAFRUIT_MCP23008_H
|
||||
// Don't forget the Wire library
|
||||
#ifdef __AVR_ATtiny85__
|
||||
#include <TinyWireM.h>
|
||||
#else
|
||||
#include <Wire.h>
|
||||
#endif
|
||||
|
||||
class Adafruit_MCP23008 {
|
||||
public:
|
||||
void begin(uint8_t addr);
|
||||
void begin(void);
|
||||
|
||||
void pinMode(uint8_t p, uint8_t d);
|
||||
void digitalWrite(uint8_t p, uint8_t d);
|
||||
void pullUp(uint8_t p, uint8_t d);
|
||||
uint8_t digitalRead(uint8_t p);
|
||||
uint8_t readGPIO(void);
|
||||
void writeGPIO(uint8_t);
|
||||
|
||||
private:
|
||||
uint8_t i2caddr;
|
||||
uint8_t read8(uint8_t addr);
|
||||
void write8(uint8_t addr, uint8_t data);
|
||||
};
|
||||
|
||||
#define MCP23008_ADDRESS 0x20
|
||||
|
||||
// registers
|
||||
#define MCP23008_IODIR 0x00
|
||||
#define MCP23008_IPOL 0x01
|
||||
#define MCP23008_GPINTEN 0x02
|
||||
#define MCP23008_DEFVAL 0x03
|
||||
#define MCP23008_INTCON 0x04
|
||||
#define MCP23008_IOCON 0x05
|
||||
#define MCP23008_GPPU 0x06
|
||||
#define MCP23008_INTF 0x07
|
||||
#define MCP23008_INTCAP 0x08
|
||||
#define MCP23008_GPIO 0x09
|
||||
#define MCP23008_OLAT 0x0A
|
||||
|
||||
#endif
|
||||
19
lib/Adafruit-MCP23008/README
Normal file
19
lib/Adafruit-MCP23008/README
Normal file
@@ -0,0 +1,19 @@
|
||||
To download, click "Download Source" in the top right corner. Then install as indicated in our tutorial:
|
||||
--> http://www.ladyada.net/library/arduino/libraries.html
|
||||
in a folder called Adafruit_MCP23008.
|
||||
|
||||
This is very much beta, it seems to work fine but its not optimized and doesn't currently suport the interrupt capability of the chip
|
||||
|
||||
Currently it can do: setting pin directions, inputs and outputs and turning on/off the pull-up resistors
|
||||
|
||||
To use:
|
||||
Connect pin #1 of the expander to Analog 5 (i2c clock)
|
||||
Connect pin #2 of the expander to Analog 4 (i2c data)
|
||||
Connect pins #3, 4 and 5 of the expander to ground (address selection)
|
||||
Connect pin #6 and 18 of the expander to 5V (power and reset disable)
|
||||
Connect pin #9 of the expander to ground (common ground)
|
||||
Pins 10 thru 17 are your input/output pins
|
||||
|
||||
Check the datasheet for more info: http://ww1.microchip.com/downloads/en/DeviceDoc/21919b.pdf
|
||||
|
||||
Enjoy and send pull requests!
|
||||
31
lib/Adafruit-MCP23008/examples/button/button.pde
Normal file
31
lib/Adafruit-MCP23008/examples/button/button.pde
Normal file
@@ -0,0 +1,31 @@
|
||||
#include <Wire.h>
|
||||
#include "Adafruit_MCP23008.h"
|
||||
|
||||
// Basic pin reading and pullup test for the MCP23008 I/O expander
|
||||
// public domain!
|
||||
|
||||
// Connect pin #1 of the expander to Analog 5 (i2c clock)
|
||||
// Connect pin #2 of the expander to Analog 4 (i2c data)
|
||||
// Connect pins #3, 4 and 5 of the expander to ground (address selection)
|
||||
// Connect pin #6 and 18 of the expander to 5V (power and reset disable)
|
||||
// Connect pin #9 of the expander to ground (common ground)
|
||||
|
||||
// Input #0 is on pin 10 so connect a button or switch from there to ground
|
||||
|
||||
Adafruit_MCP23008 mcp;
|
||||
|
||||
void setup() {
|
||||
mcp.begin(); // use default address 0
|
||||
|
||||
mcp.pinMode(0, INPUT);
|
||||
mcp.pullUp(0, HIGH); // turn on a 100K pullup internally
|
||||
|
||||
pinMode(13, OUTPUT); // use the p13 LED as debugging
|
||||
}
|
||||
|
||||
|
||||
|
||||
void loop() {
|
||||
// The LED will 'echo' the button
|
||||
digitalWrite(13, mcp.digitalRead(0));
|
||||
}
|
||||
34
lib/Adafruit-MCP23008/examples/toggle/toggle.pde
Normal file
34
lib/Adafruit-MCP23008/examples/toggle/toggle.pde
Normal file
@@ -0,0 +1,34 @@
|
||||
#include <Wire.h>
|
||||
#include "Adafruit_MCP23008.h"
|
||||
|
||||
// Basic toggle test for i/o expansion. flips pin #0 of a MCP23008 i2c
|
||||
// pin expander up and down. Public domain
|
||||
|
||||
// Connect pin #1 of the expander to Analog 5 (i2c clock)
|
||||
// Connect pin #2 of the expander to Analog 4 (i2c data)
|
||||
// Connect pins #3, 4 and 5 of the expander to ground (address selection)
|
||||
// Connect pin #6 and 18 of the expander to 5V (power and reset disable)
|
||||
// Connect pin #9 of the expander to ground (common ground)
|
||||
|
||||
// Output #0 is on pin 10 so connect an LED or whatever from that to ground
|
||||
|
||||
Adafruit_MCP23008 mcp;
|
||||
|
||||
void setup() {
|
||||
mcp.begin(); // use default address 0
|
||||
|
||||
mcp.pinMode(0, OUTPUT);
|
||||
}
|
||||
|
||||
|
||||
// flip the pin #0 up and down
|
||||
|
||||
void loop() {
|
||||
delay(100);
|
||||
|
||||
mcp.digitalWrite(0, HIGH);
|
||||
|
||||
delay(100);
|
||||
|
||||
mcp.digitalWrite(0, LOW);
|
||||
}
|
||||
20
lib/Adafruit-MCP23008/keywords.txt
Normal file
20
lib/Adafruit-MCP23008/keywords.txt
Normal file
@@ -0,0 +1,20 @@
|
||||
#######################################
|
||||
# Syntax Coloring Map for MCP23008
|
||||
#######################################
|
||||
|
||||
#######################################
|
||||
# Datatypes (KEYWORD1)
|
||||
#######################################
|
||||
|
||||
MCP23008 KEYWORD1
|
||||
|
||||
#######################################
|
||||
# Methods and Functions (KEYWORD2)
|
||||
#######################################
|
||||
|
||||
pullUp KEYWORD2
|
||||
|
||||
|
||||
#######################################
|
||||
# Constants (LITERAL1)
|
||||
#######################################
|
||||
9
lib/Adafruit-MCP23008/library.properties
Normal file
9
lib/Adafruit-MCP23008/library.properties
Normal file
@@ -0,0 +1,9 @@
|
||||
name=Adafruit MCP23008 library
|
||||
version=1.0.2
|
||||
author=Adafruit
|
||||
maintainer=Adafruit <info@adafruit.com>
|
||||
sentence=Arduino Library for the MCP23008 (and '9) I2C I/O expander
|
||||
paragraph=Arduino Library for the MCP23008 (and '9) I2C I/O expander
|
||||
category=Signal Input/Output
|
||||
url=https://github.com/adafruit/Adafruit-MCP23008-library
|
||||
architectures=*
|
||||
Reference in New Issue
Block a user