I am trying to build a program for transferring files to an arduino project with an attached sd card. I have some code, it does some interesting stuff, but it's not quite what I want it to do. What I need it to do is to be able to transfer binary files to the arduino where I will save them to the sd. There are going to be several parts of this project. One part will probably be a shell script or C# script (windows) where I will transfer the files via COM. Another part will be the arduino code which will have to be able to distinguish between individual files, and will need to be able to recognize when seperate files are sent. Ultimately the shell script/C# whatever part will be sending file after file to the arduino, perhaps in a loop in a specific folder.

The arduino part will proably be coded in the "Processing" language, the default language for arduino development. At some point I will probably migrate to teensy if I can get the logic down right. Arduino is easier for the time being.

Some of the things that are hanging me up are that I have to figure out a way how to switch between the files, and transmit file names, etc. I will be delving into a sockets book I have laying around, perhaps that can shed some light on the subject. The binary transmission and reception is also a problem, as well as thinking more in terms of socket communication.

At some point I could add some VID/PID changing code possibly if I can get the project working, as well as some code to inject the script (which will at that point be batch or something) onto the computer.

This is just something I think would be cool to make, I will be making more code etc, I just was wondering if any of you had any useful observations on the 'Socket' like aspect of the serial communication?

Here is some starter code, but it is probably not executing correctly, it is operating on text files, not binary, and it has no concept of the file name, and the file switching is not in place yet.

#include <SD.h>
#include <SPI.h>

//Set by default for the SD card library
//MOSI = Pin 11
//MISO = Pin 12
//SCLK = PIN 13
//We always need to set the CS Pin
const int CS_PIN  = 10;
const int ERR_PIN = 1;
const int WRITE_PIN = 4;
bool closed = false;

//We set this high to provide power
const int POW_PIN = 8;

const int BUFF_SIZE = 32;
const bool debug = true;//switch to false for in the wild functionality
File myFile;

void setup()

  while (!Serial) {
    ; // wait for serial port to connect. Needed for native USB port only

  Serial.print("Initializing SD card...");

  if (!SD.begin(CS_PIN)) {
    Serial.println("initialization failed!");
  Serial.println("initialization done.");

  myFile = SD.open("test.txt", FILE_WRITE);
}//end func

void loop()
  if(closed == false){
      char ch = Serial.read();

      if(ch == 0){//close file when eof encountered
        closed = true;
      else if(ch != -1){

      //if the file didn't open, print an error:
      Serial.println("error opening test.txt");

}//end func

using System;
using System.IO.Ports;

namespace SerialPortWrite
    class Program
        static void Main(string[] args)
            SerialPort port = new SerialPort();
            port.PortName = "COM6";
            port.BaudRate = 9600;
            port.DataBits = 8;
            port.Handshake = Handshake.None;
            port.StopBits = StopBits.One;


            Console.WriteLine("Input text to send to COM device: ");
            String str = Console.ReadLine() + (char)(0);

            for (int i = 0; i < str.Length; i++) {
                port.Write(str[i] + "");

                byte[] buff = new byte[1];
                port.Read(buff, 0, 1);



            //if debugger is attached, want to pause the output at the very end
            if (System.Diagnostics.Debugger.IsAttached) {
                Console.Write("Press any key to continue... ");
        }//end main

    }//end class

}//end namespace

>$port = new-Object System.IO.Ports.SerialPort COM5, 9600, None, 8 one
>$port.WriteLine("Hello World")

>$port = new-Object System.IO.Ports.SerialPort COM5, 9600, None, 8, one

>ECHO "some text" > COM5
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.