Go Down

Topic: Sending Text File To Arduino Uno via COM Port (Read 2779 times) previous topic - next topic

I'm using Windows 7 64-bit, and I have a text file (C:\Example.txt) that contains some text, and I'm trying to transmit the contents of that text file to an Arudino Uno board.

Here's the example code on the board:

Code: [Select]

void setup()
{
  pinMode(13, OUTPUT);
  Serial.begin(9600);
  digitalWrite(13, LOW);
}
void loop()
{
  while (Serial.available())
  {
    char command = Serial.read();
    if (command == 'A')
    {
      digitalWrite(13, HIGH);
      delay(250);
      digitalWrite(13, LOW);
      delay(25);
    }
  }
}


I have a text file (C:\Example.txt) that just has the following in it:

Code: [Select]

ABCDEFGHIJKLMNOPQRSTUVWXYZ
ABCDEFGHIJKLMNOPQRSTUVWXYZ
ABCDEFGHIJKLMNOPQRSTUVWXYZ
ABCDEFGHIJKLMNOPQRSTUVWXYZ
ABCDEFGHIJKLMNOPQRSTUVWXYZ
ABCDEFGHIJKLMNOPQRSTUVWXYZ
ABCDEFGHIJKLMNOPQRSTUVWXYZ
ABCDEFGHIJKLMNOPQRSTUVWXYZ
ABCDEFGHIJKLMNOPQRSTUVWXYZ


And from a DOS prompt, I'm trying to copy the contents of the text file to the Arduino via the serial port like this:

Code: [Select]

MODE COM3 9600,N,8,1,P
COPY C:\Example.txt COM3


Part of the data copies just fine, and I can tell that 5 of the 'A's have transmitted fine based on the number of times the LED blinks.  But half the data failed to be received.  I've tried to send smaller batches, and play with the COM port settings, but I haven't found a way to ensure all the data gets received by the Arduino.

Is there a way to just send text data from a DOS Command prompt to the Arduino board successfully?

retrolefty

Quote
{
     digitalWrite(13, HIGH);
     delay(250);
     digitalWrite(13, LOW);
     delay(25);
   }


I suspect your use of the delay commands is at the root of your missing characters. delay() is a blocking command that stops all further processing until it times out. At 9600 baud each character takes just 1 millsec to arrive and the arduino serial receiver buffer is only 128 bytes large, so you are bound to be overflowing the buffer.

I suggest you look over the arduino example sketch called blink without delay that shows a method to time events without blocking all processing, by using the millis() function.

Lefty

Thanks retrolefty!  That was the problem.  I modified my driver script to send each line of the file 1 at a time, with a 1 second delay between each line to ensure things were processed, and all is good.  Hopefully I can return the help one day.

Go Up