I2C and 1-wire on the same bus ?

Hello...

I wil create a clock with the arduino uno board and the 2.4 tft lcd touch screen.
When i connect thes two there are only 2 pins availeble --- scl and sda.

I also want to connect a pcf8583(real time clock) and a DHT22(temp an humidity).

My question is... can i use the same pins for these two busses without a conflict in the i2c library and the 1-wire library.

Is there someone with experience with this ?

P. Jochems

As long as you don't try to do both at the same time, and the arduino is the master controlling all communications, I can't see why you couldn't.

the i2c devices should ignore any message from the master device which doesn't start with their address.

You would have to experiment to see what the DHT22 does with data not intended for it. The DHT22 protocol is similar but not the same as the dallas 1-wire scheme, to the best of my knowledge.

The Wire library controls the SDA and SCL pin, I don't know if you can override that.
If one of the I2C is kept high, the other one can be use for other thing. But I forget if that was SDA or SCL :-[

You can try that if you are an advanced electronics and software tweaker. If you are not, there are other ways to get more pins.
The analog pins of the Arduino Uno are also digital pins. You can use them for the display or the DHT22.
There is a software I2C library ( "SoftwareWire" inside the Arduion IDE in the Library Manager) to use I2C on other pins.

Perhaps a dataline to the display can be shared with other things.

Could you give a link to that touch screen ? why is using so many pins ?
I assume pin 2,3,12,A4,A5 are still not used. If you use I2C, then 2,3,12 are still available ?

Using : UNO - 2.4inc TFT touchscreem - PCF8583 - DHT22 :

I have connect everything yet but i have now an other problem...

When i upload the code for my 2.4 tft touch...display everything works fine.
When i on the same UNO board the code upload for onley reading my i2c time (pcf8583) also this works fine !

But when i try to using them together there is something going rong with the display.

Maby the library's using the same timer ore something ?

Is there someone with experience with this ?

Could you give links to items that you use.
For example this is a link : http://www.adafruit.com/product/2478
And this is a link : http://www.mikroe.com/click/rtc/

How is the display connected ?

Could you show your sketch between code tags ?
Number 7 on this page is about code tages : http://forum.arduino.cc/index.php/topic,148850.0.html

The Wire library for I2C does not use other things. Perhaps it might be a power problem ? Do you power the Arduino with the usb cable ?

Hello !

My items are : (sory for the bad englisch...i am dutch)

display =

http://produk-inovatif.com/shop/arduino/2-4-tft-lcd-shield-touch-panel-display-with-tf-wtf-reader-for-arduino-uno/

pcf = selfmade pcb and its using onley 5v, gnd,scl and sda from the uno board and taht part is testen and works fine. (schematic..see attach.

and my code is :

// pcf8583

#include <Wire.h>
#include <stdio.h>
#include <PCF8583.h>
/*****************************************************************************

  • read/write serial interface to PCF8583 RTC via I2C interface
  • Arduino analog input 5 - I2C SCL (PCF8583 pin 6)
  • Arduino analog input 4 - I2C SDA (PCF8583 pin 5)
  • You can set the type by sending it YYMMddhhmmss;
  • the semicolon on the end tells it you're done...

******************************************************************************/

// display

#include <Adafruit_GFX.h> // Core graphics library
#include <SWTFT.h> // Hardware-specific library
#include <TouchScreen.h>

#define YP A1 // must be an analog pin, use "An" notation!
#define XM A2 // must be an analog pin, use "An" notation!
#define YM 7 // can be a digital pin
#define XP 6 // can be a digital pin

#define TS_MINX 100//150
#define TS_MINY 100//120
#define TS_MAXX 920
#define TS_MAXY 940

// For better pressure precision, we need to know the resistance
// between X+ and X- Use any multimeter to read it
// For the one we're using, its 300 ohms across the X plate
TouchScreen ts = TouchScreen(XP, YP, XM, YM, 300);

int toetswaarde=20;
int temptoetswaarde=0;
int waardebit=0;
int tijd=0;

// Assign human-readable names to some common 16-bit color values:
#define BLACK 0x0000
#define BLUE 0x001F
#define RED 0xF800
#define GREEN 0x07E0
#define CYAN 0x07FF
#define MAGENTA 0xF81F
#define YELLOW 0xFFE0
#define WHITE 0xFFFF

SWTFT tft;

// pcf8583

int correct_address = 0;
PCF8583 p (0xA0);

void setup(void) {
Serial.begin(9600);
tft.reset();
uint16_t identifier = tft.readID();
tft.begin(identifier);
delay(100);
toetsveld();
}

#define MINPRESSURE 10
#define MAXPRESSURE 1000

void loop(){

// pcf8583

if(Serial.available() > 0){
p.year= (byte) ((Serial.read() - 48) *10 + (Serial.read() - 48)) + 2000;
p.month = (byte) ((Serial.read() - 48) *10 + (Serial.read() - 48));
p.day = (byte) ((Serial.read() - 48) *10 + (Serial.read() - 48));
p.hour = (byte) ((Serial.read() - 48) *10 + (Serial.read() - 48));
p.minute = (byte) ((Serial.read() - 48) *10 + (Serial.read() - 48));
p.second = (byte) ((Serial.read() - 48) * 10 + (Serial.read() - 48)); // Use of (byte) type casting and ascii math to achieve result.

if(Serial.read() == ';'){
Serial.println("setting date");
p.set_time();
}
}

p.get_time();
char time[50];
sprintf(time, "%02d/%02d/%02d %02d:%02d:%02d",
p.year, p.month, p.day, p.hour, p.minute, p.second);
Serial.println(time);

// 2.4 inch display

TSPoint p = ts.getPoint();

pinMode(XM, OUTPUT);
pinMode(YP, OUTPUT);

int temp1=0;

if (p.z > MINPRESSURE && p.z < MAXPRESSURE) {
if(p.x<350&&p.y<280){toetswaarde=1;}
if(p.x>350&&p.x<650&&p.y<280){toetswaarde=2;}
if(p.x>650&&p.x<950&&p.y<280){toetswaarde=3;}

if(p.x<350&&p.y>280&&p.y<480){toetswaarde=4;}
if(p.x>350&&p.x<650&&p.y>280&&p.y<480){toetswaarde=5;}
if(p.x>650&&p.x<950&&p.y>280&&p.y<480){toetswaarde=6;}

if(p.x<350&&p.y>480&&p.y<680){toetswaarde=7;}
if(p.x>350&&p.x<650&&p.y>480&&p.y<680){toetswaarde=8;}
if(p.x>650&&p.x<950&&p.y>480&&p.y<680){toetswaarde=9;}

if(p.x<350&&p.y>680&&p.y<880){Serial.println("*");}
if(p.x>350&&p.x<650&&p.y>680&&p.y<880){toetswaarde=0;}
if(p.x>650&&p.x<950&&p.y>680&&p.y<880){toetswaarde=11;}

if (toetswaarde<temptoetswaarde||toetswaarde>temptoetswaarde){waardebit=1;temp1=temptoetswaarde;temptoetswaarde=toetswaarde;}
}

++tijd;
if (tijd>2000){
byte a=32;
if (toetswaarde>9){a=20;}
tft.setTextColor(BLACK); tft.setTextSize(4);
tft.setCursor(a, 263);tft.println(toetswaarde);
temptoetswaarde=20;
a=32;}

if(waardebit==1){
tijd=0;
byte a=32;
if (temp1>9){a=20;}
tft.setTextColor(BLACK); tft.setTextSize(4);
tft.setCursor(a, 263);tft.println(temp1);
a=32;
if(toetswaarde>9){a=20;}
tft.setTextColor(YELLOW); tft.setTextSize(4);
tft.setCursor(a, 263);tft.println(toetswaarde);

//Serial.println("ik heb de toets gezien !!!!!!");
//Serial.println(toetswaarde);

waardebit=0;}

}

int toetsveld() {
byte a,b,c,d,e;
a=3;b=3;c=75;d=75;e=6;
tft.fillScreen(BLACK);
vierkant(a,b,c,d,e);
vierkant(a+1,b+1,c-2,d-2,e-1);
a=82;
vierkant(a,b,c,d,e);
vierkant(a+1,b+1,c-2,d-2,e-1);
a=161;
vierkant(a,b,c,d,e);
vierkant(a+1,b+1,c-2,d-2,e-1);
a=3;b=82;
vierkant(a,b,c,d,e);
vierkant(a+1,b+1,c-2,d-2,e-1);
a=82;
vierkant(a,b,c,d,e);
vierkant(a+1,b+1,c-2,d-2,e-1);
a=161;
vierkant(a,b,c,d,e);
vierkant(a+1,b+1,c-2,d-2,e-1);
a=3;b=161;
vierkant(a,b,c,d,e);
vierkant(a+1,b+1,c-2,d-2,e-1);
a=82;
vierkant(a,b,c,d,e);
vierkant(a+1,b+1,c-2,d-2,e-1);
a=161;
vierkant(a,b,c,d,e);
vierkant(a+1,b+1,c-2,d-2,e-1);
a=3;b=240;
vierkant(a,b,c,d,e);
vierkant(a+1,b+1,c-2,d-2,e-1);
a=82;
vierkant(a,b,c,d,e);
vierkant(a+1,b+1,c-2,d-2,e-1);
a=161;
vierkant(a,b,c,d,e);
vierkant(a+1,b+1,c-2,d-2,e-1);

tft.setTextColor(WHITE); tft.setTextSize(4);
tft.setCursor(32, 27);tft.println("1");
tft.setCursor(110, 27);tft.println("2");
tft.setCursor(189, 27);tft.println("3");
tft.setCursor(32, 105);tft.println("4");
tft.setCursor(110, 105);tft.println("5");
tft.setCursor(189, 105);tft.println("6");
tft.setCursor(32, 184);tft.println("7");
tft.setCursor(110, 184);tft.println("8");
tft.setCursor(189, 184);tft.println("9");
tft.setCursor(110, 263);tft.println("0");

//tft.setTextColor(YELLOW); tft.setTextSize(4);
//tft.setCursor(32, 263);tft.println(a);
//tft.setCursor(189, 263);tft.println("#");
}

unsigned long vierkant(int a,int b,int c,int d,int e) {

int kleur=MAGENTA;
tft.drawLine(a+e, b, (a+c)-e, b, kleur);
tft.drawLine((a+c)-e, b, a+c, b+e, kleur);
tft.drawLine(a+c, b+e, a+c, (b+d)-e, kleur);
tft.drawLine(a+c, (b+d)-e, (a+c)-e, b+d, kleur);
tft.drawLine((a+c)-e, b+d, a+e, b+d, kleur);
tft.drawLine(a+e, b+d, a, (b+d)-e, kleur);
tft.drawLine(a, (b+d)-e, a, b+e, kleur);
tft.drawLine(a, b+e, a+e, b, kleur);
a=0;b=0;c=0;d=0;e=0;}

A_TFTLCD.pdf (24 KB)

I think the SDA (pin A4) is connected to LCD_RESET of that shield.
That tft shield does use many pins. Only pin 0 and 1 are not used (needed to upload a sketch) and pin A5 is not needed. That means only A5 is free to use. Just that one pin :o

An I2C bus is not possible with that shield. Sorry, but that shield uses almost every pin.
You could use A5 for the DHT22, and that's it, nothing else is possible.

Could you read my reply #4 once more, about that link with number 7 about code tags ?

Ok Thanks Peter.

I am gonna look for an other display whit less pins to connect.