0

Wire.h Schnitzelhunt leads to larger question
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

Wire.h Schnitzelhunt leads to larger question

by adaToad on Sun Aug 25, 2019 7:14 pm

Hiall -

I have recently gotten my hands on a ESP32 board with a mounted SSD1306 OLED (details at bottom of this post)
Although this particular one is not from Adafruit (and I have purchased other Adafruit boards and feathers) my question is not really about this particular board. I selected "ESP 32 - Dev Module" as the board type in the IDE.

In the example sketch I noticed this line:
Code: Select all | TOGGLE FULL SIZE
  Wire.begin(4, 15);


Every Wire.h library I found online has only these signature for the begin function:
Code: Select all | TOGGLE FULL SIZE
    void begin();
    void begin(uint8_t);
    void begin(int);


The Arduino reference documentation equally has only those versions (https://www.arduino.cc/en/Reference/WireBegin)

You will notice that the standard Wire.h library has version of begin with none or one parameter but my example calls begin with a two parameter version.
Scratching my head I tried to find where the Wire.h was that my sketch included which had this unfamiliar two-integer parameter signature.
As part of this I discovered that the Arduino IDE looks for libraries (.h's) in these folders and their respective subfolders, in this order:

1. <sketchbook location from IDE preferences>/libraries/
2. on Mac: /Users/<username>/Library/Arduino15/packages/
3. on Mac: /Applications/Arduino.app/Contents/Java/hardware/arduino/

Note that searching your Mac (finder, spotlight) will NOT search inside locations 2 and 3 (system directory and application package contents respectively) so you will not get any help finding the mystery Wire.h that way.

Instead I embarked on a Schnitzelhunt opening these locations manually and finding a plethora or Wire.h's all a little different. For example:
Code: Select all | TOGGLE FULL SIZE
/Applications/Arduino.app/Contents/Java/hardware/arduino/avr/libraries/Wire/src/Wire.h
/Users/<username>/Library/Arduino15/packages/adafruit/hardware/avr/1.4.13/libraries/Wire/Wire.h
/Users/<username>/Library/Arduino15/packages/adafruit/hardware/samd/1.5.3/libraries/Wire/Wire.h
/Users/<username>/Library/Arduino15/packages/esp32/hardware/esp32/1.0.1/libraries/Wire/src/Wire.h


That last one was the winner, with the sought-for 2 (+ optional third) integer signature:
Code: Select all | TOGGLE FULL SIZE
    bool begin(int sda=-1, int scl=-1, uint32_t frequency=0); // returns true, if successful init of i2c bus


Heuristic: search in the folder that somewhat matches your board architecture name in the search path....

So that brings me to my question....in general is there a quick way to find out which Wire.h is included or (even better) just open that one to see the what the object definitions etc look like ? In most other IDEs, you can just right click on the the filename in the
Code: Select all | TOGGLE FULL SIZE
#include <Wire.h>


And it will open the Wire.h that is actually used (vs various other detritius)
This prevents time intensive and error prone Schnitzelhunting for hidden library files. Also I think beginning users might not be aware of the various library search paths etc. ?

What is the recommendation or best practice here ?

Followup: often libraries are available on github and there, you often also find an example folder (for that particular version of the library) Which can be very helpful to illuminate some function calls that are not documented in the library .h itself. However there is no standard way (that I am aware of) to find the github or other URL that corresponds to a used library from the IDE. I guess you have to hope that the .h author has left a breadcrumb in the comments of the .h file ?














The board is a
HiLetgo ESP32 OLED WiFi Kit ESP-32 0.96 Inch Blue OLED Display WiFi+Bluetooth CP2012 Internet Development Board for Arduino ESP8266 NodeMCU
https://www.amazon.com/gp/product/B07DK ... UTF8&psc=1

adaToad
 
Posts: 7
Joined: Sun Aug 10, 2014 2:46 pm

Re: Wire.h Schnitzelhunt leads to larger question

by adafruit_support_bill on Sun Aug 25, 2019 7:34 pm

The Ardino IDE is still a relatively primitive development environment. If you select the verbose compiler output option in "File->Preferences", it will print the full path of any include files it is using in the output window.

adafruit_support_bill
 
Posts: 74364
Joined: Sat Feb 07, 2009 10:11 am

Re: Wire.h Schnitzelhunt leads to larger question

by adaToad on Mon Aug 26, 2019 1:11 am

Hello adafruit bill -

understood and no problem re Arduino not trying to be a Visual Studio clone :)

Thank you for the verbose output tip, that has the information I was looking for !

Learned something, a good day

Thanks
Robert

adaToad
 
Posts: 7
Joined: Sun Aug 10, 2014 2:46 pm

Please be positive and constructive with your questions and comments.