I needed a data logger which could take a stream of serial data and record it onto an SD card. To do this I based the hardware on the DataDuino and changed the microcontroller code.

This is an overview of the idea and the arduino code required to implement it.

This was designed to work with the pedal power equipment I have been designing.


A number of the devices I have been creating recently stream data via a serial output. This data can then be used with other devices, such as displayed on an LED display or stored onto a computer (via a USB-serial converter). Sometimes I need a stand-alone data recorder for this serial data stream.

I created the DataDuino to record anaolgue and digital data onto an SD card. This hardware can be used to read serial data and record it to the SD card.

SD write cycles

One issue with the SD card is that it will only last for a certain number of write cycles – typically 100,000. While that seems like a lot, if data is written once per second (86400 samples per day) then an SD card will only last  just a bit over 1 day. To prevent this SD cards usually have wear-levelling built in which helps to even out the number of write cycles over the whole size of the card. Writing data once per second onto a 2GB SD card typically gives a SD card life of around 100 days.

In this situation I am not recording data 24 hours a day. It will be taking data only when the pedal generator is in use. This means that I do not need to worry as much about the SD write cycles in this application.

If I was creating a data-logger which would work 24hrs a day, then I would need to think about this issue and perhaps write the data in ‘chunks’ at set intervals. This would reduce the write cycles.

Another option would be to use a much larger SD card – these have more memory therefore, with wear-levelling, the card would last longer.

Code flow overview

Rather than take analog and digital readings whenever there is a write pulse from the clock, I want the code to monitor the serial port. When serial data arrives we want to check that it is in the correct format, strip out the useful data, store it into EEPROM and then write it to the SD card in chunks when the EEPROM has filled up.

Data will be written using a version of LLAP (Lightweight Local Automation Protocol) with a unique data reference. We want to strip out the data reference, the type of data, the value of the data and also add a timestamp from the real time clock.

This unit has been designed to record from the power log unit. This outputs data at 115200 baud via the serial port. The data is streamed every second and takes the format of voltage reading, current reading , power reading.

I save all three values and store them onto the SD card. These are saved along with a timestamp. A new file is created each day.

Here are some photos of the set-up:

The DataDuino with just two input wires  – ground and data (attached to Rx pin). Power was provided by batteries.

Here you can see the three LLAP messages sent every second and then the line written to the SD card.

Arduino code for the Dataduino

The Dataduino is an Arduino-based datalogger. It is available here. The following code has been written for the dataduino to save serial data onto pin 0 (the Rx pin). This code is also available via my GITHUB repository.

This code seems to work quite well and stores the serial data to the SD card. Every so often there is an issue with the voltage reading, which could be due to the device which sends out the data, rather than this serial data recorder.

Maybe this code would be useful to you? Please feel free to adapt and use for your own use. You will need to include the RTC PCF8563 library (which must be downloaded) and the SD card library (which is included within the Arduino IDE).


One response to “DataDuino – Serial

  1. Hello,

    Would it be possible for us to get one unit of your I-V tracer?
    I have a 300 watt CPV module to test.
    Please let me know the cost and lead-time if available.

    Talk to you soon.

Leave a Reply

Your email address will not be published. Required fields are marked *