Im trying to send string data from arduino to raspberry pi via i2c. Raspberry pi can receive the data of particular length(probably32 bytes) of string since bus.read_i2c_block_data(address,0) read 32bytes only. But the string send from arduino to raspberry pi has length exceed 32bytes. Below code is arduino code.
#include <Wire.h>
#define SLAVE_ADDRESS 0x04
int sensorPin = A3;
int sensorValue;
String str;
String stringOne = "ldr";
//char data[50];
int index = 0;
void setup()
{
Wire.begin(SLAVE_ADDRESS); // join i2c bus (address optional for master)
Serial.begin(9600);
Wire.onRequest(sendData);
}
void sendData() {
sensorValue = analogRead(sensorPin);
String tagvalue = String("ldr=") + sensorValue;
//Serial.println(tagvalue);
tagvalue = String(tagvalue);
//String tagvalue1;
//tagvalue1 = String(",led=off");
tagvalue = String(tagvalue) + String(",streamkey=98081d09-4359-4b8b-8ba5-f265430155ff");
Serial.println(tagvalue);
//Wire.write('c');
//Serial.println("hi");
Wire.write(tagvalue.c_str());
//delay(1000);
//nWire.write(String("hi").c_str());
//Wire.write(tagvalue1.c_str());
}
void loop()
{
sendData();
delay(5000);
}
Raspberry pi code:
import smbus
import time
bus = smbus.SMBus(1)
address=0x04
data=""
value=""
while True:
#print 'reading'
value = bus.read_i2c_block_data(address,0)
for i in range(len(value)):
data+=chr(value[i])
print data
time.sleep(2)
data=""
value=""
This is the string im trying to receiving...
"ldr=254,led=on,stream=98081d09-4359-4b8b-8ba5-f265430155ff"
Im getting this error in raspberry pi when i try to receiving the above string.
Traceback (most recent call last):
File "i2cstr.py", line 8, in <module>
character = bus.read_i2c_block_data(address,0)
IOError: [Errno 5] Input/output error
How to solve this problem?