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.
-
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– Code Gorilla2016年10月12日 12:42:28 +00:00Commented Oct 12, 2016 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– Code Gorilla2016年10月12日 12:47:26 +00:00Commented Oct 12, 2016 at 12:47
-
1Have you read the big yellow block on the web page you link to? It kind of answers your question quite succinctly.Majenko– Majenko2016年10月12日 12:50:07 +00:00Commented Oct 12, 2016 at 12:50
-
1What is the other I2C device?Mikael Patel– Mikael Patel2016年10月12日 13:02:31 +00:00Commented Oct 12, 2016 at 13:02
-
The library above is actually software I2C (from what I can see in the source code).Mikael Patel– Mikael Patel2016年10月12日 13:08:17 +00:00Commented Oct 12, 2016 at 13:08
2 Answers 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.
-
Thanks, I also have to add this line in my code. But it should work fine: MPU6050 mpu(0x69);Dat Ha– Dat Ha2016年10月12日 15:28:50 +00:00Commented Oct 12, 2016 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– Gerben2016年10月12日 17:46:10 +00:00Commented Oct 12, 2016 at 17:46
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.
Explore related questions
See similar questions with these tags.