Cov txheej txheem:

Raspberry PI LED Huab Cua Chaw Nres Tsheb: 8 Kauj Ruam
Raspberry PI LED Huab Cua Chaw Nres Tsheb: 8 Kauj Ruam

Video: Raspberry PI LED Huab Cua Chaw Nres Tsheb: 8 Kauj Ruam

Video: Raspberry PI LED Huab Cua Chaw Nres Tsheb: 8 Kauj Ruam
Video: Часы G Shock до 100 долларов-15 лучших часов Casio G Shock до 100 дол... 2024, Kaum ib hlis
Anonim
Raspberry PI LED Huab Cua Chaw Nres Tsheb
Raspberry PI LED Huab Cua Chaw Nres Tsheb

Peb tsim Raspberry PI Weather LED Chaw Nres Tsheb. Nws qhia tus neeg siv tias lub nroog kub thiab txias npaum li cas los ntawm teeb pom kev zoo, thiab dimming, leds. Nws kuj tseem muaj coj los qhia rau lawv seb nws puas los nag hauv lub nroog uas lawv sau.

Tsim los ntawm Michael Andrews thiab Tio Marello.

Khoom siv

Cov cuab yeej

  1. Soldering Hlau
  2. Dremel
  3. Pom

Khoom siv

  1. Raspberry Pi 3 B+ ~ 40 Dollars ~ 30 Dollars
  2. Poj niam rau Txiv neej Jumper xov hlau ~ 7 daus las
  3. 3 Xiav thiab 2 Liab LED Diodes ~ 11 Dollars
  4. 100 Ohm Resistors ~ 13 Dollars
  5. 4 x 4 x 1/4 Ntoo Ntoo ~ 5 Dollars
  6. Solder ~ 10 Dollars
  7. Tooj Hlau ~ 5 Daus las

Kauj Ruam 1: Coding Raws Li Teeb Meem

Coding yog daws teeb meem

Yog li, hauv peb txoj haujlwm, peb muaj teeb meem dab tsi? Peb qhov teeb meem yog tau txais cov ntaub ntawv huab cua thiab tom qab ntawd siv cov ntaub ntawv ntawd los qhia rau peb cov LEDS seb lawv puas tawm lossis qhib. Yog li qhov no faib peb qhov teeb meem mus rau peb thaj chaw.

1. Tau Txais Cov Ntaub Ntawv Huab Cua

2. Siv Cov Ntaub Ntawv ntawd

3. Siv LEDS

Txawm li cas los xij, hom lus peb siv rau txoj haujlwm no, Python, thiab kho vajtse nws tau siv, Python, muab txoj hauv kev yooj yim rau peb kom ua tiav cov hom phiaj no.

Yog li, peb yuav cia pib nrog thawj qhov teeb meem, tau txais cov ntaub ntawv huab cua.

Kauj Ruam 2: Coding: Tau Cov Ntaub Ntawv Huab Cua

Python los ntawm nws tus kheej tsis tuaj yeem tau txais cov ntaub ntawv huab cua. Peb yuav tsum ntshuam ob yam cuab yeej, nrog rau kev pabcuam sab nraud, kom tau txais cov ntaub ntawv huab cua. Txhawm rau ua qhov no, peb siv peb yam cuab yeej.

1. Kev thov, tus nab npawb nab npawb uas tso cai rau webscraping

2. Json, tus nab npawb qauv uas tso cai rau peb siv JSON cov ntaub ntawv hom ntawv

3. OpenWeather, lub vev xaib uas tuaj yeem muab cov ntaub ntawv huab cua rau peb

Yog li, peb nqa ob qhov qauv los ntawm kev sau cov cai no nyob rau sab saum toj ntawm peb cov ntawv nab nab.

ntshuam thov

ntshuam json

Ua ntej peb siv cov cuab yeej no, txawm li cas los xij, peb yuav tsum siv Openweather. Txog qhov ntawd, peb yuav tsum tsim tus as khauj ntawm lawv lub xaib thiab tau txais tus lej API. Ua raws cov lus qhia ntawm lawv lub vev xaib thiab koj yuav tau txais cov tsiaj ntawv thiab cov lej uas yuav cia peb siv lawv cov kev pabcuam. Yuav ua li cas?

openweather_api_key = "260a23f27f5324ef2ae763c779c32d7e" #Our API Key (Tsis Tiag)

base_call = "https://api.openweathermap.org/data/2.5/weather? () #Ntawm no peb tau teeb tsa qhov chaw nyob peb yuav txuas rau hauv kev thov.get kom tau txais cov ntaub ntawv huab cua full_call = base_call+city_name+"& appid ="+openweather_api_key #Thaum kawg peb hu thov.get nrog peb qhov chaw nyob, tom qab ntawd peb hloov nws mus rau hauv json file Teb = thov.get (full_call) WeatherData = Response.json () #JSON cov ntaub ntawv muaj qhov sib txawv sib txawv uas peb tuaj yeem nkag mus siv cov kab lus no #Ntawm no peb tau txais huab cua ID thiab ntsuas kub hauv Kelvin ntawm lub nroog tus neeg siv ntaus hauv WeatherID = WeatherData ["huab cua"] [0] ["id"] City_TemperatureK = WeatherData ["lub ntsiab"] ["temp"]

Nov peb muaj cov cai uas tau txais peb cov ntaub ntawv huab cua. Kev thov, hauv daim ntawv thov.get, siv lub vev xaib chaw nyob thiab muab peb cov ntaub ntawv los ntawm lub vev xaib ntawd rov qab. OpenWeather muab chaw nyob rau peb kom hu xov tooj muab cov ntaub ntawv huab cua rau peb hauv daim ntawv json. Peb sau qhov chaw nyob uas peb ntsaws rau hauv kev thov thiab tau txais json cov ntaub ntawv rov qab. Tom qab ntawd peb tsim ob qhov sib txawv thiab muab lawv tso rau qhov ntsuas kub thiab huab cua ntawm tus neeg siv lub nroog.

Yog li tam sim no, nrog cov cai no, peb muaj ob qhov sib txawv. Peb muaj huab cua huab cua thiab kub nyob hauv Kelvin

Kauj Ruam 3: Coding: Siv Cov Ntaub Ntawv ntawd

Tam sim no peb muaj ob qhov kev hloov pauv no, peb yuav tsum npaj lawv rau kev siv rau peb cov LEDS. Txog rau qhov no, peb tsis tas yuav ntshuam ib qho qauv rau qhov no.

Ua ntej, peb hloov kelvin rau Fahrenheit.

Peb ua qhov no los ntawm kev tsim qhov sib txawv nrog cov syntax no

City_TemperatureF = (City_TemperatureK - 273)*1.8 + 32

uas hloov los ntawm Kelvin mus rau Fahrenheit (uas yog qhov hloov pauv tiag tiag los ntawm K -> C -> F)

Tom ntej yog peb huab cua ID. WeatherID yog tus lej uas Openweather muab uas qhia peb txog huab cua puag ncig ntawm ib lub nroog.

openweathermap.org/weather-conditions Nov yog cov npe ntawm lawv.

Peb pom tias txhua yam hauv qab 700 tus lej yog qee yam nag lossis daus, yog li peb tsuas yog tshuaj xyuas yog tias tus lej qis dua 700 kom pom tias nws los nag.

def CheckRain (IdCode): yog IdCode <700: rov muaj tseeb dua: rov qab yuam kev

Nrog qhov ntawd, peb muaj ob qhov kev hloov pauv tau npaj rau siv nrog peb Raspberry PI pins thiab LED Diodes.

Kauj Ruam 4: Coding: Siv RPi. GPIO thiab LED Diodes

Coding: Siv RPi. GPIO thiab LED Diodes
Coding: Siv RPi. GPIO thiab LED Diodes

Lub RaspberryPi los nrog txheej txiv neej tus pin uas peb tuaj yeem siv los sib txuas lus nrog cov tswv ntawm cov khoom siv hluav taws xob, uas qhov no, yog LED Diodes; nws zoo ib yam rau Arduino thiab nws cov kab ke. Txawm li cas los xij, Raspberry PI yog lub khoos phis tawj siv dav, tsis zoo li lub microcontroller zoo li Arduino. Yog li, peb yuav tsum ua haujlwm me ntsis ntxiv los siv lawv. Qhov no suav nrog teeb tsa tus pin ntawm Raspberry Pi. Peb ua qhov no los ntawm kev siv tus lej no.

ntshuam RPi. GPIO ua GPIO #Peb peb ntsaws tus qauv kom peb siv tau

#Teeb tsa tus pin GPIO.setmode (GPIO. BCM) GPIO.setwarnings (Cuav)

#Cov pins cov LEDs tau txuas rau. Cov no yuav txawv yog tias koj tsim nws, yog li nco ntsoov sib piv thiab hloov pauv thaum tsim nyog

Extreme_Hot_LED_PIN = 26 Kub_LED_PIN = 16

Extreme_Cold_LED_PIN = 5

Cold_LED_PIN = 6

Rain_LED_PIN = 23

#Peb mus dhau txhua tus pin, siv.setup hais kom ua, muab nws tus lej thiab teeb nws ua tus pin

GPIO.setup (Rain_LED_PIN, GPIO. OUT) GPIO.setup (Extreme_Cold_LED_PIN, GPIO. OUT) GPIO.setup (Cold_LED_PIN, GPIO. OUT) GPIO.setup (Hot_LED_PIN, GPIO. OUT) GPIO.setup (Extreme_Hot_LED_POU), GPIO.setup

Txawm li cas los xij, txoj cai no tsuas yog cia peb siv ob lub xeev nrog tus coj, uas yog, rau thiab tawm. Txawm li cas los xij, peb xav tau kom muaj peev xwm dim lub teeb. Txhawm rau ua qhov no, peb siv Pulse Width Modulation.

Siv Pulse Width Modulation

Pulse Width Modulation tso cai rau peb tso tawm cov teeb liab analog siv tus lej digital. Qhov tseem ceeb, nws tig thiab tawm lub teeb liab los ntawm tus nqi siab, uas qhov nruab nrab tawm mus rau qee qhov hluav taws xob. RPi. GPIO tso cai rau peb siv qhov no, txawm hais tias muaj qee tus lej ntxiv.

#Peb tsim plaub tus lej khoom siv GPIO. PWM hais kom ua, uas siv tus lej lej

#Tus lej thib ob yog tus lej ntawm lub sijhawm nws hloov tshiab thib ob

ExtremeHotLED = GPIO. PWM (Extreme_Hot_LED_PIN, 100) HotLED = GPIO. PWM (Hot_LED_PIN, 100)

ExtremeColdLED = GPIO. PWM (Extreme_Cold_LED_PIN, 100)

ColdLED = GPIO. PWM (Cold_LED_PIN, 100)

Rau qib tom ntej, koj yuav tsum paub txoj hauv kev peb hloov kho cov pins no.

Peb hloov cov pins siv qhov hais kom ua

ExtremeColdLED.start (x) ColdLED.start (x)

ExtremeHotLED.start (x)

HotLED.start (x)

x hauv qhov no yuav yog lub voj voog ua haujlwm, uas txiav txim siab ntau npaum li cas nws tawm. Nws txawv ntawm 0-100, yog li peb yuav tsum pib peb cov cai tom ntej tawm ntawm qhov tseeb.

Kauj ruam 5: Coding: Tau LED Brightness

Coding: Tau LED Brightness
Coding: Tau LED Brightness

Vim tias peb muaj plaub tus lej sib txawv, peb xav kom pom lawv nyob ntawm seb yuav ua li cas. txias lossis kub nws nyob ntawm tus neeg siv lub nroog. Peb txiav txim siab kom muaj plaub theem rau kev coj.

#Functions

def getmiddleleftledintensity (TemperatureinF): #Left Equation: y = -(50/20) x + 175 #Right Equation: y = (50/20) x -75 rov qab -(50/20)*Kub hauv F + 175

def getmiddlerightledintintensity (Kub hauv F):

#Left Equation: y = - (50/20) x + 175 #Right Equation: y = (50/20) x - 75 return (50/20)*Kub hauv F - 75

def getextremeleftledintensity (Kub hauv F):

#LeftEquation: y = - (100/30) x + 200 #RightEquation: y = (100/30) x - (400/3)

rov qab -(100/30)*Kub hauv F + 200

def getextremerightledintensity (Kub hauv F):

# LeftEquation: y = - (100/30) x + 200 # RightEquation: y = (100/30) x - (400/3)

rov qab (100/30)*Kub hauv F - (400/3)

#Teeb tsa LED Teeb

def GetLEDBrightness (kub):

yog temp <= 0: txias heev = 100 txias = 100 kub = 0 heev txias = 0

print ("Huab cua txias heev:" + str (huab cua txias heev))

print ("Cold led:" + str (coldled)) print ("Kub heev coj" + str (heev hotled)) print ("Kub coj:" + str (hotled))

ExtremeColdLED.start (txias heev)

ColdLED.start (txias)

ExtremeHotLED.start (kub heev)

HotLED.start (hotled) elif temp> = 100: txias heev = 0 txias = 0 kub = 100 kub heev = 100

print ("Huab cua txias heev:" + str (huab cua txias heev))

print ("Cold led:" + str (coldled)) print ("Kub heev coj" + str (heev hotled)) print ("Kub coj:" + str (hotled))

ExtremeColdLED.start (txias heev)

ColdLED.start (txias)

ExtremeHotLED.start (kub heev)

HotLED.start (hotled) elif 0 <temp <= 30: extremecoldled = getextremeleftledintintensity (temp) - 100 coldled = 100 hotled = 0 heev hotled = 0

print ("Huab cua txias heev:" + str (huab cua txias heev))

print ("Cold led:" + str (coldled)) print ("Kub heev coj" + str (heev hotled)) print ("Kub coj:" + str (hotled))

ExtremeColdLED.start (txias heev)

ColdLED.start (txias)

ExtremeHotLED.start (kub heev)

HotLED.start (hotled) elif 100> temp> = 70: txias heev = 0 txias = 0 hotled = 100 huab cua sov = getextremerightledintint (temp) - 100

print ("Huab cua txias heev:" + str (huab cua txias heev))

print ("Cold led:" + str (coldled)) print ("Kub heev coj" + str (heev hotled)) print ("Kub coj:" + str (hotled))

ExtremeColdLED.start (txias heev)

ColdLED.start (txias)

ExtremeHotLED.start (kub heev)

HotLED.start (hotled) elif 30 <temp <50: extremecoldled = 0 coldled = getmiddleleftledintintensity (temp) hotled = 100 - txias txias heev = 0

print ("Huab cua txias heev:" + str (huab cua txias heev))

print ("Cold led:" + str (coldled)) print ("Kub heev coj" + str (heev hotled)) print ("Kub coj:" + str (hotled))

ExtremeColdLED.start (txias heev)

ColdLED.start (txias)

ExtremeHotLED.start (kub heev)

HotLED.start (hotled) elif 50 <temp <70: hotled = getmiddlerightledintintensity (temp) heev hotled = 0

txias = 100 - kub

txias heev = 0

print ("Huab cua txias heev:" + str (huab cua txias heev))

print ("Cold led:" + str (coldled)) print ("Kub heev coj" + str (heev hotled)) print ("Kub coj:" + str (hotled))

ExtremeColdLED.start (txias heev)

ColdLED.start (txias)

ExtremeHotLED.start (kub heev)

HotLED.start (hotled) elif temp == 50: txias heev = 0 txias = 50 kub = 50 kub heev = 0

print ("Huab cua txias heev:" + str (huab cua txias heev))

print ("Cold led:" + str (coldled)) print ("Kub heev coj" + str (heev hotled)) print ("Kub coj:" + str (hotled))

ExtremeColdLED.start (txias heev)

ColdLED.start (txias)

ExtremeHotLED.start (kub heev)

HotLED.start (hotled)

Yog lawm, ntu ntu ntawm txoj cai no ntev heev. Nws kuj zoo nkauj nyuaj piav. Qhov tseem ceeb, cov cai saum toj no saib ntawm qhov ntsuas kub hauv Fahrenheit, thiab txiav txim siab yog tias nws nyob hauv cov txheej txheem. Nyob ntawm qhov ntau, nws muab tus lej rau txhua tus coj thiab nws qhov ci ci thiab tom qab ntawd teeb qhov ci ci los ntawm kev hu rau pib () hais kom ua. Ntawd yog cov lus piav qhia sai. Yog tias nws txaus, Kuv pom zoo kom koj txav mus rau qib tom ntej, tab sis yog tias koj xav pom qhov kev piav qhia ntev thiab tsis txaus ntseeg, nyeem txuas ntxiv.

Thaum peb ua haujlwm, peb txiav txim siab txoj hauv kev yooj yim tshaj plaws kom tau txais txiaj ntsig los ntawm qhov kub tau nyob hauv daim ntawv ntawm kev ua lej. Yog li, peb tsim cov duab hauv GeoGebra los sawv cev txog qhov kev sib raug zoo ntawm peb qhov kub thiab peb coj qhov ci ci; yog vim li cas nws mus saum 100 yog tias qhov ntxiv yuav nkag mus rau qhov coj thib ob. Txawm li cas los xij, peb tau khiav mus rau qhov teeb meem ntawm kev tau txais ib txoj haujlwm los qhia tag nrho cov ntsiab lus no rau ib qho haujlwm. Peb xav tias peb tuaj yeem siv tus parabola, tab sis peb tau txiav txim siab tsuas yog khom nqi rau kev siv ua ntu zus ntawm cov lus. Hauv qhov tseeb, tag nrho cov cai no yog ua haujlwm ib leeg.

Cov haujlwm nyob rau sab saum toj yog qhov sib npaug ntawm kab. Thaum peb txiav txim siab qhov ntsuas kub nyob ntawm daim duab, peb khiav nws los ntawm txoj haujlwm ntawd, tau txais qhov ci ci, thiab hla nws mus rau lub leds.

Kauj Ruam 6: Coding: Kauj Ruam Kawg

Thaum kawg, peb ntxiv nqe lus no thaum kawg.

sim:

thaum (Tseeb): GetLEDBrightness (City_TemperatureF) GetRainLED (WeatherID) time.sleep (10) tsuas yog KeyboardInterrupt: tawm ()

Qhov kev sim thiab tshwj tsis yog nqe lus tso cai rau peb tawm cov cai los ntawm kev siv cov keyboard txiav luv; ib yam nkaus, peb yuav tsum kaw Raspberry Pi kom rov pib dua txoj cai. Tom qab ntawd peb muaj lub sijhawm voj uas ua haujlwm tas mus li. Peb hloov kho cov leds, ntxiv rau hloov kho nag nag LED. Peb ncua rau kaum vib nas this; OpenWeather tso cai tsuas yog 60 hu rau cov ntaub ntawv ib feeb, thiab 10 vib nas this yog qhov hloov tshiab ntau.

Thiab nrog qhov ntawd, peb cov cai tau ua tiav. Hauv qab no yog txoj cai tiav.

RaspberryPIWeatherStation.py

importrequests
importRPi. GPIOasGPIO
ntshuam
sij hawm tuaj
#Openweather idCodes tsawg dua 700 yog txhua yam nag lossis daus
defCheckRain (IdCode):
ifIdCode <700:
rov tseeb
lwm tus:
rov qab tsis raug
defgetmiddleleftledintensity (Kub hauv F):
#Left Equation: y =-(50/20) x + 175
#Right Equation: y = (50/20) x - 75
rov qab- (50/20)*Kub hauv F+175
defgetmiddlerightledintensity (Kub hauv F):
#Left Equation: y =-(50/20) x + 175
#Right Equation: y = (50/20) x - 75
rov qab (50/20)*Kub hauv F-75
defgetextremeleftledintensity (Kub hauv F):
#LeftEquation: y = -(100/30) x + 200
#RightEquation: y = (100/30) x - (400/3)
rov qab- (100/30)*Kub hauv F+200
defgetextremerightledintensity (Kub hauv F):
# LeftEquation: y = -(100/30) x + 200
#Txoj kev xav tau: y = (100/30) x - (400/3)
rov qab (100/30)*Kub hauv F- (400/3)
#GPIO teeb tsa
GPIO.setmode (GPIO. BCM)
GPIO.setwarnings (Cuav)
#Tus Pin
Extreme_Hot_LED_PIN = 26
Hot_LED_PIN = 16
Extreme_Cold_LED_PIN = 5
Cold_LED_PIN = 6
Rain_LED_PIN = 23
#Tus Pin teeb
GPIO.setup (Rain_LED_PIN, GPIO. OUT)
GPIO.setup (Extreme_Cold_LED_PIN, GPIO. OUT)
GPIO.setup (Cold_LED_PIN, GPIO. OUT)
GPIO.setup (Hot_LED_PIN, GPIO. OUT)
GPIO.setup (Extreme_Hot_LED_PIN, GPIO. OUT)
ExtremeHotLED = GPIO. PWM (Extreme_Hot_LED_PIN, 100)
HotLED = GPIO. PWM (Hot_LED_PIN, 100)
ExtremeColdLED = GPIO. PWM (Extreme_Cold_LED_PIN, 100)
ColdLED = GPIO. PWM (Cold_LED_PIN, 100)
defGetLEDBrightness (temp):
iftemp <= 0:
txias heev = 100
cua sov = 100
kub = 0
huab cua = 0
print ("Huab cua txias heev:"+str (huab cua txias heev))
print ("Txias coj:"+str (txias)))
print ("Kub heev coj"+str (heev hotled))
print ("Kub coj:"+str (hotled))
ExtremeColdLED.start (txias heev)
ColdLED.start (txias)
ExtremeHotLED.start (kub heev)
HotLED.start (hotled)
eliftemp> = 100: cov
txias heev = 0
cua sov = 0
kub = 100
qhov siab tshaj plaws = 100
print ("Huab cua txias heev:"+str (huab cua txias heev))
print ("Txias coj:"+str (txias)))
print ("Kub heev coj"+str (heev hotled))
print ("Kub coj:"+str (hotled))
ExtremeColdLED.start (txias heev)
ColdLED.start (txias)
ExtremeHotLED.start (kub heev)
HotLED.start (hotled)
elif0 <temp <= 30:
txias heev = getextremeleftledintensity (temp) -100
cua sov = 100
kub = 0
huab cua = 0
print ("Huab cua txias heev:"+str (huab cua txias heev))
print ("Txias coj:"+str (txias)))
print ("Kub heev coj"+str (heev hotled))
print ("Kub coj:"+str (hotled))
ExtremeColdLED.start (txias heev)
ColdLED.start (txias)
ExtremeHotLED.start (kub heev)
HotLED.start (hotled)
elif100> sijhawm> = 70:
txias heev = 0
cua sov = 0
kub = 100
heev hotled = getextremerightledintensity (temp) -100
print ("Huab cua txias heev:"+str (huab cua txias heev))
print ("Txias coj:"+str (txias)))
print ("Kub heev coj"+str (heev hotled))
print ("Kub coj:"+str (hotled))
ExtremeColdLED.start (txias heev)
ColdLED.start (txias)
ExtremeHotLED.start (kub heev)
HotLED.start (hotled)
elif30 <temp <50:
txias heev = 0
txias = getmiddleleftledintensity (temp)
hotled = 100-txias
huab cua = 0
print ("Huab cua txias heev:"+str (huab cua txias heev))
print ("Txias coj:"+str (txias)))
print ("Kub heev coj"+str (heev hotled))
print ("Kub coj:"+str (hotled))
ExtremeColdLED.start (txias heev)
ColdLED.start (txias)
ExtremeHotLED.start (kub heev)
HotLED.start (hotled)
elif50 <lub sijhawm <70:
hotled = getmiddlerightledintensity (temp)
huab cua = 0
txias = 100-hotled
txias heev = 0
print ("Huab cua txias heev:"+str (huab cua txias heev))
print ("Txias coj:"+str (txias)))
print ("Kub heev coj"+str (heev hotled))
print ("Kub coj:"+str (hotled))
ExtremeColdLED.start (txias heev)
ColdLED.start (txias)
ExtremeHotLED.start (kub heev)
HotLED.start (hotled)
eliftemp == 50: cov
txias heev = 0
sov = 50
kub = 50
huab cua = 0
print ("Huab cua txias heev:"+str (huab cua txias heev))
print ("Txias coj:"+str (txias)))
print ("Kub heev coj"+str (heev hotled))
print ("Kub coj:"+str (hotled))
ExtremeColdLED.start (txias heev)
ColdLED.start (txias)
ExtremeHotLED.start (kub heev)
HotLED.start (hotled)
defGetRainLED (idCode):
ifCheckRain (idCode):
GPIO.output (Rain_LED_PIN, GPIO. HIGH)
lwm tus:
GPIO.output (Rain_LED_PIN, GPIO. LOW)
#Api cov ntaub ntawv: Rov ua tus yuam sij API nrog koj tus lej oepnweather api
openweather_api_key = "460a23f27ff324ef9ae743c7e9c32d7e"
base_call = "https://api.openweathermap.org/data/2.5/weather?q="
print ("Ntaus hauv ib lub nroog!")
city_name = tswv yim ()
full_call = base_call+city_name+"& appid ="+openweather_api_key
#Tau Txais Cov Ntaub Ntawv Huab Cua
Teb = thov.get (full_call)
WeatherData = Response.json ()
WeatherID = WeatherData ["huab cua"] [0] ["id"]
City_TemperatureK = WeatherData ["main"] ["temp"]
City_TemperatureF = (City_TemperatureK-273)*1.8+32#Hloov mus rau Fahrenheit
#LED/GPIO Cov Khoom
print ("K:"+str (City_TemperatureK))
print ("F:"+str (City_TemperatureF))
luam tawm (WeatherID)
sim:
thaum (Tseeb):
Tau LEDBrightness (Lub Nroog_TemperatureF)
GetRainLED (Huab cua ID)
sijhawm.sleep (10)
exceptKeyboardInterrupt:
tawm ()

saib rawRaspberryPIWeatherStation.py tuav nrog ❤ los ntawm GitHub

Kauj Ruam 7: Txhim Kho thiab Txuas Txuas

Lawd! Tom qab txhua tus lej ntawd, peb tau mus rau lub tsev, uas yooj yim dua. Vim yog corona nyob hauv tsev xaj, peb tsis tuaj yeem tau txais ntau yam cuab yeej uas peb xav kom muaj hauv tsev kawm ntawv. Yog li, ntu no yooj yim dua qhov peb xav tau. Qhov tshwj xeeb lawv tus kheej kuj hloov pauv tau. Ua ntej peb kos lub duab plaub rau ntawm cov ntoo ntoo. Qhov tshwj xeeb me me tsis muaj teeb meem ntau dhau, vim nws yooj yim ua haujlwm ua lub platform tso cov leds thiab khoom siv hluav taws xob rau.

Tom qab ntawd peb tau laum tsib 1/8 hauv qhov ntawm peb daim ntoo.

Peb tom qab ntawd txiav tawm cov duab plaub los ntawm cov ntoo los siv ua peb lub platform rau peb cov khoom siv hluav taws xob.

(Nov yog thaum peb pib; peb pom qhov pom loj dua!)

Tom qab ntawd peb thawb lub anode thiab cathode pins ntawm tus coj mus rau hauv lub qhov; cov leds yuav tsum tau tso rau saum, lawv qhov muag teev tawm; taug qab seb ceg twg ntev dua thiab luv dua. Tom qab ntawd peb tau teeb tsa los pib ua ke ua ke cov xov hlau. Ua ntej peb tso cov resistors rau anode ceg ntawm LED (ceg ntev dua).

Tom qab ntawd, peb muab cov hlua cathode ntawm LEDs rau ib leeg tooj liab hlau uas peb yuav siv los ua av. Nws yuav tsum zoo li no.

Tom qab peb ua qhov ntawd, peb txuas tus txiv neej kawg ntawm poj niam-txiv neej jumper cables mus rau qhov kawg ntawm txhua tus tiv thaiv thiab tooj liab hauv av xaim. Thaum peb ua li ntawd, peb tuaj yeem pib ntsaws cov xov hlau rau hauv raspberry PI GPIO pins. Nov yog daim duab! Txawm li cas los xij, nco ntsoov, cov pins yog cov uas tau kov yav dhau los raws li txoj cai.

Thaum koj muaj tag nrho cov xov txuas, tam sim no txhua yam koj yuav tsum ua yog tau txais Python cov ntaub ntawv mus rau raspberry Pi thiab qhib lub davhlau ya nyob twg. khiav "python3 RaspberryPIWeatherStation.py" thiab tom qab ntawd ua raws li nws qhia.

Kauj Ruam 8: Kev Qhia Tawm thiab Xaus

Ua tsaug rau kev nyeem txhua txoj hauv kev! Kuv mam xa cov ntawv nab nab hauv qab no! Yog tias muaj qee yam peb tuaj yeem ntxiv, nws yuav yog …

1. Txhawb nqa rau ntau hom kev tawm tswv yim (lub nroog, cov ntsiab lus thaj chaw, thiab lwm yam)

2. Txhawb kom muaj xov xwm ntau ntxiv txog huab cua

3. Ntxiv lub vijtsam me me los qhia cov ntaub ntawv

Qhia rau peb paub koj cov kev xav! Nov yog qhov project lom zem los tsim. Peb tau kawm ntau yam txog kev thov thiab tau txais cov ntaub ntawv internet siv nab hab sej, thiab peb kuj tau kawm ntau yam txog kev siv cov laug.

Pom zoo: