Intro: Raspberry Pi - Data Logging
In this project, we will learn how to logging data from Raspberry Pi using Python and Excel which collect data and save the output of the collection or analysis.
It’s a quite quick project and can be used either on its own or part of something bigger. Check it out >> Integrated Weather Station(IWS).
Step 1: List of Material
For this project, we will be using:
- Raspberry Pi (mine Raspberry Pi 2)
- Flashdrive cost: ~5.00 USD
Step 2: Hardware Connections
In general, the connections are fairly easy. Just connect Flash Drive to Raspberry PI with USB slot and check the name of Flash Drive in Raspberry pi by type "ls /media" in Raspberry Pi terminal, the result should be content Flash Drive's name and you are good to go.
Step 3: Raspberry Pi Programming
Below is the Python code. Edit the code in any way you prefer, run the module , and you should have no problems.
import os import time
from time import sleep
from datetime import datetime
file = open("/home/pi/data_log.csv", "a")
if os.stat("/home/pi/data_log.csv").st_size == 0:
now = datetime.now()
Step 4: Read Your Data Log
Your file that located in your /home/pi/ or any location you prefer is a comma-separated value(CVS) file. Comma-separated values (CVS) file is a formatted file that stores tabular data (numbers and text) which separated by comma. To open and modify this file, simply double click on it, or open it with Microsoft Excel. You can plot your data with Chart tools that available in Microsoft Excel.
Step 5: Enjoy!
After making sure that everything works correctly, you can take this project into bigger project or integrated it with Real Time Clock (RTC) for accurate logging. Check it out >> Raspberry Pi - Real Time Clock (RTC) !
Power through power bank or a plug and you’re good to go!