Build your own Ubuntu Linux Data acquisition and logging system using Python and Arduino
Here we will build a Python based acquisition and logging system that saves temperature values from an Arduino to a Linux System Eg Ubuntu in CSV (Comma-Separated Values)format .
Python is a great language for data acquisition and logging applications in research and academia due to its readable syntax, diverse libraries (e.g., requests
, pySerial
), cross-platform support, community resources, device integration, and database connectivity
combine that with the flexibility of an Arduino, You got yourself a cheap reliable, opensource data acquisition system for hobbyist and academic usage.
Original Article can be found here
Python Data logger running on Linux System
Source codes
All the Source codes can be downloaded using the below link.
All the Source codes can be downloaded from our GitHub repo using the below links.
Data storage format
The data acquired by our Python datalogging system is stored on the Linux system in the form of a CSV text file .
CSV stands for “Comma-Separated Values.” It is a simple and widely used file format for storing tabular data, such as spreadsheets or databases, in a plain text format. In CSV format, each line of the file represents a row of data, and within each line, values are separated by commas or other specified delimiters
In our case we will use a comma , delimiter as shown below
You can change that in the python code to other delimiters like TAB,SPACE or | or comma,
Block diagram of the System
The provided Python data logging script establishes a connection with a specified serial port and initiates communication with an attached Arduino to retrieve temperature values.
The Python script sends the character ‘$’ to the Arduino over the established serial connection.
Upon receiving the ‘$’ character, the Arduino responds with four temperature values formatted as Temp1-Temp2-Temp3-Temp4.
Subsequently, the Python script reads these temperature values from the serial port and proceeds to save them into a CSV (Comma-Separated Values) file.
This CSV file serves as a structured data storage solution, allowing the recorded temperature values to be easily managed and analyzed in the future.
Hardware Setup
The hardware arrangement is depicted above, consisting of:
- Four LM35 temperature probes
- A 4-channel LM35 signal opamp amplifier board
- An Arduino UNO
- A laptop PC operating Windows/Linux OS
The opamp amplifier strengthens the weak signals from the LM35 probes with a gain of 3.44, linking them to the ADC inputs of the Arduino UNO.
You can watch a brief instructional video on constructing the LM35 temperature probe .
The resulting connections are as follows:
- Amplifier’s AN1 is linked to Arduino’s A0 pin.
- Amplifier’s AN2 is linked to Arduino’s A1 pin.
- Amplifier’s AN3 is linked to Arduino’s A2 pin.
Executing the Python CSV Datalogger on Linux
- Fetch the relevant Arduino C code from the repository and upload it to the Arduino board.
- Establish a connection between the Arduino board and the computer.
- Identify the accurate serial port for the Arduino (details provided earlier); typically named ttyACM0 but subject to change.
- Attach the 4 temperature sensors to the Arduino board using LM324 opamp board .
- Launch the Python code using the subsequent command.
python3 your_python_logger_code.py
Upon entering the port name,
Make sure you provide the complete name, such as: /dev/ttyACM0
.
Following this, the system will commence data logging, as illustrated in the below image .
You can stop the the data logging by pressing CTRL + C.
After the logging is stopped you can find the logged data in the form of a CSV text file on the same directory as the python script.
References
References
- Serial port programming on Windows using Python and Pyserial
- Serial port programming on Linux using Python and Pyserial
- How to solve the serial port permission denied error on Linux while accessing Serial port.
- Build your own 4 channel Python and Arduino based Data Acquisition and Logging system for measuring temperature
- Operating System Signals (SIGINT,SIGBREAK) programming using Python on Windows and Linux Systems