Portable temperature, humidity and light ambient datalogger. Part 2

Part 1

Software

The software for the datalogger is download section (PIC_DATALOG_V00d). I use Mikroc Pro PIC compiler from mikroElektronika, the libraries of this compiler are great! Especially the FAT32 library, it allows to manage the micro SD card on a very easy way. Current version is 00D, and I’m still working on it. I know there’re many things that I can optimize, process that could be simpler…..but the board is still on debug!

There’re many considerations on this SW, I’ll try to explain some important points, but if you have any doubt with something, please comment it and I’ll try to answer!

At power-up, system configures and check all the peripherals: configure GPIO’s, UART, I2C, SPI, RTC status and set the time for the files on the SD card. Also reads the device ID, a parameter that identifies the datalogger (value stored in microcontroller EEPROM) (Figure 14).

At power-up datalogger configures and check all the peripherals.
Figure 14. At power-up datalogger configures and check all the peripherals.

Files on the SD has the following name format: yyyymmdd.ext . That is, year, month and day. The extension file is initially ‘000’. Every new day, system creates a new file with the same format, so every 24 hours, you’ll have a new file.

System has defined a time to update all the parameters and store it on the SD. This time is configurable by user, and can go between 1s and 999s. When a update event occurs, the system reads all the sensors and parameters and store data on the SD.

With the P1 pushbutton, you can put a mark on the file. That means that in this moment, you force a update event, so sensors are read and store on the SD card (Figure 15). With the P2 pushbutton, you can make a new file. Filename will be the same but extension changes to 001, 002….and so on. Every push on P2 makes a new file (Figure 16).

With the P1 pushbutton, you can put a mark on the file.
Figure 15. With the P1 pushbutton, you can put a mark on the file.
 
With the P2 pushbutton, you can make a new file.
Figure 16. With the P2 pushbutton, you can make a new file.

Data fomat: on the SD card files. you’ll find a new file for every day. This files has plain-text format and separated by ‘;’, for an easy import with excel or similar software (Figure 17). File has the following fields:

  • .Software name and version
  • .Device ID
  • .Time (s) when system updated the data and store it
  • .Date
  • .Time
  • .Event (Power Up, Mark, Update)
  • .Battery voltage
  • .LDR value
  • .DS18B20 temperature (now it’s fixed because I don’t read it)
  • .HDC1050 temperature (in ºC)
  • .HDC1050 humidity (%)
  • .Rest of bytes are reserved for future uses.
Datalogger: SD card data files format.
Figure 17. Datalogger: SD card data files format.

For example, Just a fast graphic of the battery level across 4 days (Figure 18).

Figure 18. Datalogger: fast graphic of the battery level across 4 days.

Every days a new file is created. To merge all the files in only one to easy import into excel and make graphics, you can use the following command: type *.* >> out_file.txt

Commands

As you can see, I implement a command-line commands to have info or set parameters of the datalogger. To connect with the board, just plug the USB cable and install the virtual COM port driver of the MCP2221. I use Tera term software for this. Baud rate is 9600 bps, 8, N,1. Important! Set ‘Local Echo’ to see the commands you send to the board. The command list I implement on the board is the following one:

  • reset -> Perform a software reset of the datalogger
  • set time -> Update time of the board (hour and minutes, seconds set to 0).
  • set date -> Update date of the board (year, month, day and day of week).
  • set update -> Set the time to update the system (from 1s to 999s)
  • set id -> Set the datalogger ID (from 000 to 999)
  • temp -> Perform a HDC1050 temperature measure
  • hr -> Perform a HDC1050 humidity measure
  • ldr -> Perform a LDR measure (mean of 10 samples)
  • batt -> Perform a battery voltage measure (mean of 10 samples)
  • date -> Shows the datalogger date
  • time -> Shows the datalogger time
  • id -> Shows the datalogger identification
  • upd -> Shows the datalogger update time (in s)

Downloads

Datalogger source code and .hex-file - download

jechavarria.com

You may have to register before you can post comments and get full access to forum.
EMS supplier