[Solved]Sensor MCP9808 over I2C on ESP32 does not work :(

Hello everyone!
This is my first post! Newbi on Mongoose-OS and happy to learn!

  1. My goal is:
    To get the MCP9808 example application (see README.md) to run on my ESP32 using Mongoose-OS.

  2. My actions are: [describe your actions - code, commands, etc]

  • First of all I have verified the hardware setup using Arduino examples, so I know the sensor is connected correctly and that you can get the temp value over I2C.
  • I cloned the test app: mos clone https://github.com/mongoose-os-apps/empty app3
  • I removed all code in the main.c file in the /app3/src folder and added the MCP9808 example application code.
  • Did these changes to my mos.yml file:
    Added the 2 following rows under libs:
  - origin: https://github.com/mongoose-os-libs/mcp9808-i2c
  - origin: https://github.com/mongoose-os-libs/i2c

Added these lines:

config_schema:
  - ["i2c.enable", "b", true, {title: "Enable I2C"}]
  - ["i2c.unit_no", "i", 0, {title: "Which hardware unit ot use, 0 or 1"}]
  - ["i2c.sda_gpio", "i", 2, {title: "GPIO to use for SDA"}]
  - ["i2c.scl_gpio", "i", 0, {title: "GPIO to use for SCL"}]
  • I then built the firmware: mos build --platform esp32
  • Flashed it to the device with out a problem.
  1. The result I see is: [show the result - log, etc]

  2. My expectation & question is: [describe your expectation and your question]
    What am I doing wrong here? I think it would be easy to get this little example up and running? Is it something obvious I have missed?

Thank you in advance for any guidance!

Is the I2C address 0x40?
Add rpc-service-i2c, build, flash and run

mos call I2C.Scan

The I2C configuration (SDA:2, SCL:0) is unusual.

Hi nliviu! Thanks for the reply!

Did what you said and got this:
Screenshot13-12-2019

I removed all I2C configuration in my mos.yml file except :

 - ["i2c.enable", "b", true, {title: "Enable I2C"}]

But I got the same result back from “mos call I2C.Scan”, [ ] .

I am guessing there is an issue with configuration?
What do you think?

Thanks again!
/Andreas

In this case the I2C pins are


Did you move the sensor to these pins?
Is your sensor 3.3V compatible?

BTW, no need to repeat the definition of i2c.enable

 - ["i2c.enable", true]

That helped when I also used pins 21 and 22. So I added them for SDA and SCL and got the following:

So the sensor is not initiated, but I get back 24 from the call! Any idea how to proceed?

Thanks again for all the help!

The address of the sensor is 24 (0x18).

mgos_mcp9808_create(i2c, 24)

It works!
Awesome!
Thanks a lot!