Sending a PC file to Arduino - and back

Hi guys;

I just wondering if it is possible to access a file from your PC, sending through the Arduino and display the hex code ( example ) to a LCD display or program an EPROM or others things base on the data in your PC. Also data from the Arduino and save it to your PC.

My answer : YES. I need an Arduino connect via USB and the Arduino connect to a LCD display , for example. ← I think that will be the hardware side.

It the software side I may have questions. I know I need a program inside the Arduino to take care of the PC data, and I need a PC program to send the data from a PC file ( example : a text file ) to the USB.

To do this In C++ ( send data through ports ??? ), I don’t know how ?

What about Processing ? I guess it is possible… I don’t know how… ?

Can you guys point me to the right info & dicrections so I can look it up, research it, experiment it and lean it. Example to do it will be nice. I just want to know if it is possible to do this type of project…

Thank in advance.

I just want to know if it is possible to do this type of project...

Creating a PC application to open a file and stream the contents to the Arduino is simple.

Processing, C++, C#, and other languages can be used.

Also data from the Arduino and save it to your PC.

You are not going to be able to store the file on the Arduino unless it is very small, or you have an SD card.

Sending data to the PC is simple. Creating an application on the PC that collects the serial data and writes it to a file is relatively simple. Processing, C++, C#, and other languages can be used.

Thank PaulS for the reply. Creating a PC program to stream to a new file is something I am trying to learn right now... I did before by changing the save file of the game Ceasar 2 and Sim Isle in console mode.

But PaulS, it to access and to send the file to the USB where the Arduino is plug in, that I have a no idea how...

And I do agree to save a file into the Arduino is "out-of-question" , use SD or save to the PC.

that I have a no idea how...

How depends on what language you are using. Java, C++, C# and other languages all have some sort of Serial class that communicates with the serial port. Processing includes some examples of reading files and some examples of writing to the serial port. Combine two of them to have an application that reads from a file and writes to the serial port.

The SerialCallResponse example is good, because it shows how to make Processing wait for the Arduino to be ready/have finished dealing with the last record.

Serial class…OK…I will into Processing. ( I SOO new at Processing … ) In C++, read a file, I am OK with that, the books I have will help… write to serial port… That part I have a problem… no info in the books I have… I will try to do a search on the Net.
My search line will be : write to serial port in C++.

Bear in mind PaulS that I have a few practice in C++, in Java…& Java Me . I am leaning about it, and C# ← ??? That last one is …Unknow.

I will do my best.

Updated :

I did a lot of reading about the subject ( use serial/USB ) , I look into Processing, YES can be done. Serial is look easy, Files processing ( read/write ) to/from a file , no so easy ( yet ) , and I have no idea to "enter" data from a keyboard in Processing. I will do a lot of reading. About C++, well not so easy to understand, I did came across this site http://www.codeproject.com/KB/system/serial.aspx , I am trying to understand, try to use and program it ( in Code::Blocks ) no luck in compiling. :stuck_out_tongue_closed_eyes: In MicroSoft Visual C++.NET, it did compile and not compile :~ , more ???? And in Java is well...uh ? ( trying to figure things out )

[rant] Anyway, my whole leaning process is : :~ and :stuck_out_tongue_closed_eyes: [/rant]

I am doing my best to figure things out.

Updated :

After my hard research and web surfing, I will stick with Processing. I try today ( it is a start ), read a file ( inside my hard drive ) , send data to the Arduino… work ( sort of… ) the RX lights up…but to use the Serial Monitor cause problem ( no display ) ( My guess is two program ( Processing is complaning/error messages ) trying to access the same port )

Anyway, I will re-write the Arduino program to do something using the data from my hard drive. As for Processing, I have to design a keyboard data entry routine ( no cin >>data; or INPUT A ) to enter the name of the file I want to send.

I am doing my best…

Yes you can't have two programs trying to access the same port on a PC.

Yep, Mike. You right… ( to my discovery ) - to bad I can not use the serial monitor from the Arduino IDE.

Anyway, gentlemen. I did it ! :open_mouth: I use Processing to send data from a PC to an Arduino. This is just a small “Hello World”. I will do an another Processing Code , to take data from a file and send it to the Arduino using the same Arduino program.

But, using C++ program ( in Windows XP ) is an another “hard” story. :~

The Arduino code have to run first, and run the Processing program.

The Arduino is simply connect to a LCD Display.

Here both codes :

Arduino Code:

#include <LiquidCrystal.h>

LiquidCrystal lcd (7,8,9,10,11,12);

byte incom;

void setup()
{
  Serial.begin(2400);
  lcd.begin(16,2);
  lcd.clear();
}

void loop()
{
  if (Serial.available()>0)
  {
    incom=Serial.read();
    lcd.write(incom); 
  } 
}

Here the Processing code :

import processing.serial.*; // the serial library for processing to use - A JAVA header "loader"

Serial myport;

int portindex=3; // the port index is where the Arduino is connect to my system - COM7

void setup()
{
   size(200,200); // a blank window
   println(Serial.list()); // show the com ports in your PC
   println("Connecting to "+Serial.list()[portindex]);
   myport = new Serial(this,Serial.list()[portindex],2400); // init the serial port 
   myport.write("This is a test");
}

void draw ()
{
  
}

Here is the Processing program to access data from a file in your PC and send via USB serial port to the Arduino. The following code is simply a “Hello World”.

Here is the steps:

  1. Type a small message like “Hello World” in Notepad and save the file like “test.txt” in your save Processing files.

example : folder : myserialtest —> myserialtest.pde test.txt ← Make sure the files are there

  1. Typed & upload the Arduino code. And make sure the Arduino program is running.

  2. Typed & run the Processing code.

  3. See the message on the LCD display.

Here the Processing code :

/*
    A simple "Hello Wold" program using a file from your computer
    and send to an Arduino with a LCD display.
    
    By Serge J Desjardins aka techone,tech37
*/

import processing.serial.*;

Serial myport;

int portindex=3; // Arduino USB port number from the serial list
int sz;

void setup()
{
   size(200,200);
   byte data[] = loadBytes("test.txt");
   sz=data.length; // How big is the array
   // Show the size of the file
   println("The size of the file is : "+sz+"\n");
   // Show the ports list of your computer system   
   println(Serial.list());
   println("Connecting to "+Serial.list()[portindex]);
   // init Port COM7 <- in the author case...
   myport = new Serial(this,Serial.list()[portindex],2400);
   println("Sending Data...\n");
   // Sending the content of the array 
   for (int i=0;i<sz;i++)
   {     
     print(char(data[i])); // Monitor send data
     myport.write(char(data[i])); // Convert Decimal to ASCII
     // And send data out.
   }  
   println("\nFinish.\n");
 }

void draw ()
{
  
}

This is just the basics methods. I hope it is useful.

Have fun and send me any comments.