Everyone wants to ensure that their precious notes and files are safe and accessible anywhere, well this device makes all of that easy. The Arduino Yun will back up your SD card files on Dropbox, and the best part is that all you have to do is insert the SD card and watch. There is no circuit involved, so it only takes minutes to get the project up and running.
This project requires a Dropbox account to work, you can create one for free. Temboo is used to communicate with Dropbox, The Arduino Yun will read the data on an SD card file and will then send the data to Dropbox, simple. The Yun will only execute this protocol once, it will do so again after reset. Here is an image illustrating the data parsing protocol.
Here is an image capturing the project's code overview.
Read
File
will read the contents of the file selected
Format
Buffer
will store the value to a String and prepare it for parsing.
Connect
Temboo
will connect the Yun to Temboo Services
Upload
File
will upload the contents of the file to Temboo, the data will then be assigned to a file in Dropbox.
This simple protocol basically backs up a text file on an SD card to Dropbox. There is not that much to explain about it because it's as simple as that. Note that the Yun can be disconnected from power and the SD card can be removed only when the device executes the code to prevent damaging the SD Card. Note that the Serial Monitor must be open to operate the device. A Temboo account is required to operate this project, see below for a guide.
BenefitsThe user operating this project will benefit in:
- Storing files on Dropbox easily
- Backing up text files to dropbox from an SD Card in seconds.
Step 1: Required Apparatus
- 1, Arduino Yun
- 1, Micro SD Card and SD Card adapter (max 32 GB)
Step 2: Preparing the SD Card
The Arduino Yun requires an SD card formatted with MS_DOS 16 or 32 bit. You will also need one or more files on the SD card for the Arduino to read. Here is a guide to getting all of that done. This tutorial is designed for an Apple Comput
Step 3: Setting Up Dropbox
These images will guide you through the process of setting up Dropbox, note that you need a Dropbox Account.
Step 4: Setting Up Temboo
A Temboo account is also required to operate this project, you can create one for free. Fallow the images below to set up Temboo.
Step 5: Acknowledging the Code
This simple code is composed of four main sections:
- Read File
- Format Buffer
- Connect Temboo
- Upload File
Each of these sections will be further explained below.
- Read File
File dataFile = FileSystem.open("/mnt/sd/datalog.txt", FILE_READ); // open the file as read (must be present)
if(dataFile) // if file is present
{
Serial.println(" Success - File Open");
Serial.println("Reading File Content");
while(dataFile.available())
{
data = dataFile.read(); // read incomming bytes
dataString = dataString + data; // store them to string
}
}
This section of code opes the file and reads its contents if the file is available. The contents are then stored to a String Variable.
- Format Buffer
char valueToSend[120];
dataString.toCharArray(valueToSend, 120); // convert string to char
these are two simple lines of code which covert the resulting data stored in a String Variable to a char array, Temboo requires a char array to be able to send non-encrypted data.
- Connect Temboo
TembooChoreo UploadChoreo; // initialise the choreo
UploadChoreo.begin(); // begin the choreo
UploadChoreo.setAccountName(TEMBOO_ACCOUNT);
UploadChoreo.setAppKeyName(TEMBOO_APP_KEY_NAME);
UploadChoreo.setAppKey(TEMBOO_APP_KEY);
UploadChoreo.addInput("Path", "/YunSD.txt"); // the path to the file
UploadChoreo.addInput("FileContent", valueToSend);
UploadChoreo.addInput("ContentType", "text/plain"); // text/plain does not require encription
UploadChoreo.addInput("AccessToken", DROPBOX_ACCESS_TOKEN); // edit in header file
UploadChoreo.addInput("Mode", "overwrite"); // if file exists; overwrite
UploadChoreo.setChoreo("/Library/Dropbox/Files/Upload"); // identify the choreo to run
This block of code tells the choreo to begin, initialises the choreo and configures the inputs.
- Upload File
UploadChoreo.run(); // run the choreo
A single line of code that tells the choreo to run and the file gets uploaded. The code is very simple in the project.
Setting Up the Variables
In this project there is a header file named "TembooAccount.h" which has to be configured to the user's preference. the Temboo Account credentials are received when the user creates his/her Temboo Account and creates their first app. If you wish to retrieve this data, go to Temboo and open an example. Your credentials are stored in the header file provided with the code.
Libraries
- Bridge - copyright (c) Arduino LLC under the GNU Lesser General Public Licence, this library is in the public domain.
- File IO - Copyright (c) 2013 Arduino LLC under the GNU Lesser General Public Licence, this library is in the public domain.
- Temboo - Copyright (c) 2017 Temboo Inc. under the Apache 2.0 Licence. View this licence
Final
The last step is to connect your Arduino Yun to a computer and upload the code below, ensure that the SD Card is inserted before continuing. Everything is automatic, in about 30 seconds, the Bridge will load and the file will be uploaded to Dropbox. You can change the name of the file to upload manually. You are all set.
BackgroundI created this project because I thought it would be nice to back up a file to Dropbox by just simply inserting an SD card into an Arduino Yun. I decided to create another project using the Yun's built in SD Card module, after Blynk Terminal to SD Card because it is fun and easy to use the module.
Comments