Arduino data logger - Software

The Arduino software is required to collect from the
currentand
voltage
ADC inputs and the
wind
and
frequency
digital inputs.
I wanted a simple output data format so used comma
separated value (CSV) text and streamed this back to a laptop PC over the USB link where it
could be written straight to a file. The file can then be easily viewed in any spread sheet.

I also needed a means of controlling the system so used
the same text format commands to start and stop collection. This made it possible to control
the collection by typing commands into the Arduino serial monitor and view the data in the output screen.
While this made development and use easier the down side of this approach is there is a greater
overhead formatting and transmitting the data compared to a binary format.
In the end I wrote a simple GUI in the Processing language to control the Arduino, display the data and manage the CSV files.

The ADC inputs (voltage and current) are rectified AC so I wanted the sampling of these to be as fast
as possible. The output power is the product of the current and voltage so ideally this should be
calculated for each sample. The average current, voltage and power needs to accumulated and reported
every time a data point is required.

The frequency measurements are calculated by timing the number of rotations in a given period.
The count and time measurements are driven from an interrupt generated when the digital input changes state.
When a report is required the frequency is calculated from the difference between the first and last
interrupt times divided by the number of interrupts.

The readings from the ADCs and frequency calculation are the raw input values and need to be adjusted
to get the calibrated reading. The raw values are used in a polynomial
(e.g. Y=A+Bx+Cx2+Dx3+...) where x are the raw values, the coefficients A,B,C,D, etc are the
calibration values and Y is the calibrated (cooked?) result.
The coefficients can be found by taking a number of samples in a spread sheet and generating a linear or
polynomial trend line with equation.

Initially, the data sampling was made in the software main loop and timed using delays to poll for the next
collection cycle. I tried various collection rates but typically the ADCs sampled at 2m/s intervals and
data was reported every second with the ADC data samples being averaged.
The problem with this was that the calculation, formatting and sending of the data was taking up several sample cycles.
I then changed the code so the sampling was driven from an interrupt handler driven from the hardware timer
(see Arduino timer3 library).
The ADC's were simply read and the data put into a FIFO (First in first out) buffer. The FIFO buffers
were read and data processed in the main programme loop. Using this method the ADC sampling could be run at
2ms interval (500 per second) without over running the FIFO buffers. Changing the interval to 1m/s (1000 per second)
resulted in data being lost.

There are a large number of additional data values that can be derived from the four channels of data.
These could be added during the post processing of the CSV file in a spread sheet but it is quite useful
to generate them at run time so they can be monitored. This causes an additional load on the Arduino
processor and transmission to the PC but was a convenient point to do the processing. The channels and data
collected so far are below. It is very easy to add or remove channels in the Arduino sketch so these might
be removed if I want to reduce the size of the the output files in future.

Time stamp

Time from start of Arduino board (seconds)

DC Current

Average raw ADC value

Average calibrated value(Amps)

RMS calibrated value(Amps)

DC Voltage

Average raw ADC value

Average calibrated value(Volts)

RMS calibrated value(Volts)

AC Frequency

Calculated frequency value(Hertz)

Calibrated frequency (e.g. AC current to turbine frequency)(Hertz)

Calibrated frequency * 60 (RPM)

Wind speed

Calculated frequency value(Hertz)

Calibrated wind speed(m/s)

Change in speed since last collection (m/s)

Wind power - The air density and area of the turbine need to be input for the calculation (watt)

Generator power - This requires the voltage and current samples and the resistance of the alternator circuit.

Output power (voltage * current) (Watts)

Input power(approx) = output power + resistance * current2(Watts)

Efficiency - This requires the wind power and generator power samples.