Part 1: You are here.
Note: This project uses a Tiva LaunchPad board, but it works with the MSP432 LaunchPad board too with some modifications by martinvalencia - click here for the MSP432 modifications to this project.
This was a quick project to build a data logger, useful around the lab or elsewhere. So quick it can be built in a couple of hours, and with dozens of uses. The facility to log events or values over time is extremely important for many projects - it is a useful Swiss army knife to have around when needed. It uses a which is a small board from Texas Instruments containing an ARM chip. It can be programmed just like an Arduino - download the Arduino-like software, write your Arduino code in a single window, and transfer it to the board using the supplied USB cable.
It is not hard to justify purchasing a data logger. Frequent, accurate data acquisition will greatly help in understanding the environment indoors or outdoors using measurements from sensors. A better understanding results in better products and solutions. Productivity will be improved immensely with the capability to record information automatically over a period of minutes, hours or days.
This logger is extremely easy to use, and so low cost that many could be created. Plug in an SD card, plug the board into a 5V supply (e.g. a phone charger) and it will automatically start storing analog voltage measurements to the SD card in a file. The analog input could be connected to a sensor. It will also record temperature. Everything is time-stamped (in part 2, (part 2 is now available, click here) - part 1 saves data with no time-stamp).
The diagram below shows the solution overview. A (less than £10) forms the heart of the data logger. SD card capability and (in part 2) a Real Time Clock (RTC) will be attached to it. Any initial configuration will be via serial port (USB serial) using a PC, and then the PC is no longer required – the logger will be controlled via on-board buttons to start/stop logging to the SD card.
The hardware design of the SD card portion of the data logger is covered below. The full source code is attached to this post too.
When run, this project logs analog data to the SD card without a timestamp. The RTC time-stamp functionality will be covered in part 2 in a day or so.
We wanted a solution that could run untethered from a PC and I considered a few platforms (including the RPI and BBB) but eventually settled on a Texas Instruments LaunchPad. It is low cost yet powerful enough to capture and store data.
For my particular use-case low power consumption was not a concern, but a quick solution was. I didn’t want to spend a lot of effort or money developing a data logger. I just wanted something that would work.
The Tiva range of microcontrollers from TI are ARM Cortex-M4 based. Within the Tiva family there are two categories. I chose the lower-end here, for which the Tiva LaunchPad costs about £10.
The LaunchPad does not contain an on-board SD card, but it was quick to add one onto a piece of stripboard. First, an and a piece of stripboard were acquired (ignore the green board in this photo, it was not needed):
The pinout from an existing board http://doc.43oh.com/The_Card_Reader_SDCard_BoosterPack intended for a different LaunchPad was followed, to retain some standard. The pinout is listed below.
Launchpad pin SD card pin Description ------------- ----------- ----------- J1-1 4 VDD (3.3V) J1-7 5 SCLK J1-8 1 CS J2-1 6 GND (VSS1) J2-6 2 MOSI J2-7 7 MISO
This is the SD card pinout:
Header pins were soldered to interface with the required LaunchPad pins as shown in this photo:
Then the SD card holder was soldered onto the underside and wired up. It really is simple. A 100nF capacitor was also soldered into place across the supply rails, close to the SD card holder. It is the only other component required to build the SD card functionality.
After this hardware was complete, it was time to move onto the software.
This was easy. An existing SD card implementation was taken and adapted slightly to suit the Tiva LaunchPad board. The source code is attached to this post. The development environment is called Energia. If you’re not familiar with it, it is near-identical to Arduino’s development environment. The functions are the same. If you can use an Arduino then you can use a LaunchPad. After having studied it, the conclusion is that the main difference is the color of the development environment:
The software attached to this post consists of two parts; an SD card support library, and the application code that implements the data logger. The SD card support library was saved into the folder energia/hardware/lm4f/libraries, so that (say) the file SD.h could be found at energia/hardware/lm4f/libraries/SD/SD.h
The application code is in a single file called sd_logger.ino and it can be saved elsewhere. Using the Energia development environment, the code can be compiled and uploaded to the board. For debug purposes, a serial port monitor can be used. This is part of the Energia development environment. The serial communication occurs over the USB connector that is part of the LaunchPad board.
Using the Logger
With the board programmed, power is applied. The logger will now wait until the on-board switch SW1 is pressed. Once pressed, the green light turns on to indicate logging, and it will record an analog value (analog input is pin J1-2 on the LaunchPad board) once per second to the SD card. Optionally, the data can be observed in real time as well, by plugging in the USB cable into a PC and using any console/terminal software (such as PuTTY).
Here is some example output on the console:
Initializing SD card...card initialized. Creating filename DAT1.TXT Starting logging... 2511, 327, 322, 327, 311, 2240, 2143, 322, 323, 321 323, 311, 323, 322, Logging stopped.
Pressing stop (SW2) and then start (SW1) will generate a new file:
Creating filename DAT2.TXT Starting logging... 311, 326, 320, 311, Logging stopped.
The saved files contain one value per line with no additional text, ready for importing into Excel.
This was a trivial software logger, but the information here could be useful to save any data to an SD card. The development environment that was used for the Tiva Launchpad is near-identical to the Arduino development environment therefore it should be an easy and smooth transition for Arduino users.
Part 2 (click here) will provide useful time-stamping functionality and a serial port menu for configuration.
The code is attached below.
sd-logger-source.zip 69.7 KB