Your Arduino As a File Transfer Machine - Works With USB, WiFi, and More
by herwig9820 in Circuits > Arduino
785 Views, 10 Favorites, 0 Comments
Your Arduino As a File Transfer Machine - Works With USB, WiFi, and More

Move Files Back and Forth With a Single Command
Wouldn’t it be great if you could transfer complete text files — or even binary files — between your computer and your Arduino?
And what if you could do so with a single command in the Arduino command line, without writing any extra code?
In fact, you send and receive files over USB, TCP/IP, or any interface that uses the Arduino Stream class — as long as the device you're communicating with can also handle file transfer.
In this Instructable, I’ll show you how to send and receive files over USB.
Follow along, and you’ll be moving files to and from your Arduino in no time. Let’s get started!
Supplies
- Arduino nano (use one of these: ESP32, nano 33 IoT, 33 BLE, RP2040)
- An SD card module
- A free Terminal program on your computer
Prerequisite: SD Card Module Connected to Your Arduino

Of course you'll need a medium to store files that you receive and / or send: an SD card ! For this, you'll need a tiny SD card module that you need to connect to your Arduino.
This instructable assumes that your Arduino is wired to an SD card module. If that's not the case yet, you'll find a very good tutorial here: https://learn.adafruit.com/adafruit-micro-sd-breakout-board-card-tutorial
This tutorial explains which wire connections to make, how to format the SD card, which Arduino libraries to use... Furthermore, it will guide you through a set of basic test and demo programs.
Once you're acquainted with all that, let's move on!
Prepare a Few Test Folders and Files

On your computer create 3 folders:
- engines
- factory
- images
Download the attached text files and save them on your computer:
- save 'comb_eng.txt', 'elec_mot.txt', 'steam_eng.txt' and 'wind_tur.txt' in folder 'engines'.
- save 'cust_ord.txt, 'employee.txt', 'pr_tasks.txt' and 'prod_inv.txt' in folder 'factory'
- save a few images you own (which are binary files) in folder 'images'
⚠ Please note: the SD library uses the 8.3 file system: file names are limited to 8 characters, followed by a 3-character extension. Change image file names to comply if needed.
Prepare the SD card
On your computer, format an SD card (maximum size 32 GB, FAT32 file system).
Copy the three folders you created, with their contents, from the computer to the SD card.
Safely eject the SD card and keep it ready.
Install the Justina Interpreter Library

Justina is an easy-to-use programming language for Arduino. It's interpreted, meaning we can also use it in 'immediate mode', typing commands right into the Command Line of the Arduino Serial Monitor (or another Terminal program, as we'll see further down). And that's exactly what we need to send and receive files.
Now, install the library from the Arduino IDE:
- select the 'Libraries' icon
- search for library 'Justina'
- install the library
You can find more info about Justina in
- my instructable https://www.instructables.com/Introducing-Justina-Just-an-Interpreter-for-Arduin/
- the Justina user manual (attached to the last step) - but feel free to skip that for now, as you won't need it here
Upload Justina Example Program 'Justina_easy'


Justina comes as a library, meaning you will still need a 'main' Arduino program to call it. For that purpose the library contains a few example programs, but we're only going to use program 'Justina_easy' (which rightfully suggests there's nothing difficult about it).
In the Arduino IDE:
- select 'File -> Examples'
- In the list of examples, scroll down to 'Examples from Custom Libraries'
- Scroll further down to 'Justina interpreter -> Justina_easy'
This is a really small program: it just creates a Justina object, sets a baud rate and starts Justina.
At this time, verify that the correct board and port are selected in the Arduino IDE, and set the baud rate of the Arduino Serial Monitor to 115200 (same as set in the Arduino program).
Finally, compile and upload the program. After a few seconds, on the Serial Monitor you should see the Justina startup message and a Justina prompt, as shown in the second figure.
Let's quickly test proper functioning of Justina now
In the command line (Serial Monitor) type
1+2 (+ ENTER)
This 'statement' will be echoed after the Justina prompt and the result will be shown, right-aligned, on the next line.
Now, type
cos(0) (+ ENTER)
This calculates the cosine of a zero-angle, which is 1 (irrespective of the angle mode).
Verify that also this statement and its result are displayed on the Serial Monitor.
Examine the Contents of the SD Card

Carefully insert the SD card in the Arduino SD card module.
Then, in the command line, type
startSD (+ ENTER)
to initialize the SD library.
If the system responds with an error, either the SD card module is not properly wired, the SD card is not inserted correctly or it's not recognized.
Assuming all is OK, 'startSD' will be echoed and a new Justina prompt will be printed.
Now type
listFiles (+ ENTER)
This lists all SD card folders and files together with the file sizes. You should see a file list as in the figure above, listing the files you placed earlier on the SD card.
Send Text Files to Your Computer

Let's now send one of the files you saved earlier on the SD card to the Serial Monitor.
In the command line, type
sendFile "/engines/comb_eng.txt", CONSOLE (+ ENTER).
CONSOLE refers to the standard I/O device, which is set to Serial (USB) right now (other I/O devices can be defined as well, e.g., a TCP/IP terminal).
⚠ you must include the full file path in the file name, and start with a slash ('/')
⚠ The SD library uses slash characters as separators in path names, not backslash characters.
The Serial Monitor has no functionality to automatically save the file on the computer, which is of course a problem for large files, we'll deal with that in the next step. For now, select and copy the file content (ctrl-C) in the Serial Monitor window and paste it in a text file in order to save it.
Use a Terminal App Instead of the Serial Monitor



The Arduino Serial Monitor is a great debugging tool for basic serial communication and monitoring, but it only allows for real-time viewing of serial data, without direct options to save data to a file, log output automatically, send files, etc.
A number of alternatives exist, such as PuTTY and Tera Term. But we will use YAT (Yet Another Terminal) in the remainder of this instructable. YAT is a free, versatile Terminal: it allows logging of both sent and received data, it can send and receive files over USB, TCP/IP connections etc., it supports timestamps, predefined commands etc.
Download and install YAT
- On your computer, download and install YAT (https://sourceforge.net/projects/y-a-terminal/).
- Start YAT terminal
Prepare YAT to transfer (send and receive) text files
Execute the actions below.
Terminal->Settings popup (see figure):
- terminal type: Text
- I/O type: Serial COM port
- Serial port: the USB port the Arduino is connected to
- Enter the correct the baud rate etc.
- button 'Text settings...': in the sub-popup that opens, select 'Separate settings for Tx and Rx' and enter 'Break lines after': 128 characters.
Send menu:
- in the dropdown that will open, verify that the only option selected is 'Keep [Text] after Send'. Deselect all other menu options
View menu (see figure):
- Verify that all options are deselected in the dropdown
- Disable the formatting menu item
- Radix->String: this prints characters sent to YAT's output window as normal text, and not as the internal codes representing these characters (you could also click toolbar button 'Str')
- Click 'Panels' and
- deselect the first two menu items('Unidirectional send' / 'Bidirectional send / receive'), select 'Unidirectional receive' instead
- select menu items 'Send Text' and 'Send File'
Prepare YAT to save text files sent by Arduino
Execute the actions detailed below.
Log->Settings... popup (see figure):
- Root directory and filename base: choose the folder where you want to store received text files and the first (common) part of filenames
- Neat format: select 'log receive data (Rx)' (deselect the other check boxes) and select a file type (.txt)
- File write mode: select 'Create separate files'
- You can then further specify whether to create subfolders, inclusion of date and/or time in the filename and so on.
Connecting and disconnecting YAT
Use the green and red buttons in the toolbar (underneath the menu bar) to connect or disconnect YAT (see figure).
⚠ Before connecting YAT, close the Arduino Serial Monitor window (you cannot connect both at the same time).
⚠ While connected, verify that indicators 'RTS' (Request to Send) and 'DTR' (Data Terminal Ready) are ON (green light). If currently OFF (red lights), click on the indicators to change their status. The other indicators are not relevant.
Transfer Text Files From Arduino to Your Computer (II)

Sending a text file to the computer: didn't we do that already ? Well, yes, but this time we would like to automatically save the received file on the computer, as an exact copy of the sent file. This requires following sequence of events:
- Arduino: stop printing 'Justina>' prompts etc. (dispMode command)
- YAT: start saving ('logging') received data to file
- Arduino: send the file, without 'Sending file...' and 'File sent' messages ('silent' mode)
- YAT: stop saving ('logging') received data to file and close the file
- Arduino: restore display mode again (dispMode command)
Transfer a text file to the computer and save it there
Let 's transfer one of the text files you saved earlier on the SD card back to the computer.
Execute the actions below (bold: typed in command line, italic: menu items to execute).
dispMode 0, 1 (+ ENTER)
Log->On
sendFile "/engines/comb_eng.txt", CONSOLE, FALSE (+ ENTER)
Log->Off
dispMode 2, 1 (+ ENTER)
The file has been transferred and saved and Justina display mode is restored.
Note: If logging was already switched on, switch it off briefly and switch it back on again. This starts logging with a fresh log file .
The last argument in the sendFile command ('FALSE') suppresses 'Sending file' and 'File sent' messages.
⚠ you must include the full file path in the file name, and start with a slash ('/')
⚠ The SD library uses slash characters as separators in path names, not backslash characters.
⚠ The full Justina command syntax (which you don't need right now) is described in the Justina user manual, attached to the last step of this instructable.
View the saved text file
Select 'Log->open log folder in file browser...'. This opens the folder in windows explorer. Sort the files by descending date. The newly created file will be shown on top. Change the file name as required and open it in Notepad (or Notepad++) to verify its contents.
Transfer Text Files From Your Computer to Arduino

To transfer a text file to Arduino, the same settings apply as for transferring a text file from Arduino to computer.
If the directory where we want to store the file does not exist yet on the SD card, we must first create it separately.
First, select the file to transfer to the Arduino SD card:
- click button 'browse for a file' (button with three horizontal dots, to the left of button 'Send File') to open a Windows Explorer window
- navigate to folder 'factory' (folder you created earlier on)
- select the file 'employee.txt' (see figure) and click OK
In Arduino, we'll create a new folder on the SD card and store the file there.
Transfer a text file to the Arduino SD card
Execute the actions below (bold: typed in command line, italic: menu items or to execute or buttons to click).
createDirectory("factory2")
receiveFile CONSOLE, "/factory/employee.txt", FALSE (+ ENTER)
click button 'Send File [F4]'
The file has been transferred and saved on the SD card on a newly created directory.
The last argument in the receiveFile command ('FALSE') forces overwriting files without asking confirmation. It also suppresses 'Waiting for file', 'Receiving file' and 'File received' messages. Remove this argument (or enter 'true' instead) if you want Arduino to request confirmation before overwriting a file (only send the file after the confirmation).
⚠ you must include the full file path in the file name, and start with a slash ('/')
⚠ The SD library uses slash characters as separators in path names, not backslash characters.
⚠ The full Justina command syntax (which you don't need right now) is described in the Justina user manual, attached to the last step of this instructable.
List SD card files and check the new file is there
Use the ListFiles command to print a file list; compare the size of the new file in folder 'factory2' with the older copy in folder 'factory'
Transfer Binary Files From Arduino to Your Computer

Preparation
First, we will need to set YAT to binary mode. These settings are identical to the settings for text files, except a few changes that must be made, as detailed below.
Terminal->settings popup:
- Terminal Type: Binary
- button 'Binary settings...': in the sub-popup that opens, select 'Separate settings for Tx and Rx' and enter 'Break lines after': 128 characters
In binary mode, when sending a command to Arduino, the command (e.g., sendFile...) will not be terminated with an end of line character (ASCII code 0x0A). So Arduino would keep waiting for this 'EOL' character before doing something. Solution: adding it manually by typing a 2-character 'escape sequence '\n' (backslash n) at the end.
But for that to work, we must first enable 'escape sequences':
Send menu:
- Select option 'Enable Escapes on sending [Text]'
Log->settings popup:
- Change the log type to 'raw data' and select a binary file type (e.g., enter .jpg for .jpg images - don't forget the starting dot)
View menu:
- Radix->Hexadecimal: this prints the hexadecimal codes of the characters sent to YAT's output window instead of the characters themselves (plain text). You could also click toolbar button '16')
That's all that needs to be changed to be able to send binary files.
Transfer an image file to the computer and save it there
Let's transfer one of the image files that you saved earlier on the SD card:
Execute exactly the same actions as you executed to transfer a text file to the computer but end each command with '\n' (backslash 'n'). That's all there is to it.
dispMode 0, 1\n (+ ENTER)
Log->On
sendFile "/images/<your image file name on the SD card>", CONSOLE, FALSE\n (+ ENTER)
Log->Off
dispMode 2, 1\n (+ ENTER)
The image has been transferred and saved and Justina display mode is restored.
⚠ The binary contents of the file are printed in the output window in hexadecimal format, which is normally not very useful (hexadecimal output).
When done: set the terminal back to text mode
- 'Terminal->settings' popup: switch back to terminal type 'text'
- 'Send' menu: deselect option 'Enable Escapes on sending [Text]'
- 'View' menu: switch back to radix 'String'
- 'Log->settings': switch back to text file logging
Verify that the saved file is identical to the original file
Select 'Log->open log folder in file browser...'. This opens the folder in windows explorer. Sort the files by descending date. The newly created file will be shown on top. Change the file name as required.
Open the image file in an image viewer (double-clicking on it will open the default one) and visually check that the image is displayed correctly.
In windows explorer, right-click on the file, select properties. In the popup that opens, verify that the size (not the 'size on disk') is identical to the size of the original file.
Transfer Binary Files From Your Computer to Arduino
To transfer a binary file to Arduino, the same settings apply as for transferring a binary file from Arduino to computer.
In this step we'll transfer an image file to Arduino. To select it:
- click button 'browse for a file' (button with three horizontal dots, to the left of button 'Send File') to open a Windows Explorer window
- navigate to the image you want to transfer and click OK
In Arduino, we'll store the file in (existing) folder 'images'.
Transfer an image file to the Arduino SD card
Execute the actions below (bold: typed in command line, italic: menu items or to execute or buttons to click).
The command is the same as used to transfer a text file to the computer but end it with '\n' (backslash 'n').
receiveFile CONSOLE, "/images/<image file name on the SD card>", FALSE\n
click button 'Send File [F4]'
The file has been transferred and saved on the SD card with the file name you entered.
The last argument in the receiveFile command ('FALSE') forces overwriting files without asking confirmation. It also suppresses 'Waiting for file', 'Receiving file' and 'File received' messages. This 'silent' mode is preferred when transferring binary files because in binary mode it's quite difficult to interpret what you see in the output window.
⚠ you must include the full file path in the file name, and start with a slash ('/')
⚠ The SD library uses slash characters as separators in path names, not backslash characters.
⚠ The full Justina command syntax (which you don't need right now) is described in the Justina user manual, attached to Step 3 of this instructable.
When done: set the terminal back to text mode
- 'Terminal->settings' popup: switch back to terminal type 'text'
- 'Send' menu: deselect option 'Enable Escapes on sending [Text]'
- 'View' menu: switch back to radix 'String'
List SD card files and check the new file is there
Use the ListFiles command to print a file list; compare the size of the new SD card file with the original file on the computer (in windows explorer, right-click on the file, select properties. In the popup that opens, verify that the size - not the 'size on disk' - is identical to the size of the original file).
Taking It Further

In this instructable you learned how files can be transferred between your Arduino and a computer. For this, we relied on the Justina interpreter. As you might have guessed, Justina can do much more than transmitting files. You're invited to download the Justina user manual (attached to this step) and explore it's capabilities in more detail.
More information:
https://www.instructables.com/Introducing-Justina-Just-an-Interpreter-for-Arduin/
And on GitHub:
https://github.com/Herwig9820/Justina_interpreter/blob/master/README.md
A final note on TCP/IP
As mentioned earlier, transmitting files (or live data) is stream-independent. In the case of a TCP/IP connection, the setup of Justina is a little more complex: when starting Justina, you need to pass
- a reference to the TCP/IP stream
- the address of a callback routine to maintain the TCP/IP connection
- if you want to control the TCP/IP server from within Justina: the addresses, aliases... of callback routines performing specific functions (starting / stopping WiFi,...)
And you can continue to use YAT as terminal, because YAT can easily be configured as TCP/IP client!
Justina library example program 'Justina_TCP_server' demonstrates this (Arduino IDE: File -> Examples -> (custom libraries) -> Justina_TCPIP_server).
See also Appendix C of the Justina user manual.