Go Down

Topic: Sending a file from PC to Arduino using Gobetwino (Read 1 time) previous topic - next topic

JayBee

Responses to my previous post got me going on this.  I am trying to send a file from the pc to Arduino where it will be written to the EEPROM.  I have the communication over the serial link working OK but can only get the first byte.  How do I get the rest of it? 

I suspect that I have to increment it somehow but am unsure where and how.

Code: [Select]

#include <EEPROM.h>


int incomingByte = 0; //for incoming serial data
int i = 0;  // for counting iterations during testing

void setup() {
  Serial.begin(9600);  // opens serial port, sets data rate to 9600 bps

}


void loop ()
{
while (i<1){
Serial.print ("i = ");  //for test purposes
Serial.println (i);
  Serial.println("#S|DOGGROWL|[]#");
i++;
}
  if (Serial.available() > 0) {  // send data only when you receive data
    incomingByte = Serial.read();  //read the incoming byte if it is there
for (int a = 0;  a < 512; a++)
EEPROM.write(a, incomingByte);

  }
}

PaulS

Code: [Select]
while (i<1){
Serial.print ("i = ");  //for test purposes
Serial.println (i);
  Serial.println("#S|DOGGROWL|[]#");
i++;
}

This loop will execute exactly once. The same thing would have happened had you simply put
Code: [Select]
Serial.print ("i = ");  //for test purposes
Serial.println (i);
  Serial.println("#S|DOGGROWL|[]#");

in setup.

I'm curious what you expect GoBetwino to do with " i = 0"?

Code: [Select]
  if (Serial.available() > 0) {  // send data only when you receive data
    incomingByte = Serial.read();  //read the incoming byte if it is there
for (int a = 0;  a < 512; a++)
EEPROM.write(a, incomingByte);

You are reading one byte, and writing that into EEPROM 512 times. How does that make sense?


JayBee

I expect Gobetwino to ignore the "i" which it does.  I used that to make sure that I understood what was going on.

JayBee

"You are reading one byte, and writing that into EEPROM 512 times. How does that make sense?"

Correct.  How do I increment to the other bytes in the file being read?  That is the point of my post.

PaulS

Quote
How do I increment to the other bytes in the file being read?

What makes you think you are not getting all the bytes from the serial port? The fact that you write the value read from the serial port to every position in EEPROM does not tell you that you are not reading multiple bytes.

Remove the code that writes to EEPROM, for now. Just blink an LED each time there is data to read. See how many times the LED blinks.

MikMo

In the GoBetwino download there's sample code demonstrating how to use the RFLIN command type.

You just repeat calling the RFLIN command you setup until it returns -2 which indicates that the requested line does not exist

pseudocode:

X=1
repeat
  give me line x
  x+=1
until GoBetwino returns -2



JayBee

OK, I have this working, sorta.  However, I get multiple iterations of the same line, ie. 10 line 1s followed by 10 line 2s followed by 10 line 3s, etc.  It is as if an EOL never occurs so the code keeps asking for the same line 10 times then moves on to the next line for some reason that I do not understand.

The file being read is a .wav file.

Code: [Select]
// Test reading a file using the Betwino RFLIN command //

int a=1; //for incrementing line number
int incomingLine = 0; //for incoming data

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

int GETLINE (){
  Serial.print("#S|DOGRFLIN|[");
  Serial.print(a);
  Serial.println("]#"); //send Betwino command
  if (Serial.available() > 0){
    incomingLine =  Serial.read();  //Get line of data
    a++;
    return (incomingLine);
  }
}

void loop () {
  while (incomingLine> -1){ /*  -1 = file does not exist
  -2 = linenr > highest linenr
  -3 = some other error */
  GETLINE ();
}
}

PeterH

You seem to be sending the GoBetwino command string and then reading back the first character of the response, and then requesting the next line. You need to wait until you have received the complete line before you request the next line.
I only provide help via the forum - please do not contact me for private consultancy.

JayBee

Yes, that seems to be the case.  I need to study up on the Serial.read stuff.

Thanks.

Go Up