I modified the Adafruit MCP23008 example for blinking an LED, and left the blink code in to verify communication with the MCP23008. I connected the center pin of a 10k pot to the MCP23008 GP2, (pin 2, physical 12) and its other pins to 3.3V and ground, so I can vary the voltage on pin 2.
On github i found a library file by Limor Fried/Ladyada github page that says:
Code: Select all
/**
* Read a single port, A or B, and return its current 8 bit value.
* Parameter b should be 0 for GPIOA, and 1 for GPIOB.
*/
uint8_t Adafruit_MCP23017::readGPIO(uint8_t b) {...
BTW, Bing Chat wrote this when I asked it how to get analog data from an MCP23008:
Code: Select all
#include <Wire.h>
#include <Adafruit_MCP23008.h>
Adafruit_MCP23008 mcp;
void setup() {
mcp.begin(); // use default address 0
}
void loop() {
uint8_t data = mcp.readGPIO();
// process the data
}
4
4
4
...
Code: Select all
#include <Adafruit_MCP23X08.h>
#include <Wire.h>
#define LED_PIN 0
Adafruit_MCP23X08 mcp;
void setup() {
Serial.begin(9600);
delay(500);
Serial.println("MCP23008 Blink and readGPIO Test!");
if (!mcp.begin_I2C()) {
delay(500);
Serial.println("Error.");
delay(500);
}
mcp.pinMode(LED_PIN, OUTPUT);
mcp.pinMode(2, INPUT);
}
void loop() {
mcp.digitalWrite(LED_PIN, HIGH);
delay(1000);
mcp.digitalWrite(LED_PIN, LOW);
delay(1000);
int pin2 = mcp.readGPIO(2);
Serial.println(pin2);
}