[Info] I2C Scanner using ESP-IDF APIs

User avatar
kolban
Posts: 1683
Joined: Mon Nov 16, 2015 4:43 pm
Location: Texas, USA

[Info] I2C Scanner using ESP-IDF APIs

Postby kolban » Thu Jan 26, 2017 1:25 am

While studying I2C, I wanted to see what it would take to create an equivalent of the "i2cdetect" tool found on Linux. This is a useful tool that pings each I2C address to see if anyone responds. Fortunately, this wasn't too difficult and I offer the following as an example:

https://github.com/nkolban/esp32-snippe ... cscanner.c

An illustrative output might be:

Code: Select all

     0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f
00:          -- -- -- -- -- -- -- -- -- -- -- -- --
10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
20: 20 -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
40: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
50: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
60: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
70: -- -- -- -- -- -- -- --
Free book on ESP32 available here: https://leanpub.com/kolban-ESP32

spazhead
Posts: 1
Joined: Thu Jan 26, 2017 10:48 am

Re: [Info] I2C Scanner using ESP-IDF APIs

Postby spazhead » Thu Jan 26, 2017 10:50 am

Hey kolban,

Im interested in what you have made, but how would I go about running this on my ESP32? Im currently using Arduino

Cheers,
spazhead

User avatar
kolban
Posts: 1683
Joined: Mon Nov 16, 2015 4:43 pm
Location: Texas, USA

Re: [Info] I2C Scanner using ESP-IDF APIs

Postby kolban » Thu Jan 26, 2017 4:42 pm

Howdy spazhead,
The ESP32 provides a development kit called the "ESP-IDF" (ESP IoT Development Foundation). This is a set of libraries that can be used to write C and C++ applications that, when linked with your own code, produce an executable that can run on the ESP32. There are rich docs available on using the ESP-IDF. Think loosely of the ESP-IDF as the "operating system" services available to your own apps. These services include networking, GPIO, I2C, SPI and all the other goodies we want to access. The ESP-IDF is the "base" on which the majority of all other applications were written. The Arduino project is an "abstraction" layer on top of the ESP-IDF (and in some cases with APIs directly mapped to the lower level hardware). The goal of the Arduino project is to provide an environment for programmers who choose not to use the ESP-IDF platform but instead want to use the "common" functions of Arduino and perhaps re-use existing Arduino scripts.

In order to use the I2C Scanner code mentioned in my previous post, the assumption would be that you have a comprehension of writing ESP-IDF applications. So before going down the route of the I2C Scanner, first learn how to build ESP-IDF apps. The instructions can be found here:

http://esp-idf.readthedocs.io/en/latest/

To do this, you download a toolchain (compiler/linker/etc), then you pick an editor of choice to edit C code (I use Eclipse) and then you run the ESP-IDF build tools using "make". The result is a binary file (the executable) that you flash to the ESP32 using a tool called "esptool" and the result is that YOUR program is running.

But before you go down this route, you should think carefully about your goals. For many folks, working in Arduino will achieve all that is needed and, in fact, Arduino code and ESP-IDF code can be mixed together. The choice of whether to build on the Arduino conventions for APIs or directly on the ESP-IDF APIs is one I can't answer for you. Some is a question of taste ... others are a question of support statements. I believe that functions will be supported earlier and "better" directly from the ESP-IDF platform, however using ESP-IDF may be more "complex" than leveraging the wealth of common Arduino knowledge.
Free book on ESP32 available here: https://leanpub.com/kolban-ESP32

Who is online

Users browsing this forum: No registered users and 29 guests