New to PlatformIO and trying to get my bearings. Was wondering if someone might know what the int values the Wire.begin method is looking for for SDA and SCL. I have an OLED 128 x 32 screen and a Node MCU. I have the pins that the OLEd needs on pin D1 and D2 respectively.
I have tried swapping the numbers, I tried using the GPIO pin numbers (4,5) instead of D1 and D2 and neither work.
I have gotten it to work with normal C++ for Arduino, but PlatformIO is closer to my .NET knowledge and when I remove the begin method, it seems to work⌠for now.
Below is a screenshot of the method and intellisense from VSCode of the override method Iâm looking at.
There are 5 overloads (5 different versions) for Wire.begin that you can use.
You can view these overloads by pressing the arrows (in your screenshot).
And you can go directly to itâs declaration / implementation by CTRL+click on Wire.begin. ( â this is the best feature to learn!)
There are begin(int sda, int scl)
Let you specify the pins for SDA and SCL
begin(int sda, int scl, uint8_t address)
Let you speficy the pins for SDA and SCL and the address
begin(void)
Using the default pins (board specific) for SDA and SCL
begin(uint8_t address)
Using the default pins (board specific) for SDA and SCL and let you specify the address as an uint8_t
begin(int address)
Using the default pins (board specific) for SDA and SCL and let you specify the address as an int
In your screenshot simply a â;â is missing after âWire.begin()â.
So âWire.begin();â would be correct if you use the default pins for SDA and SCL for your board.
Thank you for the info. Yes, thankfully I am familiar with C++,Java, C# etc, so Iâm familiar with interfaces and navigating to the methods. Unfortunately, none of the methods have comments, so it doesnât tell you exactly what it is looking for and I am missing something for sure.
I should have provided the screenshot from the video I was following. I would put the code in here, but there is no github for it from the author.
Here is the video as well. https://www.youtube.com/watch?v=jB0TxtKQVzw&t=8s
The author has it set to 13 and 12. As mentioned, I have tried swapping the numbers, to match Node MCU. I tried using the GPIO pin numbers (4,5) instead of 1 and 2 (D port numbers) and neither work. I also tried using D4 and D4 (GPIO port 2 and 14) which also didnât work.
The Author of the video said that his board does not use the default SDA and SCL pins. Thatâs the reason why he specified the GPIOâs for SDA and SCL.
The default GPIOâs on an ESP32 are GPIO 21 (SDA) and GPIO 22 (SCL) - See pins_arduino.h
But due to the ESP32âs GPIO Matrix and Pin Mux these can be mapped to any GPIO. This is the reason for the existence of the begin function which allows you to specify the GPIOâs you want to use for SDA and SCL.
The questions are
Which board do you have exactly?
Whatâs the board = entry in your platformio.ini
How did you wire the display to your board?
Offtopic but to clarify the terminology and to avoid misunderstandings later on:
What you refer to as an âinterfaceâ is a âclassâ.
What you refer to as an âinterface file (.h)â in the other post is a âheader fileâ.
Yes, sorry in C++ they are called headers, sorry about that. Used to the other languages. Not sure what you were referring to me calling interfaces classes. But I must have misspoke.
Based on what you explained above I am using D1 (GPIO 5) and D2 (GPIO 4) and I am now using the overload method without values Wire.begin() so it defaults to what SDA/SCL are for these boards.
What Iâm confused about is when I used the method on my original post, I tried using the overload for SDA/SCL it didnât like it.
Is the number supposed to use the digital number or the GPIO number?
This contradicts your statements in the other thread. There you said that you use Espressif32. The NodeMCU is available with both ESP8266 and ESP32. But now we know that you are using the ESP8266.
So youâre platformio.ini should look something like
Ok got it. Thank you for the help and the pointers .you are correct. I must have copied from the wrong platformio.ini. i had an example VSCode open as well. Sorry about that. I updated the other thread so anyone finding either donât get confused.