================================================================================================================================================

Wednesday, July 4, 2018

UART or SD Card based 8-Channel Data-logger with temperature log




Hi Friends,
        here is one more data-logger circuit, which will be useful for some who have not much ventured into the ADC for datalogging or RTC or i2c communication, etc. This one is based on ATmega32. It has 8-channel 10-bit ADC. Hence, providing us with 8-channels with 0 to 5V voltage level measurement. The circuit also has on-board RTC (based on DS1307) to log the data with time-stamp. Data is logged via UART or using microSD card. The circuit has 3-pin UART connector, which can be used to connect to PC/laptop using UART(TTL) to USB serial converter, commonly available in electronic markets (UART setting: 38400-1-N-1).
      Also, there is a thermometer IC, DS1621, which is connected via i2c (along with the RTC IC) and provides temperature measurement from -55 to +125 Deg. C. The temperature is also sent along with the voltages to the UART for logging.
     (The logging with microSD card is added later in this post).
    The circuit schematic is given in the following figure (pdf file can be downloaded from here):


     At power on, the current date and time are displayed on the first raw of LCD. The temperature and the logging ON/OF status is displayed on the second raw. A green LED is also turned ON as an additional status of the proper power-up of the microcontroller .
     The data measurement can be started anytime by pressing the 'SET' button (keep pressed till the red LED turns ON). The recording ON status is displayed on LCD as well as by the glowing red LED. During this recording, at a regular interval (as defined in the code), the microcontroller gets the temperature from DS1621, measures the 8 voltages connected to 8 of its screw-terminals, w.r.t GND on the 9th terminal (as shown in the schematic), and forms a string which includes line number, time (hh:mm:ss format), temperature and the 8 voltage values, in a comma separated format. This string is then sent to UART, which can be logged into a file or seen on a terminal program in the PC/laptop using the serial-to-usb converter.
     The operation is shown in the following screen-shot of the Proteus simulation (in the simulation, the temperature set in the IC and displayed by the LCD has difference of 1.5C, as the code applies the correction factors read from the IC to the temperature reading and then displays it, which represents the actual temperature):


     (Note: The Proteus simulation files are included in the source code folder download at the end of the post).
   
     The circuit in operation, with logging ON and OFF, is shown the following pics:




        The actual UART output captured on a terminal of the Atmel Studio during the logging ON,  is shown in the left side image, where temperature shown is 30.3 C, channel-2 was connected with +5V (VCC) and channel-7 was connected with the Li battery cell of the RTC. Rest of the channels were kept open at the screw-terminals.

      The RTC date and time can be changed using the three push-buttons, similar to the procedure shown in my previous post of the RTC based relay-control. The procedure is given here:








 

For setting RTC Date/Time:

  1. Press 'SET' button and Power ON the circuit, keeping the button pressed while the circuit is starting.
  2. "RTC Setting.." message will be displayed on the first row of the LCD.
  3.  Release the 'SET' button "Date: XX" will be displayed on the second row of the LCD, where XX is the existing current date as per the RTC.
  4.  Press 'UP' or 'DOWN' button to increase or decrease the Date. When desired date is displayed, press 'SET' button to store it
  5. "Month: XX" message will be displayed, where XX is the current month as per the RTC
  6. Press 'UP' or 'DOWN' button to increase or decrease the Month. When desired month is displayed, press 'SET' button to store it
  7. "Year: XXXX" will be displayed, use 'UP'/ 'DOWN' buttons to change the year and then press 'SET' button to store the year value
  8. Then "Hour: XX" will be displayed, set it as per the previous steps and also set next "Minutes: XX" similarly, and store using 'SET' button.
  9. When the Minutes is set, "RTC Setting" mode is over and normal operation resumes, where the LCD will display Date and time in the first row and temperature and log:OFF status in the second row.

 

  • Data-logging with SD card 

         (Updated: Sep 2021)



Above image shows the logging with microSD card. A commonly available microSD card module (mostly used with Arduino) is used here. Please note that this module interferes with programming of the board on AVRISP port (which is not a problem with Arduino as it uses the USB bootloader programming and not AVRISP), so it's necessary to remove the card while loading the code. You can find solutions/modules online to overcome this issue.

Following images show the generated .csv file in the SD card and also opened file in MS-Excel. The logging was done without any voltages connected to the ADC channels, so the voltages are 0, but the  temperature log can be seen along with the time stamp. You can view another log file here, where I've connected the 8 channels to 3V RTC battery and VCC (~5V) line one by one (cross-coupling of signal to nearby free channel is also logged there).


The file name format is: DDMMYYNN.CSV, where DDMMYY is the date of logging and NN is the file number. After power on, the file number is set to 00. Every time logging is started and then stopped, the file number increments, hence, new file is created. As file number is a 2 digit value, max 100 (00 to 99) log files can be created after power on in a day, after that it will send error message. I guess you may not need to do the logging ON and OFF more than 100 times a day (after single power ON), but if you do, the file name string can be tweaks as necessary.

After Power off and on, when datalogging is started, the code looks if the filename is already existing or not, if it is, it will change the log-file number (and hence, name) to next available number, and so on. So, always a new file is created whenever logging is started.

  • SD card datalogging using FatFS library

I'm  also uploading here the data-logging project code with a more generic FatFs library, which has been highly standardized and is officially supported/included by many IDEs/ Development boards/ Platforms (like Arduino, mbed, STM32, Keil, etc..). I've just replaced my FAT32 (and SD routines) libraries with FatFs modules. This also has been tested and the project folder is included in the downloads (Sr.No.2).

The datalogging and RTC setting procedures are same for all the above options, as explained in the earlier paragraphs. Functionality or user operations are same, only internal library change is there. Data-logging option with only UART or only SD card or both can be selected by proper macro selection in the main.h file. 

Note: You can connect UART while operating if you need to see the status/error messages for any troubleshooting. Otherwise, UART is not necessary if logging is done in SD card.

The circuit hardware is not much complicated, can be assembled on a general purpose PCB also. I'm including here the Gerber files also, along with the other downloads, if it's required.


Downloads:
  1. Source Code for SD/UART Logging (with FAT32 Lib) (Atmel Studio-7 project)
  2. Source Code for SD/UART Logging (with FatFs Lib) (Atmel Studio-7 project)
  3. Proteus Simulation for UART datalogging
  4. EAGLE Schematic and Board files
  5. Gerber Files
Datasheets: ATmega32,   DS1307,   DS1621
 
You may also check out my post here, where I started on SD cards, for more info/ further reading/ references.

Enjoy!!

Regards,

CC Dharmani
ccd@dharmanitech.com