There are very complex ways of saving sensor data from Arduino to a text file. Also there are easy program. There was time when Mac were run with user created programs. Roger Meier’s Freeware site has such own created programs. Download the “CoolTerm” program. Extract it. Double click on the CoolTerm application to launch. Click on Connection, then go to Options and then in Serial Port Options select the Port you will use. It is easy with Arduino IDE. On the Arduino IDE you’ll see the type of board and the numerical value of COM port. We usually use 9600 baudrate, so set baudrate to 9600 and in your Arduino, include the Serial.begin(9600);
(like you normally do for watching various sensor data on Arduino’s serial monitor). In CoolTerm program, go to Connection > Options > Receive and tick mark the “Add timestamps to received data” option. CoolTerm program has connect and disconnect options. To have any serial data from Arduino, click Connection > Capture to Text File and click on Start. This much work needed to setup the datalogger. This the easy way.
What is Difficult Way Data From Arduino To a Text File?
Method 2 : From Terminal
There are many difficult ways! Fiirst difficult way is derivative for recording with headless Raspberry Pi. Of course you can do with full computer. Previously we written a guide on how to control Arduino from Terminal. Your whole thing became Python. Then we will do the fun from PySerial :
---
1 | https://pythonhosted.org/pyserial/ |
You need some Python script like this to do the desired work :
1 2 3 4 5 6 7 8 9 10 11 12 | import serial from datetime import datetime sensor = "DH11" serial_port = '/dev/ttyACM0' baud_rate = 9600 path = "%s_LOG_%s.txt" % (str(datetime.now()), sensor) ser = serial.Serial(serial_port, baud_rate) with open(path, 'w+') as f: while True: line = ser.readline() f.writelines([line.strip(), " t = %s \n " % (datetime.now())]) |
Method 3 : From SD Card Reader
Secondly, you can use Arduino SD Card reader for data logging. You will just need the SD card reader, SD card and this kind of Arduino sketch :
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 | /* Writing Sensor Data to an SD card // This example shows how to write data to an SD card using the SD library. // The circuit: * SD card attached to SPI bus as follows: ** MOSI - pin 11 ** MISO - pin 12 ** CLK - pin 13 ** CS - pin 10 Uno (53 on Mega) Based on code by Tom Igoe */ // #include "SD.h" #include"SPI.h" // //the hardware CS pin (10 on most Arduino boards, // 53 on the Mega) must be left as an output or the SD // library functions will not work. const int CSpin = 10; String dataString =""; // holds the data to be written to the SD card float sensorReading1 = 0.00; // value read from your first sensor float sensorReading2 = 0.00; // value read from your second sensor float sensorReading3 = 0.00; // value read from your third sensor File sensorData; // // void setup() { // Open serial communications Serial.begin(9600); Serial.print("Initializing SD card..."); pinMode(CSpin, OUTPUT); // // see if the card is present and can be initialized: if (!SD.begin(CSpin)) { Serial.println("Card failed, or not present"); // don't do anything more: return; } Serial.println("card initialized."); } // void loop(){ // build the data string dataString = String(sensorReading1) + "," + String(sensorReading2) + "," + String(sensorReading3); // convert to CSV saveData(); // save to SD card delay(60000); // delay before next write to SD Card, adjust as required } // void saveData(){ if(SD.exists("data.csv")){ // check the card is still there // now append new data file sensorData = SD.open("data.csv", FILE_WRITE); if (sensorData){ sensorData.println(dataString); sensorData.close(); // close the file } } else{ Serial.println("Error writing to file !"); } } |
Method 4 (most difficult) : Using Processing Program to Redirect
Processing is a prototyping board, kind of father of Arduino. Obviously it has an IDE. It is easiest for me to redirect you to read this whole guide to do it :
1 | https://arduinobasics.blogspot.com/2012/05/reading-from-text-file-and-sending-to.html |
I do not use any more ways. I mean, you should not need more ways!
Tagged With how to save the data from sensor in text file , arduino write console to text file , arduino save data to text file , reading from serial port and saving in a file , arduino txt file pc , arduino output to text file , CAN data to txt file arduino , sending sensor data to BC95 in Arduino IDE , arduino save to file , arduino save serial data to file