Data Drop with Arduino Yun

This tutorial shows how to upload data directly from an Arduino Yun to Data Drop, using the Arduino Device Driver. To interface with Data Drop, the Arduino Yun needs to be connected to the internet. Note that all of this functionality is only compatible with the Arduino Yun and will not function with the Arduino Uno.
Setting Up the Yun for Internet Connectivity.
The easiest way to set up the Arduino Yun is to connect the Ethernet cable jack to the network. This requires no setup on the Yun and is also the most reliable form of network connection. Note that the Yun has to make outgoing requests to the internet, so your network administrator may need to allow the access through your firewall, if it exists.
To set up the Arduino Yun to use a wireless connection over Wi-Fi, you will need to set it up to connect to your wireless network. The manufacturer provides documentation online on how to do this at this link.
Uploading the Sketch to the Board
Now that the Arduino Yun has been set up to connect to the internet, the next step is to upload the custom Wolfram Language sketch to the board. This sketch is what enables the Arduino Yun to communicate with Wolfram Language and also provides Data Drop functionality, in the form of functions that upload values to Data Drop.
First, open a connection to the device with DeviceOpen, specifying the option "BoardType""Yun" to enable Yun support.
By default, this will upload to the device the custom Wolfram Language sketch, as the option "InitialUpload" defaults to True. This enables the special function DatabinAdd on the Arduino.
A prerequisite to uploading to Data Drop is having a Databin to upload the data to. This can either be a preexisting databin or a new one made with CreateDatabin.
Adding Data with DeviceExecute
The DatabinAdd function will add the current value of the specified pin to Data Drop in the bin. To upload to the bin, either the "UUID" or the "ShortID" of the bin, or the bin itself is necessary as the value of the option "Databin". Additionally, the pin to read from has to be specified. It can either be specified with the option "Databin" in DeviceExecute, or it can be configured as a default bin with DeviceConfigure.
Using DeviceConfigure to specify a "Databin" requires a re-upload.
Now calling the function does not require a "Databin" to be specified.
Scheduling the DatabinAdd function works too; this is done asynchronously from the Wolfram Language kernel and will continue if the Wolfram Language session is exited. This is done with the option "Scheduling". Here, every three seconds for a maximum of 10 times, the value of pin 4 will be uploaded to Data Drop.
When uploading to Data Drop, by default the name of the key uploaded is of the form "DigitalPinX" or "AnalogPinX", depending on what type of pin is read from. This can be changed with the option "Key".
Automatically Uploading to Data Drop
Data can be automatically added to Data Drop by uploading a "BootFunction" to the Arduino Yun. This "BootFunction" is run immediately as soon as the device turns on. This enables you to deploy to the Arduino Yun a task to upload to Data Drop, then remove the device and deploy it in the field and have the device just start uploading on its own.
This will upload a single value from pin "A5" as soon as the device turns on.
It is also easy to schedule this to run on a specified schedule after turning on with the "Scheduling" option. Here, the automatic upload is scheduled to be run every 60 seconds indefinitely.
Adding Custom Data Values to Data Drop
It is also possible to upload custom data to Data Drop from within C/C++ code functions uploaded to the Arduino Yun with the "Functions" option to DeviceConfigure.
There are three functions prototyped in the sketch that can be used to upload custom values to Data Drop: DatabinIntegerAdd, DatabinRealAdd, and DatabinStringAdd, which all upload val to the Databin specified by binID, with the Key of keyName. These allow you to code custom functions that upload values other than the pin values to Data Drop.
void DatabinIntegerAdd(char * binID, char * keyName, long val)
void DatabinRealAdd(char * binID, char * keyName, double val)
  • DatabinRealAdd uploads Real numbers to the Databin.
  • void DatabinStringAdd(char * binID, char * keyName, char * val)
  • DatabinStringAdd uploads String numbers to the Databin.
  • For example, if you want to calculate the average of a pin value and upload the average, a custom function can be written to do this.
    After uploading, this function can be called normally as any custom function would with DeviceExecute.
    It can even be scheduled on demand with the "Scheduling" option. Here, this upload will take place 45 seconds in the future after evaluating.
    This function can also be easily adapted into a "BootFunction" for automatic running as soon as the device powers up. The "Scheduling" option here configures the function to be run every 30 seconds.