Arduino Utils

Wednesday, 28th October 2009 - 13:44 GMT

The Arduino Utils package is made up of 3 small utilities, arduino, arduino-send and arduino-read. The main utility is the arduino one which is responsible for communicating with the arduino device and handling the requests for data. The other two utilities are simple helper applications for reading inputs and sending data to the arduino device. Each utility can be downloaded separately or you can download a ZIP file containing all the utilities along with a compile script. All utilities, and the whole package, are released under the GPL v2 license and can be downloaded at the bottom of the page.

The arduino daemon

The arduino utility is actually a daemon that is designed to run 24/7 and will read the input from the arduino device. The main purpose of the daemon is to create a static interface to the arduino device so if the code changes on the arduino (to add more data readings for example) then any programs reading from the arduino device won't need to be recoded. The arduino daemon uses a single carriage return character ("\r") to separate the data inputs and a line feed character ("\n") to separate the rows of data. There is some sample code demonstrating how to format the data from the arduino device included in the source code for the arduino daemon.

The arduino daemon protocol is very simple. The first byte signifies which inputs you wish to receive the data for, this is a bitmask so to read inputs 1 and 2 you would send 0x03. The input values are then sent one by one on a new line until the socket connection is terminated. If you are just sending data to the arduino, the first byte sent must be of the value 0x00. The remaining data is a byte to indicate the length of the data followed by the actual date itself.

To compile the source code, providing you have the necessary compiler tools, simply run:

Bash code:
  1. g++ arduino.c -o arduino -lpthread

The arduino-send utility

The arduino-send utility is very basic and to send the data to the arduino you simply execute './arduino-send <the data here>'. To compile the source code, providing you have the necessary compiler tools, simply run:

Bash code:
  1. gcc arduino-send.c -o arduino-send

The arduino-read utility

The arduino-read utility is also rather basic, simply specifiy the number of the input (or inputs) you wish to read and the utility will start reading off the inputs, one by one, on a separate line. Quick example, to read inputs 1 & 2, simply execute './arduino-read 1 2'. To compile the source code, providing you have the necessary compiler tools, simply run:

Bash code:
  1. gcc arduino-read.c -o arduino-read

Attached files