Build a Arduino Based 4 Channel Python Data Logging System (DAQ) to CSV Text File for Beginners

by xanthium-enterprises in Circuits > Arduino

1283 Views, 2 Favorites, 0 Comments

Build a Arduino Based 4 Channel Python Data Logging System (DAQ) to CSV Text File for Beginners

Build a Arduino based 4 channel Python 3 data logging system (DAQ) to CSV text file for beginners

In this instructable,

We will build a low cost multi channel data acquisition system using Python and Arduino UNO board that will log and save data to a CSV (Comma Separated Values) file on the disk.

The system can monitor temperature data from 4or more independent sources at the same time and log the data to the disk.

The system will use an Arduino and an analog front end based on LM324 opamp to measure temperature from 4 LM35 temperature sensors.

The analog values are digitized by the Arduino UNO's (ATmega328P) 10 bit ADC and transmitted to a PC or MAC using Virtual Serial Port communication.


Supplies

arduino-python-pc-temperature-data-logger.jpg
  1. Arduino UNO
  2. LM324 4 Channel Opamp Amplifier Board
  3. Python3 Interpreter
  4. Windows10 or Linux OS

Source Codes

src.png

What Is a CSV or Comma Separated File

python-csv-file-format.jpg

A comma-separated values (CSV) file is a delimited text file that uses a comma to separate values. Each line of the file is a data record. Each record consists of one or more fields, separated by commas. The use of the comma as a field separator is the source of the name for this file format.

CSV file Structure for the data logger

The data will be stored in a CSV file by the python code.Here we will use  , (comma) as the delimiter.

The data will be stored in the following order 

No,Date,Time,AN1,AN2,AN3,AN4

File name for the .csv file is auto generated using current date and time information at the time program is run.

A Python 3.x.x script running on the PC will receive the data and log the time stamped data into a CSV file on the disk.  



Block Diagram of Arduino Python Datalogger System

arduino-python-pc-data-logger-system.jpg

The system comprises of 4, LM35 temperature sensors connected to a LM324 amplifier board which acts as an analog front end for the Arduino board.The Analog signal from the amplifier board are digitized by the ADC on the Arduino and send to a PC MAC or Linux computer.

A Python script running on the PC will monitor the serial port and receive the temperature values from the Arduino.

The script will write the received values to a CSV file 

You can terminate the script by using the CTRL + C Keyboard combination


Hardware Connections for the Python Data Logging Program Using Arduino

Building Hardware of 4 channel Arduino LM35 temperature data acquisition system using Python

Hardware setup is shown above,

It consists of 

  1. Four (4) LM35 temperature Probes
  2. 4 Channel LM35 signal opamp amplifier board
  3. Arduino UNO
  4. Laptop PC running Windows/Linux OS system

The weak signals from the LM35 temperature sensor probes are amplified by the opamp amplifier by a gain of 3.44 and is connected to the ADC inputs of the Arduino UNO.

You can check out a short video on building the LM35 temperature probe here

The Output

  1. AN1 of amplifier is connected to A0 pin of Arduino
  2. AN2 of amplifier is connected to A1 pin of Arduino
  3. AN3 of amplifier is connected to A2 pin of Arduino
  4. AN4 of amplifier is connected to A3 pin of Arduino


Explanation of the Python Data Logger Code

python-data-logger-software-architecture.jpg

The Python data logger code connects to a given serial port and queries the connected Arduino for temperature values.

The Python code sends the character '$' to the Arduino.

The Arduino replies with 4 temperature values in the format Temp1-Temp2-Temp3-Temp4.

The Python code then reads these values from the serial port and writes to a CSV file.

 

User presses CTRL + C key combination which generates a SIGINT signal.  SIGINT signal is captured by the signal handler which in turn makes the sentry variable False, resulting in code exiting from the loop.

Full Explanation of the Python data logging code can be found here


Running the Python Data Logger Code on Windows

python-data-logging-software-win32.jpg

Running the Python Data Logger Code 

Make sure that you have Pyserial installed on your system.

If you are not familiar with Pyserial, Check our tutorial on using Pyserial