chipKIT® Development Platform

Inspired by Arduino™

Need help on I2C

Created Tue, 26 Mar 2013 23:48:55 +0000 by AErol


AErol

Tue, 26 Mar 2013 23:48:55 +0000

I want to read temperature from a temperature sensor TMP275 through I2C on a chipkit UNO32 . I connected the SDA to A5 and SCL TO A4 .

first i used this program

#include <Wire.h>

void setup() {
  Wire.begin();
  Serial.begin(9600);

  for(int i=0; i<128; i++) {
    Wire.beginTransmission(i);
    int x = Wire.endTransmission();

    if(!x) {
      Serial.print("Success at: ");
      Serial.print(i, BIN);
      Serial.print(", 0x");
      Serial.print(i, HEX);
      Serial.print(" ,");
      Serial.print(i);
      Serial.println("");
    }

  }// for
}

void loop() {}// loop

and on serial monitor i received this using an atmega board :

Success at: 0, 0x0 ,0
Success at: 1001001, 0x49 ,73

and this when i used the UNO32 board :

Success at: 0, 0x0 ,0
Success at: 1, 0x1 ,1
Success at: 10, 0x2 ,2
Success at: 11, 0x3 ,3
Success at: 100, 0x4 ,4
Success at: 101, 0x5 ,5
Success at: 110, 0x6 ,6
Success at: 111, 0x7 ,7
Success at: 1111100, 0x7C ,124

, the program that works on arduino is the following :

#include <Wire.h>
int tmp275Address = 0x49;

void setup(){
  Serial.begin(9600);
  Wire.begin();
}

void loop(){

  float celsius = getTemperature();
  Serial.print("Celsius: ");
  Serial.println(celsius);

  delay(1000); //just here to slow down the output. You can remove this
}

float getTemperature(){
  Wire.requestFrom(tmp275Address,2); 

  byte MSB = Wire.read();
  byte LSB = Wire.read();

  //it's a 12bit int, using two's compliment for negative
  int TemperatureSum = ((MSB << 8) | LSB) >> 4; 

  float celsius = TemperatureSum*0.0625;
  return celsius;
}

so i need to convert the program to work on UNO32 to , if anyone knows how or what to change , please help me !


AErol

Mon, 01 Apr 2013 21:42:51 +0000

:( no one ?

so nobody used the I2Cto read a sensor ? or the chipkit is really hard to program :(


majenko

Mon, 01 Apr 2013 22:57:32 +0000

Do you have pull-up resistors, or does the sensor have pull-up resistors built in?


W4GNS

Mon, 01 Apr 2013 23:23:47 +0000

:( no one ? so nobody used the I2Cto read a sensor ? or the chipkit is really hard to program :(

I added code tags to your post so it is easier to read, maybe folks will look at it closer now. :P

Regards-Gary


AErol

Wed, 03 Apr 2013 16:25:34 +0000

Do you have pull-up resistors, or does the sensor have pull-up resistors built in?

yes , i have added the pull-up resistors


mikes

Wed, 03 Apr 2013 17:03:59 +0000

The basic I/O shield has a i2c temperature sensor on it, you could download the library here to peek at the code. http://www.digilentinc.com/Data/Products/CHIPKIT-BASIC-IO-SHIELD/chipKIT%20IOShield%20Library.zip


mifay

Thu, 09 May 2013 21:58:37 +0000

I haven't tested your code on my UNO32, but I did a quick look at your code and it looks pretty fine to me. The only thing that I would change are the "Wire.read()" instructions for "Wire.receive()" instructions. MPIDE doesn't support Arduino 1.0+ changes. Its still stuck with Arduino old function naming.


les1943

Fri, 10 May 2013 08:47:06 +0000

Just had a quick look , Your TMP275 slave address seems to be an issue the data sheet shows h'90 range with what you have wired on the A0 - A2 pins , but UNO (wire) shifts the address left 1 bit to add the R/W bit so you need to make int tmp275Address = 0x48
ored with A1 & A2 you wont be able to use A0 as it gets over written.