Problem with Multiple I2C devices on Due
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

Problem with Multiple I2C devices on Due

by nataku on Mon Feb 17, 2014 10:10 pm

Hi,
I am having problem connecting 2 I2C devices on the Due. All shields and bidirectional level shifter from Adafruit.
The problem is like this :
I have RGBLCDShield and RTC DS1307 Shield that I want to connect into the Due.
I can only get the 2 devices communicate to the Due correctly if I connect the RTC Shield to SCL 21 and SDA 21 and the RGB LCD Shield to SCL1 and SDA1.
If I try connecting both shields on SCL21 and SDA21, then only the RTC Shield works but the LCD Shield does not work.
If I try connecting both shields on SCL1 and SDA1, then only the LCD works but the RTC Shield does not work.
If I swap the SCL21 and SDA21 so they are connected to the RGB LCD Shield, and SCL1 and SDA1 to the RTC Shield, then none of them work.

I tried them with and without pull up resistors (10K). Same results.

I am using bidirectional level shifter to go from the 5V side logic from the shields to the 3.3V side logic of the SCL and SDA inputs in the Due.

Does anyone have any clue on what to check?

nataku
 
Posts: 36
Joined: Sun Feb 17, 2013 12:09 am

Re: Problem with Multiple I2C devices on Due

by adafruit_support_mike on Tue Feb 18, 2014 12:47 am

The symptoms are wierd enough that my first hunch is to look at the wiring. Could you post a photo of how you have things connected please?
When you void a product warranty, you give up your right to sue the manufacturer if something goes wrong and accept full responsibility for whatever happens next. And then you truly own the product.

adafruit_support_mike
 
Posts: 17596
Joined: Thu Feb 11, 2010 2:51 pm

Re: Problem with Multiple I2C devices on Due

by nataku on Wed Feb 19, 2014 12:55 am

I am attaching the fritzing file. I is pretty close to what I have. You may have to rename the extension back to .fzz
Attachments
i2c multiple device on DUE.txt
rename extension of this file to fzz
(5.07 KiB) Downloaded 5 times

nataku
 
Posts: 36
Joined: Sun Feb 17, 2013 12:09 am

Re: Problem with Multiple I2C devices on Due

by nataku on Wed Feb 19, 2014 12:57 am

The devices I used in the fritzing file I sent you are not exactly what I have since Fritzing does not have those equipment library model. but I think you will be able to understand my wiring. Imagine the LCD shield there is Adafruit RGBLCD and the 2 wires are the SDA and SCL inputs.
The LCD are powered using 5V. and the RTC clock also are powered using 5V from the Due. I did not show this.

Thanks.

nataku
 
Posts: 36
Joined: Sun Feb 17, 2013 12:09 am

Re: Problem with Multiple I2C devices on Due

by adafruit_support_mike on Wed Feb 19, 2014 1:15 am

I'm looking for non-schematic information about the actual wiring and the connections. A schematic shows what you think is there, a photo of the hardware shows what's really there.
When you void a product warranty, you give up your right to sue the manufacturer if something goes wrong and accept full responsibility for whatever happens next. And then you truly own the product.

adafruit_support_mike
 
Posts: 17596
Joined: Thu Feb 11, 2010 2:51 pm

Re: Problem with Multiple I2C devices on Due

by nataku on Thu Feb 20, 2014 12:09 am

How do you even post a jpg here?
The jpg file is not accepted as a valid file.
I just rename the jpg and upload need. You need to rename it back to jpg.
Attachments
photo.txt
(740.08 KiB) Downloaded 18 times

nataku
 
Posts: 36
Joined: Sun Feb 17, 2013 12:09 am

Re: Problem with Multiple I2C devices on Due

by adafruit_support_mike on Sat Feb 22, 2014 12:04 am

Thank you.

Given that setup, there are a couple of ways to share the I2C bus. You can make A1 the SCK input and connect both the RTC and LCD SCK lines to B1, and do the same with SDA, A2, and B2. You can also leave the RTC and LCD jumpers where they are and use jumpers to copy the SCK/SDA signals from A1/A2 to A3/A4.

Which version did you do when testing the connections?
When you void a product warranty, you give up your right to sue the manufacturer if something goes wrong and accept full responsibility for whatever happens next. And then you truly own the product.

adafruit_support_mike
 
Posts: 17596
Joined: Thu Feb 11, 2010 2:51 pm

Re: Problem with Multiple I2C devices on Due

by nataku on Sat Feb 22, 2014 12:19 am

1.5.5,
I'll give it a try and I'll let you know.

nataku
 
Posts: 36
Joined: Sun Feb 17, 2013 12:09 am

Re: Problem with Multiple I2C devices on Due

by nataku on Wed Feb 11, 2015 12:42 am

Hello,
I just post this on the Arduino forum and I think definitely has to post here too since this conclude the problem I was having and how I solved it. By the way this was tested using Arduino IDE 1.6.0 released yesterday or this morning.

Hello,
I just want to share that I am able to share SCL1,SDA1 pin between RTC clock using Adafruit RTClib.h library with their RGBLCDShield.
I did have to do modification as everyone mention in the other posts. What I think is lacking is for someone to actually clearly setup an entire code for someone to see.
I am a novice so when reading "just change Wire to Wire1" and go to this folder and include this and that. It is very difficult, anyway I am able to put together some instruction here with hope it may be useful for someone.

Originally the RTC clock using RTClib.h by default can only be used on SDA(20) and SCL (21). However, I want to be able to share this with SDA1 and SCL1 pin on the Due. What is the point of having i2C if each device use their own pins right?

Anyway, because the built-in SDA1 and SCL1 have no pull up resistors, these will be the one to use according to the posts I read so far. Luckily the RTC clock and RGBLCDShield already has built in pull up resistors.

Step 1.
I copy RTClib folder in my Arduino library folder ( I am using MAC). and copy it in the same library folder with the name RTClib1

Step 2.
Rename the 2 files under that RTClib1 folder so you would have these 2 names RTClib1.cpp and RTClib1.h

Step 3.
Edit the RTClib1.cpp using text editor and here is what it looks like for me
#include <Wire.h>
#include <avr/pgmspace.h>
#include "RTClib.h"
#define DS1307_ADDRESS 0x68
#define SECONDS_PER_DAY 86400L
...

Step 4.
Change the 3rd and insert a new 4th line to look like :
#include <Wire.h> // keep this don't delete
#include <avr/pgmspace.h> // no change on this line
#include <RTClib1.h> // this is to match the name of the library and use <> instead of ""
extern TwoWire Wire1; // insert this line is the modification to include Wire1
....

Step 5.
Now still in the RTClib1.cpp use search and replace feature for the word Wire to Wire1. Make sure you do not change the "extern TwoWire" you add above.

There is no change needed in RTClib.h other than renaming that file to RTClib1.h

Step6.
Okay, now to the .ino file or the Arduino IDE code that you use that you will download. Here are what mine look like :
#include <Wire.h>
#include <Adafruit_MCP23017.h>
#include <Adafruit_RGBLCDShield.h>
Adafruit_RGBLCDShield lcd = Adafruit_RGBLCDShield();
#define WHITE 0x7
#include "RTClib1.h" // a modified version of RTClib.h from Adafruit to force the Due to use Wire1 instead of Wire
RTC_DS1307 rtc; //this stay the same as instructed in the tutorial
...
the rests of the code here can be kept similar to their tutorials or whatever you want to do with it.
Notice that the only place that you want to make sure is when you include the library RTClib1, make sure
you include RCTlib1.h not RTClib.h
(by the way I am not sure why sometime they use "" and sometime <> when including libraries)


Hope this helps you. I will try to attached my code and the RTClib1.cpp that I modified. The original RTClib.h can be found from Adafruit link and this did not change other than renaming the file.

The 2 ino files are for comparison purposes. One is for Uno the other one is for the Due. Same function.

Now you just have to remember to use RTClib1.h if you want to use it on SCA1,SDL1
and use RCTlib.h if you want to use SCA0,SDL0.

Tada..... I am a happy camper. Thanks you all inspired me to keep learning and sharing.
Attachments
Due_all_in_one_sensors.ino.txt
(1.11 KiB) Downloaded 4 times
Uno_all_in_one_sensors.ino.txt
(1.02 KiB) Downloaded 3 times
RTClib1.cpp
(6.76 KiB) Downloaded 3 times

nataku
 
Posts: 36
Joined: Sun Feb 17, 2013 12:09 am

Re: Problem with Multiple I2C devices on Due

by adafruit_support_mike on Fri Feb 13, 2015 1:28 am

Thanks for posting the follow-up. I'm sure it will help others in the future!

adafruit_support_mike
 
Posts: 17596
Joined: Thu Feb 11, 2010 2:51 pm

Please be positive and constructive with your questions and comments.