Skip to content

Instantly share code, notes, and snippets.

@WestonReed
Last active March 27, 2018 23:59
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 WestonReed/cfc0f3f6ab62657d680c9b84978bc273 to your computer and use it in GitHub Desktop.
Save WestonReed/cfc0f3f6ab62657d680c9b84978bc273 to your computer and use it in GitHub Desktop.
Data Collection Python Script for Raspberry Pi with Sense Hat
#!/usr/bin/python3
from ev3dev.ev3 import *
import csv
import time
filename = input('Enter a name for the file: ')
filename = filename+".csv"
cl = ColorSensor()
cl.mode='RGB-RAW'
with open(filename, 'w') as logfile:
fieldnames = ['red', 'green', 'blue']
logwriter = csv.DictWriter(logfile, fieldnames=fieldnames)
logwriter.writeheader()
for x in range(0,1500):
red = cl.value(0)
green = cl.value(1)
blue = cl.value(2)
logwriter.writerow({
'red' : red,
'green' : green,
'blue' : blue
})
time.sleep(.1)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment