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