Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
R
Raspberry Pi
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
sam.pople
Raspberry Pi
Commits
58e1facb
Commit
58e1facb
authored
Jan 19, 2025
by
sam.pople
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add new file
parents
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
125 additions
and
0 deletions
+125
-0
Program.py
Program.py
+125
-0
No files found.
Program.py
0 → 100644
View file @
58e1facb
#!/usr/bin/env python3
#Run this file to enact the device
import
requests
import
random
import
time
from
seeed_dht
import
DHT
from
grove.display.jhd1802
import
JHD1802
from
grove.grove_ryb_led_button
import
GroveLedButton
# Connects to the ThingSpeak channel
WRITE_API_KEY
=
'I7OWLPEYX17YJFVH'
# API key
CHANNEL_ID
=
'2767951'
# Channel ID
THINGSPEAK_URL
=
'https://api.thingspeak.com/update?api_key=I7OWLPEYX17YJFVH&field1=0'
# URL
def
send_data_to_thingspeak
(
temperature
,
humidity
):
# Sends temperature data to ThingSpeak
# Create the payload with the field data
payload
=
{
'field1'
:
temperature
,
# Field1 corresponds to temperature
'field2'
:
humidity
# Field2 corresponds to humidity
}
# Send the HTTP GET request to ThingSpeak
response
=
requests
.
get
(
THINGSPEAK_URL
,
params
=
payload
)
# Check the response code
# Announces if successfully sent
if
response
.
status_code
==
200
:
print
(
'Data sent successfully'
)
else
:
print
(
'Failed to send data. Response code: {response.status_code}'
)
def
main
():
# Grove - 16x2 LCD(White on Blue) connected to I2C port
lcd
=
JHD1802
()
# This connects the LED button to the D22 port
ledbtn
=
GroveLedButton
(
22
)
# Grove - Temperature&Humidity Sensor connected to port D5
sensor
=
DHT
(
'11'
,
5
)
while
True
:
ledbtn
.
led
.
light
(
True
)
# This detects the temperature and humidity
humi
,
temp
=
sensor
.
read
()
# This converts the temperature (which is Celsius) to Farenheit
faren
=
round
(
temp
*
1.8
+
32
,
2
)
# This displays the Temperature in Celsius and in Farenheit on the terminal
print
(
'Temperature = {}C ({}F)'
.
format
(
temp
,
faren
))
# This displays the Temperature in Celsius on the LCD's top row
lcd
.
setCursor
(
0
,
0
)
lcd
.
write
(
'Temperature: {0:2}C'
.
format
(
temp
))
# This displays the Temperature in Farenheit on the LCD's second row
lcd
.
setCursor
(
1
,
0
)
lcd
.
write
(
'({0:2}F)'
.
format
(
faren
))
# This waits 10 seconds to show the temperature before moving on
time
.
sleep
(
10
)
lcd
.
clear
()
# This displays the recommended clothes for a temperature equal to or higher than 20C
if
temp
>=
20
:
print
(
'Recommended Clothes: T-Shirt, shorts, sunscreen, short socks'
)
lcd
.
setCursor
(
0
,
0
)
# This displays the appropriate clothes and information on the LCD while waiting a few seconds to display one screen after another
lcd
.
write
(
' Recommended'
)
lcd
.
setCursor
(
1
,
0
)
lcd
.
write
(
'Clothes'
)
time
.
sleep
(
5
)
lcd
.
clear
()
lcd
.
setCursor
(
0
,
0
)
lcd
.
write
(
' T-Shirt, Shorts'
)
lcd
.
setCursor
(
1
,
0
)
lcd
.
write
(
' Sunscreen'
)
time
.
sleep
(
10
)
lcd
.
clear
()
lcd
.
setCursor
(
0
,
0
)
lcd
.
write
(
' Short Socks'
)
# This displays the recommended clothes for a temperature between 10 and 20
elif
temp
>
10
and
temp
<
20
:
print
(
'Recommended Clothes: Long shirt, trousers, jacket, regular socks'
)
lcd
.
setCursor
(
0
,
0
)
# This displays the appropriate clothes and information on the LCD while waiting time to display it one screen after another
lcd
.
write
(
' Recommended'
)
lcd
.
setCursor
(
1
,
0
)
lcd
.
write
(
' Clothes'
)
time
.
sleep
(
5
)
lcd
.
clear
()
lcd
.
setCursor
(
0
,
0
)
lcd
.
write
(
' Long shirt'
)
lcd
.
setCursor
(
1
,
0
)
lcd
.
write
(
' Trousers'
)
time
.
sleep
(
10
)
lcd
.
clear
()
lcd
.
setCursor
(
0
,
0
)
lcd
.
write
(
' Jacket'
)
lcd
.
setCursor
(
1
,
0
)
lcd
.
write
(
' Regular Socks'
)
# This displays the recommended clothes for a temperature below 11
else
:
print
(
'Recommended Clothes: Coat, trousers, gloves, jumper, long shirt, thick socks'
)
lcd
.
setCursor
(
0
,
0
)
# This displays the appropriate clothes and information on the LCD while waiting a few seconds to display one screen after another
lcd
.
write
(
' Recommended'
)
lcd
.
setCursor
(
1
,
0
)
lcd
.
write
(
'Clothes'
)
time
.
sleep
(
5
)
lcd
.
clear
()
lcd
.
setCursor
(
0
,
0
)
lcd
.
write
(
' Coat, Trousers'
)
lcd
.
setCursor
(
1
,
0
)
lcd
.
write
(
'Jumper, Gloves'
)
time
.
sleep
(
10
)
lcd
.
clear
()
lcd
.
setCursor
(
0
,
0
)
lcd
.
write
(
' Long shirt'
)
lcd
.
setCursor
(
1
,
0
)
lcd
.
write
(
'Thick socks'
)
#This send the temperature and humidity to Thingspeak
send_data_to_thingspeak
(
temp
,
humi
)
time
.
sleep
(
10
)
# This waits another 10 seconds to show the advice before clearing and detecting and displaying the next current temperature
lcd
.
clear
()
if
__name__
==
'__main__'
:
main
()
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment