Skip to main content

Enginursday: Multiple I2C Ports on ESP32

For as long as I've been at SparkFun (longer actually, this project started back at school), I've been working on a fiber optic light suit. The idea originally came about because I was frustrated with the lack of controllability of EL wire. It's only monochrome and, as far as I can tell, most inverters don't have the required duty cycle for PWM. I wanted to have glowing wires all over me but didn't know where to look.

A friend who was also interested in the idea bought me a roll of some thin fiber optic from a supplier in Texas, and I was off to the races, hot gluing bundles of fiber optic and simple 5mm LEDs into Starbucks straws (my part-time college job) and putting them all over my arms.

Version 2 of the Light Suit at Pretty Lights show in 2017
Version two of the Light Suit at a Pretty Lights show in 2017

I've come a very long way since then. Four versions later, I've moved from "dumb" LEDs in straws and bulky PWM controllers running on a relatively slow Arduino Pro Mega that I had left over from a digital electronics class, to shiny, custom PCBs with SMD APA102s, 3D-printed mounts, an ESP32 Thing Plus and even I2C based finger-bend sensors that eventually became a SparkFun product. In versions three and four, I made the move to add legs and a torso to this glowing suit, adding a whole host of new problems. After version three had issues staying plugged in, I took a step back and collected my thoughts before starting again.

I finally gathered the motivation and time to pick this project back up and figured I'd tackle my problems getting my six I2C gesture sensors to pull some readings, four of which are the ADS1015, ADC-to-I2C-based Qwiic Flex Glove Controller, and read how bent all of my fingers (excluding my thumbs) are. The other two sensors in the feet are also ADS1015-based boards that attach to force sensors; this enables me to see how my weight is balanced.

Weight Sensing Insole
Weight-sensing insole

The ADS1015 has a hardware configurable address; tie the ADR pin to GND, 3V3, SDA, or SCL to select one of four available addresses. If you're a math genius you'll realize we have more sensors than addresses. That's a problem our trusty ESP32 can solve. We'll simply need to create an I2C bus for each side - this way we can have each side be a mirror image of the other in code. To do this, we first need to include a few libraries and create our I2C buses.

#include <SparkFun_ADS1015_Arduino_Library.h>
#include <Wire.h>

TwoWire leftBus = TwoWire(0);
TwoWire rightBus = TwoWire(1);

We'll then say which addresses we want our sensors to be on as well as create the objects for our sensors themselves, since we have two buses, we'll only need to use 3 addresses.

/***Addresses for Different Parts of Limb***/
#define PINKY 0x48
#define INDEX 0x4A
#define FOOT 0x4B

/***ADS1015 Objects***/
ADS1015 leftPinky;
ADS1015 leftIndex;
ADS1015 leftFoot;
ADS1015 rightPinky;
ADS1015 rightIndex;
ADS1015 rightFoot;

In our setup loop, we initialize some Serial output to see what's going on, we then initialize our left and right buses on two different sets of pins. I also use 100 kHz as I've got some pretty long wires, which hinders I2C communication. We then add our gesture sensors to their respective buses using their respective addresses. No need for an I2C Mux today! Note that I also change the gain of my sensors; this is specific to my project and sensors, so you won't need to do this for your accelerometer or other I2C device.

void setup() {
  /***Debug Output***/

  /***Initialize I2C Devices***/
  leftBus.begin(23, 22, 100000);
  rightBus.begin(16, 17, 100000);
  leftPinky.begin(PINKY, leftBus);
  leftIndex.begin(INDEX, leftBus);
  leftFoot.begin(FOOT, leftBus);
  rightPinky.begin(PINKY, rightBus);
  rightIndex.begin(INDEX, rightBus);
  rightFoot.begin(FOOT, rightBus);

  /***Change Gain***/

My main loop() is as simple as printing the values out over Serial!

void loop() {
    for (int channel = 0; channel < 2; channel++)
        Serial.print(": ");
        Serial.print(": ");
        Serial.print(": ");
        Serial.print(": ");
    for (int channel = 0; channel < 4; channel ++)
        Serial.print(": ");
        Serial.print(": ");

And here's the output below, notice how all of the feet values are resting close to 0, as the circuit the board they are on doesn't include the op-amp circuit.

Serial Output from 4 Limbs
Serial output from all four limbs

comments | comment feed

from SparkFun: Commerce Blog


Popular posts from this blog

TE Connectivity Announced Ultra Small Spring Fingers

TE Connectivity (TE)’snew ultra small spring fingers have one of the smallest footprints in the market to save valuable PCB space, allowing for use in a broad range of applications with space constraints across various industries.TE’s ultra small spring fingerscan save valuable PCB space with one of the smallest footprints in the market. Closed-loop contact design ensures reliable connection to the PCB, better normal force and higher current capacity (1.5A). Robust side wall minimizes over- compression. Special anti-lifting design can improve assembly e ciency by locking the tip of the contact within the sidewall of the spring  nger, which helps prevent the contact from getting caught on an operator’s glove during assembly. Pick-and-place area supports auto-assembly processes. It also offered in different heights and styles.As an authorized distributor for TE Connectivity, Heilind Asia provides TE’s products and also value added services. Heilind Asia supports both original equipment …

Hanwha TechwinCollects Two NPI Awards for Its Cutting-Edge Modular Mounter and Screen Printer at APEX

Hanwha Techwin Automation Americas, formerly Samsung C&T Automation, today announced that it has received two 2019 NPI Awards in the categories of Component Placement – High-Speed for its HM520 Cutting-Edge Modular Mounter and Screen/Stencil Printing for the ESE US-2000XF. The awards were presented to the company during a Tuesday, Jan. 29, 2019 ceremony that took place at the San Diego Convention Center during the IPC APEX EXPO.With the HM520 Modular Mounter, actual productivity is highest among machines of the same class and is optimized to high quality production. The system configures a flexible production line by applying a modular head and various production modes. The HM520 realizes unmanned, non-stop, and zero-defect production using the Smart Factory S/W Solution.The high performance HM520 offers a compact foot print, auto-calibrating maintenance free feeders, and modular heads. The HS(High Speed) Head offers a 20 Spindle x 2 Gantry, 80,000 CPH, ±25 μm @ Cpk ≥ 1.0, 0201 ~ …

Siemens partners with TIES, a Chinese R&D Center to develop new technologies for electric vehicle batteries

Advanced Battery Technology Innovation Center (ABTIC) is initiated jointly by Tianmu Lake Institute of Advanced Energy Storage and Siemens to develop advanced battery technologies and help bring them to volume productionABTIC aims to develop and provide digital solutions for production chains and innovation chains on next generation batteriesSiemens Digital Industries Software has partnered with Tianmu Lake Institute of Advanced Energy Storage Technologies (TIES), a major Chinese energy storage research and development center, to build an Advanced Battery Technology Innovation Center. The Innovation Center, to be located at the 500 million-yuan, 51,000 square meter TIES facility in Liyang, China, will be dedicated to transforming and upgrading the advanced battery industry, including nurturing advanced battery technology research and development, and the development and introduction of high-end talents in this growing area.The Innovation Center will provide the advanced battery innova…