Cov txheej txheem:

IoT - Portable Mood Reporter: 4 Kauj Ruam
IoT - Portable Mood Reporter: 4 Kauj Ruam

Video: IoT - Portable Mood Reporter: 4 Kauj Ruam

Video: IoT - Portable Mood Reporter: 4 Kauj Ruam
Video: 20 MOMENTS YOU WOULDN'T BELIEVE IF NOT FILMED 2024, Hlis ntuj nqeg
Anonim
IoT - Portable Mood Reporter
IoT - Portable Mood Reporter

Yam peb yuav xav tau:

  • Raspberry Pi nrog Raspbian
  • Kov Sensor los ntawm adafruit
  • Hwj chim Source (Roj teeb/DC)
  • Ethernet lossis WiFi rau Raspberry Pi
  • Lwm lub computer

Kauj Ruam 1: Teeb Peb Raspberry Pi Kho Vajtse

Teeb Peb Raspberry Pi Khoos Phis Tawj
Teeb Peb Raspberry Pi Khoos Phis Tawj
Teeb Peb Raspberry Pi Khoos Phis Tawj
Teeb Peb Raspberry Pi Khoos Phis Tawj

Ua ntej tshaj, txuas peb lub ntsuas ntsuas mus rau GPIO pins ntawm peb Raspberry Pi. Siv qee cov kab uas hloov pauv tau

Txheeb xyuas 3 tus pin ntawm peb lub sensor:

  • GND - txuas rau tus pin hauv av
  • VCC - txuas rau 5V tus pin
  • SIG - txuas rau tus lej cim npe

Peb yuav siv 5V, hauv av thiab GPIO 18 ntawm peb cov raspberry pi hauv qhov piv txwv no.

Kauj Ruam 2: Teeb Peb Ib puag ncig ntawm Raspberry Pi

Kev teeb tsa Peb Ib puag ncig ntawm Raspberry Pi
Kev teeb tsa Peb Ib puag ncig ntawm Raspberry Pi

Tau txais IP chaw nyob ntawm peb raspberry Pi.

Tom qab ntawv txuas rau peb cov raspberry pi siv ssh:

ssh username@ipaddress

tom qab ntawd ntaus peb tus password.

Thaum peb nyob hauv, tom qab ntawd nruab apache2 raws li peb lub vev xaib los ntawm kev ntaus hauv:

sudo apt-tau nruab apache2

Kauj Ruam 3: Tsim Ib Daim Python Code Nyeem Ntawv Los Ntawm Peb Lub Sensor

Tsim Ib Daim Python Code Nyeem Ntawv Los Ntawm Peb Lub Sensor
Tsim Ib Daim Python Code Nyeem Ntawv Los Ntawm Peb Lub Sensor

Tsim

Hauv peb tus lej piv txwv, peb siv ob peb qhov lus txib sib txawv.

Txhawm rau qhia tias peb zoo siab, peb ua 2 ntev nias

Txhawm rau qhia tias peb tu siab, peb ua ib lub kais luv, thiab nias ntev

Txhawm rau qhia tias peb tsis meej pem, peb ua ib lub kais luv, tos kom nrawm, tom qab ntawd 2 lub kais dej luv. Txhawm rau qhia tias peb zoo siab, peb ua ib tus kais luv, ib qho luv luv, thiab nias ntev

Txhawm rau qhia tias peb tau dhuav, peb 3 lub kais dej luv

Txhais cov no rau cov lus txib: (t rau kais luv, T rau nias ntev, g rau qhov sib txawv luv, G rau qhov sib txawv ntev)

zoo: tgt

siab: tg

tsis meej: tGtgt

siab: tgtgt

Tom qab ntawd peb yuav muaj peb cov cai tso tawm peb qhov kev xav tam sim no rau hauv browser-phooj ywg html cov ntaub ntawv rau kev ua haujlwm.

Code

ntshuam RPi. GPIO ua GPIOimport lub sijhawm

GPIO.cleanup ()

GPIO.setmode (GPIO. BCM) GPIO.setup (18, GPIO. IN)

cov_count = 0

touch_state = 0 touch_duration = 0 gap_duration = 0 current_cmd = ""

def cmd (): ua

ntiaj teb tam sim no_cmd yog tam sim no_cmd [-3:] == "TgT": current_cmd = "" kev xav ("Tu siab") yog tam sim no_cmd [-3:] == "tgT": current_cmd = "" kev xav ("Zoo siab") yog tam sim no_cmd [-5:] == "tGtgt": current_cmd = "" mood ("Tsis meej pem") yog current_cmd [-5:] == "tgtgt": current_cmd = "" mood ("Bored")

def mood (kev xav):

file = qhib ("index.html", "w") html = """

Portable Mood Reporter

Hav, kuv qhov kev xav tsis ntev los no yog

{}

"""

file.write (html.format (kev xav))

thaum (1):

time.sleep (0.001) yog (GPIO.input (18)): yog touch_state == 0: yog gap_duration> 2000: gap_duration = 0 yog gap_duration> 200: current_cmd = current_cmd + "G" ntxiv: current_cmd = current_cmd + "g "gap_duration = 0 touch_state = 1 touch_count = touch_count + 1 yog touch_state == 1: touch_duration = touch_duration + 1 ntxiv: yog gap_duration 200: current_cmd = current_cmd +" T "ntxiv: current_cmd = current_cmd +" t "touch_duration = 0 cmd ()

GPIO.cleanup ()

Teeb kom ua haujlwm nrog peb lub vev xaib

ntaus lossis xa cov ntaub ntawv nab hab sej saum toj no rau hauv peb qhov chaw webserver, uas yog defaulted rau/var/www/html

cd/var/www/html

sudo nano touch.py

Tom qab ntawv ntaus cov cai saum toj no

Kauj Ruam 4: Pib Peb Cov Neeg rau zaub mov kom pom nws hauv Kev Ua

Pib Peb Cov Neeg rau zaub mov kom pom nws hauv Kev Ua!
Pib Peb Cov Neeg rau zaub mov kom pom nws hauv Kev Ua!

cd/var/www/html

sudo nab hab sej touch.py

Tom qab ntawv ntaus tus IP chaw nyob rau peb Raspberry Pi, tom qab ntawd peb yuav tsum pom peb tus kws tshaj lij xov xwm ua haujlwm!

Sim sib txawv hom kev hais kom ua, thiab nplooj ntawv yuav tsum pib kho tshiab kom pom qhov ntawd!

Pom zoo: