1

I have 2 I2C devices that uses the same address. One of them is the DS3231 RTC. I use this library for the DS3231. I dont want to mess with the other one cause it is way more complicated then this one.:

#include <DS3231.h>

http://www.rinkydinkelectronics.com/library.php?id=73

Then, there is an object declaration for the real time clock:

DS3231  rtc(SDA, SCL);

I wounder if I can change that to:

DS3231  rtc(A0, A1);

I've seen the library but I haven't understand it yet (duh... I'm so stupid!). But is it possible to use an other pair of pins for I2C communication.

Note that I've already tried to use the soft I2C library but I really want to avoid it because it is just too much. If it is the final solution then so be it.

6
  • I suspect it wouldn't work because of interrupts and stuff. Its really a question against the Wire library, because I suspect that's what it uses underneath. – Code Gorilla Oct 12 '16 at 12:42
  • If you can't get it to work you might want to look at a I2C Multiplexer (ti.com/product/PCA9544A) or in a board (hobbytronics.co.uk/…). From a quick glance it looks like these might do the job and they are relatively cheep (~£5). – Code Gorilla Oct 12 '16 at 12:47
  • 1
    Have you read the big yellow block on the web page you link to? It kind of answers your question quite succinctly. – Majenko Oct 12 '16 at 12:50
  • 1
    What is the other I2C device? – Mikael Patel Oct 12 '16 at 13:02
  • The library above is actually software I2C (from what I can see in the source code). – Mikael Patel Oct 12 '16 at 13:08
2

You can change the address of the GY-521 by pulling the AD0 pin to Vcc. After that the address will be 0x69 instead of 0x68.

2
  • Thanks, I also have to add this line in my code. But it should work fine: MPU6050 mpu(0x69); – Dat Ha Oct 12 '16 at 15:28
  • Great. Good point about changing the code to select the correct address. Would be very helpful for others with the same problem. – Gerben Oct 12 '16 at 17:46
1

Ok, so I've realise that the anwser was somewhat on the page of the library (that I completly ignored). I can change the pins like I did because the library uses a "TWI-/I2C-like protocol".

The library has not been tested in combination with the Wire library and I have no idea if they can share pins. Do not send me any questions about this. If you experience problems with pin-sharing you can move the DS3231/DS3232 SDA and SCL pins to any available pins on your development board. This library will in this case fall back to a software-based, TWI-/I2C-like protocol which will require exclusive access to the pins used.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.