I'm working on a project that suppose to read text files from SD card, Transfer the first 3 lines (50 characters) in each file using I2C protocol to another arduino, which show these lines on tv screen.
The problem is with the transfer protocol and the TV part. Some data is transfered but it shows few, messy letters on the tv screen and i can't find what exactly is wrong.
The first arduino (SD read + data transfer) code is:
#include <SD.h>
#include <Wire.h>
File myFile;
int relay = 2;
char inputChar;
void setup() {
Wire.begin();
pinMode(relay, OUTPUT);
pinMode(10, OUTPUT);
SD.begin(4);
}
void loop() {
for(int i=1;i<4;i++)
{
Wire.beginTransmission(4);
String temp = "Book";
temp.concat(i);
temp.concat(".txt");
char filename[temp.length()+1];
temp.toCharArray(filename, sizeof(filename));
myFile=SD.open(filename);
for (int j=1; j<50; j++) {
inputChar = myFile.read();
Wire.write(inputChar);
}
Wire.endTransmission();
long ontime =((0.1* myFile.size())-30);
digitalWrite(relay,HIGH);
delay(ontime);
digitalWrite(relay, LOW);
delay(5000);
myFile.close();
}
}
The 2nd arduino (Data receive + TVOUT) code is:
#include <TVout.h>
#include <Wire.h>
TVout TV;
char tvMessage[49];
int index=0;
void setup ()
{
Wire.begin(4); // join i2c bus with address #4
Wire.onReceive(receiveEvent); // register event
TV.begin(_PAL);
}
void loop ()
{
TV.clear_screen ();
TV.print_str(0, 50, tvMessage);
TV.delay ( 60 );
}
void receiveEvent(int howMany)
{
while(0< Wire.available())
{
tvMessage[index] = Wire.read();
index++;
if (index==49) {index=0;}
}
}
Any ideas?
Thanks.