logo elektroda
logo elektroda
X
logo elektroda

Changing I2C pins in the Arduino Uno using the Wire.h library: are PC5 and PC4 free?

pier 2685 14
ADVERTISEMENT
Treść została przetłumaczona polish » english Zobacz oryginalną wersję tematu
  • #1 19351767
    pier
    Level 24  
    Hi.

    Does the Wire.h library after changing the standard I2C pins to other pins mix anything else on these standard pins?
    Figuratively, let's take for example an Arduino Uno which has standard I2C on the PC5 PC4 pins I change them via Wire.begin(12,13); and I can already use the PC5 PC4 pins without problems?
  • ADVERTISEMENT
  • #2 19351827
    khoam
    Level 42  
    The Arduino Uno is an atmega328, so you can't change the SDA/SCL - they are hardware permanently assigned to the PC4/PC5.
  • #3 19351831
    GanzConrad
    Level 25  
    I don't play with arduino, but I would look at the library first: if it uses hardware I2C (TWI) then it won't work, but if it generates programmatically then there should be no problem.
  • #4 19351836
    khoam
    Level 42  
    The Wire library for the Arduino Uno uses a hardware I2C controller. If for some valid reason you would like to use other pins to support I2C, then software support for I2C remains, e.g. SoftWire ( Link ) or SoftI2CMaster ( Link ).
  • ADVERTISEMENT
  • #5 19351958
    pier
    Level 24  
    A little more detail.
    I am using the Esp8266 not the uno, the uno was given as an example.
    Without any problem I use Wire.begin(); so as to change the I2C pins from standard to others and it works.
    The problem is that under these standard I2C pins in my case I have a gps receiver plugged in.
    And yes, if I use only the gps it is ok and everything works but if I configure I2C with the wire.begin(12,14); command, i.e. on other pins, the gps stops working and I2C works. It's as if even after changing the pins the library still freaks something out on those standard I2C pins.
  • #6 19352303
    khoam
    Level 42  
    pier wrote:
    I use Esp8266 not uno, uno I gave as an example.
    .
    Specifically an example for what? Wire libraries are implemented differently on different platforms. Even the Wire API can vary slightly.
    pier wrote:
    The problem is that under these standard I2C pins in my case I have a gps receiver plugged in.
    And yes, if I use only gps then it's ok and everything works but if I configure I2C with command wire.begin(12,14); that is on other pins then gps stops working and I2C works.
    .
    Show at least the bit of code that does not meet your expectations.
  • #7 19352753
    krzysiek_krm
    Level 40  
    pier wrote:
    And yes, if I use only gps then it is ok and everything works but if I configure I2C with the wire.begin(12,14); command, i.e. on other pins then gps stops working and I2C works. It's as if even after changing the pins the library still freaks something out on those standard I2C pins.
    .
    You write slightly vaguely. However, I think that when you change the I2C pins it is the bus on those "original" pins that stops working. You need to create a second I2C bus (on those previous pins).
  • ADVERTISEMENT
  • #8 19353097
    pier
    Level 24  
    I don't know how to describe it better.
    I fired up a homemade board with esp8266 and oled on pins 14,12, to it I connected a gps receiver which is plugged into the standard pins used by esp for I2C. Don't ask why I2C on different pins than it should be. The library for the gps is tinyGPS++ and SoftwareSerial.

    If I fire the gps itself on pins 4,5 it is ok, everything works. If I run the bus to the oled on pins 14,12 the oled works but the gps does not. Why?
  • #9 19353122
    khoam
    Level 42  
    pier wrote:
    The library for gps is tinyGPS++
    .
    Provide a link to this library that you used.

    Added after 1 [minute]: .

    pier wrote:
    If I fire up the bus to the oled on pins 14,12 then the oled works but the gps no longer.
    .
    And to this display too.
  • #10 19353133
    pier
    Level 24  
    khoam wrote:
    pier wrote:
    The library for gps is tinyGPS++
    .
    Provide a link to this library that you used.

    Added after 1 [minute]: .

    pier wrote:
    If I fire up the bus to the oled on pins 14,12 then the oled works but the gps no longer.
    .
    And to this display too.



    TinyGPS++ .
    And the library for the oled is the one from Adafruit without any quirks. Adafruit_SSD1306.h
  • #11 19353151
    khoam
    Level 42  
    pier wrote:
    And the library for the oled is the one from Adafruit without any quirks.
    .
    Well that's great, and now still write how you specifically call the Adafruit_SSD1306::begin() command i.e. with all four parameters.
  • #12 19353329
    pier
    Level 24  
    khoam wrote:
    pier wrote:
    And the library for the oled is the one from Adafruit without any quirks.
    .
    That's great, now write how you specifically call the Adafruit_SSD1306::begin() command i.e. with all four parameters.
    .

    display.begin(SSD1306_SWITCHCAPVCC, 0x3C);
  • #13 19353356
    khoam
    Level 42  
    The function Adafruit_SSD1306::begin() has the following declaration:
    Code: C / C++
    Log in, to see the code
    If you do not specify the value of the parameter periphBegin in its call, it assumes the value true . You're very reluctant to show even snippets of your program's source code, so I've included below a snippet of code for the Adafruit_SSD1306::begin() function - hiding a clue to solving the problem :) .
    Code: C / C++
    Log in, to see the code
  • ADVERTISEMENT
  • #14 19353741
    pier
    Level 24  
    The code is no secret:

    Code: C / C++
    Log in, to see the code
    .

    I can already see what this is about.
  • #15 19355707
    khoam
    Level 42  
    You should also use the Adafruit_SSD1306 class constructor for I2C in this form:
    Code: C / C++
    Log in, to see the code
    The one you used is "deprecated".

Topic summary

The discussion revolves around the use of the Wire.h library for I2C communication on an Arduino Uno, specifically addressing the implications of changing the default I2C pins (PC4 and PC5) to other pins (e.g., 12 and 14). It is clarified that on the Arduino Uno, the I2C pins are hardware-assigned and cannot be changed, meaning that using Wire.begin(12, 13) does not free up PC4 and PC5 for other uses. Users are advised to consider software alternatives like SoftWire or SoftI2CMaster for I2C on different pins. A follow-up reveals that the original poster is using an ESP8266, where they successfully change I2C pins but encounter issues with a GPS receiver when I2C is configured on non-standard pins. The conversation highlights the need for careful management of I2C buses and the potential conflicts with other devices connected to the standard pins.
Summary generated by the language model.
ADVERTISEMENT