Tell me what you want, What you really, really want.

Moderator: Mmiscool

User avatar
By trackerj
#51876 Hello,

I want to start writing some more ESPBasic I2C related drivers and examples for widely used I2C compatible IC's, like ADC's, DAC's, Sensors, port expanders, etc but I really like to use other GPIO pins for the SDA/SCL lines. For this feature working we need a way to be able to define at the beginning of the program the allocated I2C pins like it is in Arduino IDE or even in LUA.

A simple way is to declare the desired SDA and SCL pins definitions to the start of the program:

I know that in ESPBasic we have hardcoded values for SDA and SCL as below:
Code: Select all Wire.begin(0, 2);


If this can be changed to
Code: Select all Wire.begin(SDA, SCL);
and then in the program you can define the SDA and SCL pins as you want. Problem solved.

I think this is a quite simple feature to add and will made many people to adopt ESPBasic for their I2C related projects. GPIO0/2 are not exactly the most used pins for I2C out in the wild and might vary a lot based on projects needs.

Thank you,
TJ.
User avatar
By trackerj
#53857 Any news on this one? I know that they are also other people interested in this subject.

It's a real pitty to struggle to recompile the entire ESPBasic just to change the I2C pins to some more usual used ones. I really hope is a simple way to be able to change SDA/SCL to GPIO4/5 or any other pair.

Mmiscool, can you please help us with this one? Even a separate release with GPIO4/5 will be great to have until dynamic allocation will be available.

Thank you.
User avatar
By forlotto
#53861 hrmmm seems like a good idea to me I don't know maybe mmiscool is a bit busy at the moment or has no interest in dynamic I2C or maybe there is already a way to set dynamic.

Could you point me to the file and line number on git hub where this needs to be changed to make it work I am interested in seeing the code and how it plays out I remember seeing it when I was looking for bugs a few weeks ago but ... Best just to have a direct value and place to look saves on time.

Thanks TJ for pointing this out no reason to keep the hardcoded GPIO's for I2C for 3.x branch as ESP01 is no longer supported by 3.x so very valid point.

Maybe mmiscool has his reasons if so I am curious as to what they are.

If so it could still be made possible by simply doing something like this:

if user specifies sda and scl during setup then use users pins else use default pins for basic.

This would limit support issues if this is the reasoning for not doing this.

Really don't know their could be a number of reasons. If I am understanding you right GPIO 4 and 5 are the standard for everything else and you are worried about some modified boards that use gpio 0 for autoreset etc...

mmiscool is the guy for this one though I really wish I could help more.
Last edited by forlotto on Fri Aug 26, 2016 12:08 pm, edited 1 time in total.
User avatar
By trackerj
#53863 The line where I2C is hardcoded is in:

Code: Select allhttps://github.com/esp8266/Basic/blob/NewWebSockets/ESP8266Basic/ESP8266Basic.ino


Line 1119 :
Code: Select all Wire.begin(0, 2);


I really think a more general I2C used GPIO4/5 pair might be better.

Dynamic allocation will be even better.