The integrated circuits ADS1115, MCP23017, PCF8574 and PCA9685 are 4 solutions to very easily increase the number of digital IO, PWM and analog inputs / outputs via the I2C bus. This will keep the source code of your project and save development time by avoiding having to migrate to another platform such as STM32 or ESP32. This is for example the case of the ESP8266 micro-controller has a single analog input and 8 digital I/O.
All of these expansion boards use the I2C bus to communicate. Consequently, they can be used by all compatible platforms including Raspberry Pi, Orange Pi, Odroid nano PCs …
ADS1115 (ADSxxxx), add 4x 16-bit A/D inputs
The ADS1115 integrated circuit allows you to add 4 analog inputs
Main technical characteristics
|
MCP23017, add 16x digital I/O over I2C. MCP23S17 (SPI version)
The MPC23017 integrated circuit allows the addition of 16 additional digital IO via the I2C bus.
The MCP23S17 is a version suitable for the SPI bus up to 10 MHz.
Main technical characteristics
|
Basic connection for integrated circuits
Please note, to be able to use the DIP28 or SO28 package version, you must connect the following pins
- I2C SDA and SCL pins at 3.3V using a 4.7 KΩ pull-up resistor .
- Pins A0, A1 and A2 to GND
- RESET to 3.3V
- VDD at 3.3V
- VSS to GND
Example code to light an LED
#include <Wire.h>
#include "Adafruit_MCP23017.h"
// Basic pin reading and pullup test for the MCP23017 I/O expander
// public domain!
// Connect pin #12 of the expander to Analog 5 (i2c clock)
// Connect pin #13 of the expander to Analog 4 (i2c data)
// Connect pins #15, 16 and 17 of the expander to ground (address selection)
// Connect pin #9 of the expander to 5V (power)
// Connect pin #10 of the expander to ground (common ground)
// Connect pin #18 through a ~10kohm resistor to 5V (reset pin, active low)
// Input #0 is on pin 21 so connect a button or switch from there to ground
Adafruit_MCP23017 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));
}
PCF8574, add 8x digital IO
Texas Instrument’s PCF8574 integrated circuit allows you to add 8 additional digital IO. Operation is very similar to Microchip’s MCP23017 seen previously
Main technical characteristics
- Manufacturer: Texas Instrument
- Power supply:
- from 2.5V to 6V
- standby current: 10 μA max
- Output current: 25mA per output
- I2C addresses
- Primary: 0x38
- Alternative : 0x3F
- Other: use pins A0, A1 and A2 to assign an address
- Supported I2C bus speed: 100kHz, 400kHz and 1MHz
- Brooches
- VCC Power supply (2.5V to 6V)
- GNG electrical ground
- A0, A1, A2: I2C address selector. No need to connect to GND or VCC if default address
- Bookstores
- PCF8574 by Rob Tillaart (PIO 1358)
- Availability
- DIP16 box to be welded at 2.54mm pitch
- Expansion board
- Technical documentation
PCA9685, add 16x 12-bit PWM channels for LED or servo motors
The PCA9685 integrated circuit allows you to add 16 12-bit PWM channels that will drive LEDs or low power servo motors. The PCA9685 is perfectly suited to control robotic arms.
Main technical characteristics
- Manufacturer: NXP
- Power supply:
- from 2.3V to 5.5V
- over-voltage protection
- standby current: 1 μA max.
- Output current: 20mA per output without exceeding 150mA in total on VSS
- PWM outputs
- 16 12-bit outputs (4096 levels) for LEDs
- Frequency from 24 Hz to 1526 Hz
- I2C addresses
- Primary: 0x40
- Alternative : 0x7F
- Other: use pins A0 to A5 to assign an address manually. 64 possible addresses
- Supported I2C bus speed: 1MHz
- Brooches
- VDD Power supply (2.3V to 5.5V)
- VSS GND, electrical ground
- A0 to A5: up to 62 I2C addresses to drive up to 992 LEDs by combining several PCA9685
- Bookstores
- Adafruit PWM Servo Driver Library (PIO 30)
sumotoy servo_PCA9685 to drive servomotors
- Availability
- Expansion board
- Technical documentation
The complete test of the Geekcreit expansion board with Arduino or MicroPython code
Other projects
- Unpacking the Geekcreit PCA9685 I2C Shield 16 Servos + 2 DC motors for Arduino or ESPDuino (ESP8266)
Example of Arduino code to drive a servo motor
A small example which varies the position of a servo motor over 180 ° developed using the Sumotoy library.
/*
Test PCA9685 driver Doit.am 16 servos I2C shield
Compatible Arduino Uno / Espduino / ESP8266
*/
#include <Wire.h>
#include <servo_PCA9685.h>
#define MAX_SERVOS 16
/*
* ESP8266 I2C - pins
* SDA: 4 - D2
* SCL: 5 - D1
*/
servo_PCA9685 servo = servo_PCA9685();
uint8_t servonum = 0;
void setup() {
#if defined(ESP8266)
Serial.begin(115200);
#else
Serial.begin(38400);
#endif
Serial.println("\nservo start");
servo.begin();
}
int angle = 0;
void loop() {
if ( angle == 180 ) {
angle = 0;
}
servo.moveServo(0,angle);
Serial.println("Move to "+angle);
angle++;
delay(200);
}
I2C addresses of ADS1115, MCP23017, PCF8574, PCA9685 breakouts
If you have difficulty initializing the equipment you can use the I2C scanner offered in this tutorial.
Each device has an alternative I2C address. Depending on the manufacturer of the expansion board, the selection of the alternative address will be made via a jumper, a solder bridge or directly by programming. Consult the manufacturer’s technical documentation for how to choose the I2C address.
Equipment | Application | I2C address | Alternative address |
ADS1115 | 4 additional 16-bit A/D inputs | 0x48 | 0x4B |
MCP23017 | 16 additional digital IO, DIP28 box Bus speed: 100kHz, 400kHz, 1.7MHz | 0x20 | 0x27 |
PCF8574 | 8 additional digital IOPWM Bus speed: 100kHz, 400kHz, 1MHz Technical documentation | 0x38 | 0x3F |
PCA9685 | 16 12-bit PWM channels Technical documentation | 0x40 | 0x7F |
Updates
28/10/2020 Publication of the article
- Get Started with HC-SR04, measure distance by ultrasound. Arduino code example
- ESP32, GPIO pins and associated functions. I/O, PWM, RTC, I2C, SPI, ADC, DAC
- ESP32-CAM pinout and equipments. ESP-EYE, AI Thinker, TTGO T-Camera, M5Stack Timer Camera …
- ESP32-CAM. Which model to choose? ESP-EYE, AI Thinker, TTGO T-Camera, M5Stack Timer Camera …
- M5Stack Atomic GPS. ESP32 TinyGPS++ tracker, GPX export on SD card, visualization on Google Maps or VSCode