Skip to content

Add setPins to Wire instead of overloading begin() in a breaking manner #3779

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
ladyada opened this issue Mar 2, 2020 · 24 comments
Closed
Assignees

Comments

@ladyada
Copy link
Contributor

ladyada commented Mar 2, 2020

hi folks - we get about 1 request every week or so for us to change our libraries so people can pass I2C pin numbers into Wire.begin()

We can't merge these PRs because official Arduino code style has Wire.begin() in sensor/device begin():
https://github.com/arduino-libraries/Arduino_LSM6DS3/blob/master/src/LSM6DS3.cpp#L76

please add a Wire.setPins() or similar function that can be called at the beginning of the sketch, instead of breaking compatibility by changing the prototype of Wire.begin() - it will make both library developers and users much happier!

see:

@stickbreaker stickbreaker self-assigned this Mar 2, 2020
@stickbreaker
Copy link
Contributor

@ladyada A simple answer for this problem, call Wire.begin(sdapin,sclpin,busspeed) in setup() and your libraries use the standard Wie.begin() in the library. (I assume your libraries execute a Wire.begin() as part of the library initialization code, multiple invocations of Wire.begin() are supported.) The Wire() code is designed to reuse the previously assigned pins and bus speed. Since the pin allocation is necessary for ESP32, it should be set. And Setup() is the logical place.

Chuck.

@ladyada
Copy link
Contributor Author

ladyada commented Mar 3, 2020

@stickbreaker hi, thanks for the response. that is the exact thing we will not do because official Arduino code style has Wire.begin() in sensor/device begin() :)

https://www.arduino.cc/en/Reference/WireBegin

ESP changed the Wire prototype so that it is different from every other Arduino platform. We are asking that this not be done and an alternative way to set pins is defined

@stickbreaker
Copy link
Contributor

@ladyada So, you want code like this?

void setup(){
#ifdef ARDUINO_ARCH_ESP32
   Wire.setpins(sda,scl);
#endif
   Wire.begin();
}

Chuck.

@ladyada
Copy link
Contributor Author

ladyada commented Mar 4, 2020

yeah that would best! also, capitalize P in setPins() to match arduino style :)

@stickbreaker
Copy link
Contributor

If you can use the #ifdef this example is already supported.

void setup(){
#ifdef ARDUINO_ARCH_ESP32
   Wire.begin(sda,scl);
#endif
   Wire.begin(); //redundant, but won't cause any problems.
}

Chuck.

@ladyada
Copy link
Contributor Author

ladyada commented Mar 4, 2020

hi, not if the code is inside existing written libraries. they need to be able to call setPins before the sensor begin

APDS9960 sensor = APDS9960();

void setup() {
   Wire.setPins(4, 5);
   sensor.begin(); // calls Wire.begin
}

@Andrewiski
Copy link

@ladyada Is this why the OLED feather displays garbage on ESP32 but same code works on a Wiced Feather?

@ladyada
Copy link
Contributor Author

ladyada commented Mar 4, 2020

@Andrewiski probably not - if you need tech support please post in the adafruit forums :)

@ladyada
Copy link
Contributor Author

ladyada commented Mar 10, 2020

@stickbreaker hi hi, checkin' in - do you have any other questions on this issue? :)

@stale
Copy link

stale bot commented May 9, 2020

[STALE_SET] This issue has been automatically marked as stale because it has not had recent activity. It will be closed in 14 days if no further activity occurs. Thank you for your contributions.

@stale stale bot added the Status: Stale Issue is stale stage (outdated/stuck) label May 9, 2020
@ladyada
Copy link
Contributor Author

ladyada commented May 9, 2020

@me-no-dev can y'all assign someone else who is interested in this issue? @stickbreaker has not replied in ~2 months.

@stale
Copy link

stale bot commented May 9, 2020

[STALE_CLR] This issue has been removed from the stale queue. Please ensure activity to keep it openin the future.

@stale
Copy link

stale bot commented Jul 8, 2020

[STALE_SET] This issue has been automatically marked as stale because it has not had recent activity. It will be closed in 14 days if no further activity occurs. Thank you for your contributions.

@stale stale bot added the Status: Stale Issue is stale stage (outdated/stuck) label Jul 8, 2020
@ladyada
Copy link
Contributor Author

ladyada commented Jul 14, 2020

@me-no-dev can y'all assign someone else who is interested in this issue? @stickbreaker has not replied in ~4 months

@stale
Copy link

stale bot commented Jul 14, 2020

[STALE_CLR] This issue has been removed from the stale queue. Please ensure activity to keep it openin the future.

@stale stale bot removed the Status: Stale Issue is stale stage (outdated/stuck) label Jul 14, 2020
@me-no-dev
Copy link
Member

@ladyada yup. Let me see what I can do. I have no heard from Chuck if a few as well.
What I gather is that you just need a method added that would preset the pins used for begin(). Am I correct?

@ladyada
Copy link
Contributor Author

ladyada commented Jul 16, 2020

yes! right now we get weekly requests to have special code for ESP since they want to run Wire.begin(4, 5) or whatever, in the sensor begin() function. Instead, if we had a function that would Wire.setPins(), then when Wire.begin() is called later it would use the pins set by setPins earliler. If setPins is never called, Wire.begin() would use the board support package default

@me-no-dev
Copy link
Member

cool! Will do!

@ladyada
Copy link
Contributor Author

ladyada commented Jul 17, 2020

thankyouthankyouthankyou it will be incredibly helpful and let many more ESP customers use our libraries!

@me-no-dev
Copy link
Member

done :)

@ladyada
Copy link
Contributor Author

ladyada commented Jul 18, 2020

yaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaay this is awesome! thank you!

@me-no-dev
Copy link
Member

@ladyada please do email me if you see that there is no response. Things do get buried sometimes for various reasons :)

@githufsb
Copy link

Wow! I was just looking at how to use 9960 on a wemos esp32 board! Thank you @ladyada and @me-no-dev! It's so great to start a dev project and then see github comments from days ago that may solve your problem!

@kamikaze2112
Copy link

For anyone here pulling their hair out like me wondering why this doesn't work with their ESP32-S3-devkit1 and the Adafruit SSD1306 library, make sure you've got the right I2C address for your display. The example code in the Adafruit SSD1306 library states that the 128x64 I2C address is 0x3D. The particular 128x64 displays that I have are 0x3C by default.

Image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants