Skip to content

Instantly share code, notes, and snippets.

@seth10
Created August 1, 2017 19:37
Show Gist options
  • Save seth10/4443cc2181f9cd9e7655d4834d30af4f to your computer and use it in GitHub Desktop.
Save seth10/4443cc2181f9cd9e7655d4834d30af4f to your computer and use it in GitHub Desktop.
A simple program to take readings for a moisture sensor on the PiStorms-GRX
# import some stuff we'll need
from GroveDevices import Grove_Moisture_Sensor
from PiStorms_GRX import PiStorms_GRX
import numpy as np
import time
# create a sensor (on port BAA1), the PiStorms object, and an empty list to hold the data
sensor = Grove_Moisture_Sensor("BAA1")
psm = PiStorms_GRX()
data = []
# show a label on the screen
psm.screen.termPrintln("Current moisture measurement:")
psm.screen.termPrint("[none]")
# repeat this until you press the GO button at least once (not 0 times)
while psm.getKeyPressCount() == 0:
# take a reading, put it on screen, add it to the data array, and wait 10 seconds before taking another measurement
reading = sensor.moistureLevel()
psm.screen.termReplaceLastLine(reading)
data.append(reading)
time.sleep(10)
# open a file called moisture.csv in your Documents folder, write each data point with a comma after it
with open("/home/pi/Documents/moisture.csv", "w+") as file:
for measurement in data:
file.write(str(measurement) + ",")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment