Wifi_twit.py changing Celsius to Fahrenheit and changing frequency of tweet



Hello Dexter Community. I’ve been working with the wifi_twit.py project and have almost everything up and running. But I have two questions:

  1. How do I get the code to output the temperature in Fahrenheit instead of Celsius?

  2. How do I make the code tweet less frequently?

Thank you!

Error Code: Duplicate Tweet or Twitter Refusal: [{u'message': u'Status is a duplicate.'. u'code': 187}]

Hi @mremingtonb,

How do I get the code to output the temperature in Fahrenheit instead of Celsius?

The formula for converting Fahrenheit degrees into Celsius degrees is the following:

  1. Multiply your Fahrenheit value by 9.

  2. The result is divided by 5.

  3. And at the end add 32.

If you want to go the other way, like convert from Celsius to Fahrenheit degrees, you just need to reverse these 3 steps.

How do I make the code tweet less frequently?

I’m not sure what you’re referring to since I don’t have any code to look on. Maybe you can share it with us and we’ll give you some advice.

My first impression is that you need to add a delay, or a scheduler. It totally depends on your setup.

Thank you!


Thanks for the reply Robert! I know the formula for converting between Celsius and Fahrenheit, I just don’t know where in my code to put that formula to make it display in Fahrenheit instead of Celsius. It displays in Celsius by default.

I figured it would be something like x = (x * 9/5) + 32

But I’m not sure what x is, nor where to put it in the code.

Anyway, as to that, and as to tweeting frequency, here’s the code:

import twitter
import time
import grovepi
import math


sound_sensor = 0 # port A0
light_sensor = 1 # port A1
temperature_sensor = 2 # port D2
led = 3 # port D3

intro_str = “DI Lab’s”

Connect to Twitter

api = twitter.Api(

grovepi.analogWrite(led,255) #turn led to max to show readiness

while True:

# Error handling in case of problems communicating with the GrovePi

    # Get value from light sensor
    light_intensity = grovepi.analogRead(light_sensor)

    # Give PWM output to LED

    # Get sound level
    sound_level = grovepi.analogRead(sound_sensor)


    # Get value from temperature sensor
    [t,h] = grovepi.dht(temperature_sensor,0)

    # Post a tweet
    out_str ="%s Temp: %d C, Humidity: %d, Light: %d, Sound: %d" %(intro_str,t,h,light_intensity/10,sound_level)
    print (out_str)
except IOError:
except KeyboardInterrupt:
except Exception as e:
    print("Duplicate Tweet or Twitter Refusal: {}".format(e))



Hello @mremingtonb,
You are talking about this project, right?

To tweet less often:

  • change the last line from time.sleep(60) to time.sleep(3600) where the number is how many seconds between tweets. The first one is once a minute, the second one is once per hour.

To change to Fahrenheit:

  • after this line: [t,h] = grovepi.dht(temperature_sensor,0) add
    ` t = ((t * 9) / 5.0) + 32