Arduino <> raspberry pi via i2c

I am trying to pass data to a rpi from arduino via i2c.The lcd is displaying the correct values at the arduino. i am getting this result from the rpi
quote]
Enter Task
1 Check Time
2 North Garage Door
3 South Garage Door
: 1
RPI:Hi Arduino, I sent you a 1
Time is
[]

Enter Task
1 Check Time
2 North Garage Door
3 South Garage Door
: 2
RPI:Hi Arduino, I sent you a 1
Time is

Enter Task
1 Check Time
2 North Garage Door
3 South Garage Door
[][/quote]

Arduino code:

/**
 * ReadSHT1xValues
 *
 * Read temperature and humidity values from an SHT1x-series (SHT10,
 * SHT11, SHT15) sensor.
 *
 * Copyright 2009 Jonathan Oxer <jon@oxer.com.au>
 * www.practicalarduino.com
 */

#include <SHT1x.h>
#include <Wire.h>
#include <UTFT.h>\




// Specify data and clock connections and instantiate SHT1x object
#define dataPin  15
#define clockPin 14
#define SLAVE_ADDRESS 0x04
extern uint8_t BigFont[];
char tStr[7];
char hStr[4];

UTFT    myGLCD(ITDB32S,38,39,40,41);
SHT1x   sht1x(dataPin, clockPin);


void setup()
{
  Serial.begin(115200); // Open serial connection to report values to host
  Serial.println("Starting up");
  myGLCD.InitLCD();
  myGLCD.clrScr();
  myGLCD.setFont(BigFont);
  myGLCD.setBackColor(0, 0, 255);
  Wire.begin(0x04); // join i2c bus
}

void loop()
{
  float temp_c;
  float temp_f;
  float humidity;

  // Read values from the sensor
  temp_c = sht1x.readTemperatureC();
  temp_f = sht1x.readTemperatureF();
  humidity = sht1x.readHumidity();


  dtostrf(temp_f, 4, 1, tStr);
  dtostrf(humidity, 2, 0, hStr);
  Serial.print(tStr);
  Serial.println('   ');
  Serial.print(hStr);
  Serial.println('   ');
  myGLCD.print("Temperature: ",LEFT,0);
  myGLCD.print(tStr,15*13,0);
  myGLCD.print("Humidity: ",LEFT,15);
  myGLCD.print(hStr,12*13,15);
  delay(2000);
}

// callback for received data
void receiveData() 
{
  char c = Wire.read();
///  Serial.println(c);
}



void writeData (char* data)
{
  Wire.beginTransmission(04); // transmit to device #04
  // device address is specified in datasheet
  Wire.write(data);             // sends value byte  
  Wire.endTransmission();     // stop transmitting

  delay(500);
}

// callback for received data
void readData ()
{
  int number;
  while(Wire.available())
  {
    number = Wire.read();
    switch (number)
    {
    case 1:
      writeData(tStr);
      break;
    case  2:
      writeData(hStr);
      break;
    }
  }
}

Raspberry pi code

    import smbus
    import time
    # for RPI version 1, use "bus = smbus.SMBus(0)"
    bus = smbus.SMBus(1)

    # This is the address we setup in the Arduino Program
    address = 0x04

    def writeNumber(address, value):
        bus.write_byte(address, value)
        # bus.write_byte_data(address, value)
        return -1

    def writeChar(address, value):
        bus.write_word(address, value)
        return -1


    def readNumber(address):
        number = bus.read_byte(address)
        #number = bus.read_byte_data(address, 1)
        return number

    while True:
        print "Enter Task"
        print "1  Ckeck Time"
        print "2  North Garage Door"
        print "3  South Garage Door"
        var = input(": ")
        if not var:
            continue

        writeNumber(address, var)
        print "RPI: Hi Arduino, I sent you ", var


        # sleep one second
        time.sleep(1)

        number = readNumber(address)
        print "Arduino: Hey RPI, I received a digit ", number
        print


    def rdb():
        buffer[10]
        bus.read_block_data(address,buffer)

I posted this on the rpi forum and the general consensus was that the arduino is not passing good info. So I'd like your opinion.

Jim

and the general consensus was that the arduino is not passing good info.

Based on what evidence? Where do you (think you) actually send data to the I2C bus?

PaulS:

and the general consensus was that the arduino is not passing good info.

Based on what evidence? Where do you (think you) actually send data to the I2C bus?

In the writeData function. It works in arduino code

#include <Wire.h>

#define SLAVE_ADDRESS 0x04
int number = 0;
int state = 0;

void setup() {
    pinMode(13, OUTPUT);
    Serial.begin(9600);         // start serial for output
    // initialize i2c as slave
    Wire.begin(SLAVE_ADDRESS);

    // define callbacks for i2c communication
    Wire.onReceive(receiveData);
    Wire.onRequest(sendData);

    Serial.println("Ready!");
}

void loop() {
    delay(100);
}

// callback for received data
void receiveData(int byteCount){

    while(Wire.available()) {
        number = Wire.read();
        Serial.print("data received: ");
        Serial.println(number);

        if (number == 1){

            if (state == 0){
                digitalWrite(13, HIGH); // set the LED on
                state = 1;
            }
            else{
                digitalWrite(13, LOW); // set the LED off
                state = 0;
            }
         }
     }
}

// callback for sending data
void sendData(){
    Wire.write(number);
}

pi code

import smbus
import time
# for RPI version 1, use "bus = smbus.SMBus(0)"
bus = smbus.SMBus(1)

# This is the address we setup in the Arduino Program
address = 0x04

def writeNumber(value):
    bus.write_byte(address, value)
    # bus.write_byte_data(address, 0, value)
    return -1

def readNumber():
    number = bus.read_byte(address)
    # number = bus.read_byte_data(address, 1)
    return number

while True:
    var = input("Enter 1 - 9: ")
    if not var:
        continue

    writeNumber(var)
    print "RPI: Hi Arduino, I sent you ", var
    # sleep one second
    time.sleep(1)

    number = readNumber()
    print "Arduino: Hey RPI, I received a digit ", number
    print

where result on pi is

RPI: Hi Arduino, I sent you 2

Arduino: Hey RPI, I received a digit 2

RPI: Hi Arduino, I sent you 9

Arduino: Hey RPI, I received a digit 9
Jim

In the writeData function.

Which wasn't even in the first code you posted. I've lost track of what your problem is.

PaulS:

In the writeData function.

Which wasn't even in the first code you posted. I've lost track of what your problem is.

I trying to pass data from arduino to rpi via i2c.

Jim

So how do you know the hardware is correct?
In order to protect the Pi you need an Arduino I2C library that does not enable the internal pull up resistors. The library you use is the standard one that does enable these. Have you hacked it to disable them?