0

I have an arduino that is reading data and sending it to my computer which is then read by a python script, to be saved as a csv file.

however at the end of the line there is a "\r\n" that pops up. I essentially want all these values to be stored as a float, not a string.

here is my py script

import serial
import csv
import numpy as np
import matplotlib.pyplot as plt
import matplotlib.animation as animation


index = 0
ser = serial.Serial('/dev/ttyUSB0', 9600)
vol = 1.0
tempHL = []
tempWL = []
tempCL = []
timeL = []
humidL = []
dataT = timeL, tempWL, tempCL, tempHL, humidL



while True:
    index +=1
    #temp = float(ser.readline())
    temp = ser.readline()
    time, tempW, tempC, tempH, humidity = temp.split(",")
    print "Time: ", time, " TempW: ", tempW, " TempC: ", tempC, " TempH: ", tempH, " Humidity: ", humidity
    print


    timeL.append(time)
    tempWL.append(tempW)
    tempCL.append(tempC)
    tempHL.append(tempH)
    humidL.append(humidity)

        with open("/home/matthew/sketchbook/VaporPod/VaporPod/data.csv", 'wb') as f:
        writer = csv.writer(f)
        for t, tW, tC, tH, h in zip(dataT[0], dataT[1], dataT[2], dataT[3], dataT[4]):
            writer.writerow([t, tW, tC, tH, h])
            #print "Time: ", t, " TempWater: ", tW, " TempCube: ", tC, " tempHumidity: ", tH, " Humidity: ", h
    #print


    f.close()

Here is my Arduino code.

void loop() {  


  monitor.setCursor(0, 1);
  sensors.requestTemperatures();


  //---from humidity sensor

  float tempWater = sensors.getTempF(waterTemp);
  float tempCube = sensors.getTempF(cubeTemp);

  float humd = myHumidity.readHumidity();
  float tempH = (myHumidity.readTemperature()) * 1.8 + 32.0;


  //time

  Serial.print(millis() / 1000);
  Serial.print(",");



  //Water TempC
  Serial.print(tempWater);
  //printTemperature(waterTemp);
  Serial.print(",");


  //---cube temp

  Serial.print(tempCube);
  //printTemperature(cubeTemp);
  Serial.print(",");



  //---tempC from humidity sensor
  Serial.print(tempH, 1);
  Serial.print(",");

  //humidity
  Serial.print(humd, 1);
  Serial.print("\n");

  delay(1000);


}

Here is a screenshot of the saved csv file

a screen shot of the data

1 Answer 1

1
time, tempW, tempC, tempH, humidity = map(float,temp.split(","))

maybe?

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.