I2C bus access on esp32

  1. My goal is:
    Access a device on the I2C bus of an ESP32 device.

  2. My actions are:
    I have reduced the problem down to using the ‘mos call I2C.Scan’ command to find the address of an ADS115 device on the I2C bus., This returns [].

My mos.yml is

author: mongoose-os
description: A Mongoose OS app skeleton
version: 1.0

libs_version: ${mos.version}
modules_version: ${mos.version}
mongoose_os_version: ${mos.version}

  - c

  - src

  - fs

 - ["debug.level", 2]
 - ["i2c.enable",   "b", true,    {title: "Enable I2C"}]
 - ["i2c.debug",    "b", true,    {title: "Debug I2C"}]
 - ["i2c.freq",     "i", 100000,  {title: "I2C bus speed (Hz)"}]
 - ["i2c.unit_no",  "i", 0,       {title: "Which hardware unit to use, 0 or 1"}]
 - ["i2c.sda_gpio", "i", 22,      {title: "GPIO to use for SDA"}]
 - ["i2c.scl_gpio", "i", 21,      {title: "GPIO to use for SCL"}]

  - origin: https://github.com/mongoose-os-libs/boards
  - origin: https://github.com/mongoose-os-libs/ca-bundle
  - origin: https://github.com/mongoose-os-libs/rpc-service-config
  - origin: https://github.com/mongoose-os-libs/rpc-service-fs
  - origin: https://github.com/mongoose-os-libs/rpc-uart
  - origin: https://github.com/mongoose-os-libs/rpc-service-i2c.git

manifest_version: 2017-09-29

My main.c code just flashes an LED to show it’s running.

#include "mgos.h"

#define LED_PIN 2

static void timer_cb(void *arg) {
#ifdef LED_PIN
  (void) arg;

enum mgos_app_init_result mgos_app_init(void) {
#ifdef LED_PIN
  mgos_gpio_setup_output(LED_PIN, 0);
  mgos_set_timer(1000 /* ms */, MGOS_TIMER_REPEAT, timer_cb, NULL);
  1. The result I see is:
mos call I2C.Scan
Using port /dev/ttyUSB1
  1. My expectation & question is:
    To be able to access an I2C device. I have hardware that had old code (compiled about 6 months ago) on it and it was able to access the I2C bus until I loaded newly compiled code (shown above).

I guess I’m doing something stupid but I can’t see what. Any help would be appreciated.




If you happen to use the latest release, pin to a stable one; the developers are working on a new IDF version right now. mos update release


The I2C library have been fixed in latest.

BTW, there is no need to redefine the settings. Use

 - ["i2c.enable", true]

and so on.
i2c.debug set to true will issue more messages only at debug.level=3.


Thanks, I pulled down the latest mos and the I2C is now working.