Pages: [1]   Go Down
Author Topic: Sending a file from PC to Arduino using Gobetwino  (Read 964 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 20
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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:
#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);
 
  }
}
Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 617
Posts: 49463
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Code:
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:
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:
  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?

Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 20
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Offline Offline
Newbie
*
Karma: 0
Posts: 20
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

"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.
Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 617
Posts: 49463
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

Copenhagen / Denmark
Offline Offline
Edison Member
*
Karma: 6
Posts: 2360
Do it !
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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


Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 20
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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:
// 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 ();
}
}
Logged

UK
Offline Offline
Shannon Member
****
Karma: 223
Posts: 12630
-
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

I only provide help via the forum - please do not contact me for private consultancy.

Offline Offline
Newbie
*
Karma: 0
Posts: 20
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Thanks.
Logged

Pages: [1]   Go Up
Jump to: