Skip to content

Instantly share code, notes, and snippets.

@JGarrechtMetzger
Created March 26, 2021 15:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save JGarrechtMetzger/ada3040ecd6b06a0c819669d25a26008 to your computer and use it in GitHub Desktop.
Save JGarrechtMetzger/ada3040ecd6b06a0c819669d25a26008 to your computer and use it in GitHub Desktop.
import tmp102
import csv
import time
#### Initialize communication with TMP102
tmp102.init()
temp_c = round(tmp102.read_temp(), 2)
#### Write CSV
x_value = 0
y_value = 0
fieldnames = ['x_value','y_value']
with open('data_1s.csv','w') as csv_file:
csv_writer = csv.DictWriter(csv_file, fieldnames=fieldnames)
csv_writer.writeheader()
while True:
with open('data_1s.csv', 'a') as csv_file:
csv_writer = csv.DictWriter(csv_file, fieldnames=fieldnames)
info = {
"x_value": x_value,
"y_value": y_value
}
csv_writer.writerow(info)
print(x_value, y_value)
x_value += 1
y_value = round(tmp102.read_temp(), 2)
time.sleep(.5)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment