Search code examples
pythongrovepi+

Python code not fetching up to date sensor values


So I am trying to fetch for light sensor values using the light sensor that is part of GrovePi. When I run the sample script here (https://github.com/DexterInd/GrovePi/blob/master/Software/Python/grove_light_sensor.py) the code works perfectly so this leads me to conclude that the script I wrote is somehow only fetching for one value and just stores it and outputs it without fetching for the new updated value. Note: I am storing my values in a dictionary and posting to Dweet.io

If anyone can lead me to the right direction that would be great, my code is below :

import time
import grovepi

light_sensor = 0


grovepi.pinMode(light_sensor,"INPUT")


def getLight():
  sensor_value = grovepi.analogRead(light_sensor)

  s = sensor_value
  #S seems to print just one number here?
  print(s)

  return s

def values():
  dict = {}
  dict["light"] = getLight()
  return dict

while True:
  dict = values()
  print (dweepy.dweetfor(n, dict))
  time.sleep(2)

Solution

  • Not an engineer, but why are you adding the whole dictionary part at all? Your sample code does not do that, and dweet certainly does not need it.

    My guess is that is your issue, remove it.

    While True: print (dweepy.dweetfor(s))