Cov txheej txheem:

RuuviTag thiab PiZero W thiab Blinkt! Bluetooth Beacon Raws Tus Ntsuas Kub: 3 Kauj Ruam (nrog Duab)
RuuviTag thiab PiZero W thiab Blinkt! Bluetooth Beacon Raws Tus Ntsuas Kub: 3 Kauj Ruam (nrog Duab)

Video: RuuviTag thiab PiZero W thiab Blinkt! Bluetooth Beacon Raws Tus Ntsuas Kub: 3 Kauj Ruam (nrog Duab)

Video: RuuviTag thiab PiZero W thiab Blinkt! Bluetooth Beacon Raws Tus Ntsuas Kub: 3 Kauj Ruam (nrog Duab)
Video: Часы G-Shock до 250 долларов-15 лучших часов Casio G до 250 доллар... 2024, Hlis ntuj nqeg
Anonim
RuuviTag thiab PiZero W thiab Blinkt! Bluetooth Beacon Raws Tus Ntsuas Kub
RuuviTag thiab PiZero W thiab Blinkt! Bluetooth Beacon Raws Tus Ntsuas Kub
RuuviTag thiab PiZero W thiab Blinkt! Bluetooth Beacon Raws Tus Ntsuas Kub
RuuviTag thiab PiZero W thiab Blinkt! Bluetooth Beacon Raws Tus Ntsuas Kub
RuuviTag thiab PiZero W thiab Blinkt! Bluetooth Beacon Raws Tus Ntsuas Kub
RuuviTag thiab PiZero W thiab Blinkt! Bluetooth Beacon Raws Tus Ntsuas Kub

Cov lus qhia no piav qhia txoj hauv kev los nyeem cov ntaub ntawv ntsuas kub thiab av noo los ntawm RuuviTag siv Bluetooth nrog Raspberry Pi Zero W thiab los tso saib qhov tseem ceeb hauv tus lej binary ntawm Pimoroni blinkt! pHAT. Or los muab nws luv luv: yuav ua li cas thiaj tsim tau lub xeev ntawm kev kos duab thiab tus pas ntsuas kub me ntsis.

RuuviTag yog qhov qhib qhov qhib sensor bluetooth lub teeb uas los nrog qhov ntsuas kub/av noo/siab thiab ntsuas lub ntsuas cua, tab sis kuj tseem tuaj yeem ua raws li tus qauv Eddystone ™/iBeacon sib thooj teeb liab. Nws yog qhov haujlwm Kickstarter ua tiav thiab kuv tau txais kuv li ob peb lub lis piam dhau los. Muaj Github nrog nab hab sej software los nyeem RuuviTag siv raspberry, thiab kuv tau siv ib qho ntawm lawv cov piv txwv, nrog qee qhov ntxiv.

Raspberry Pi Zero W yog tus tswv cuab tshiab ntawm RPi tsev neeg, ib txwm yog Pi Zero nrog Bluetooth thiab WLAN ntxiv.

Lub blinkt! pHAT los ntawm Pimoroni yog ib puag ncig ntawm yim RBG LEDs teeb tsa ua HAT rau Raspberry Pi. Nws yog qhov siv tau yooj yim heev thiab los nrog lub tsev qiv ntawv sej. Lub tswv yim yog nyeem cov ntaub ntawv los ntawm RuuviTag thiab tso saib nws siv lub ntsais muag! HAT. Cov txiaj ntsig tau muab tso tawm ua tus lej binary siv 7 ntawm LEDs, thaum yim siv los qhia tias cov av noo lossis qhov kub (+/-/0) qhov txiaj ntsig tau tshwm sim.

Kauj ruam 1: Teeb tsa Qhov System

Teeb tsa cov txheej txheem yog yooj yim:- Hloov ntawm RuuviTag (RuuviTag qhov ntsuas kub ntsuas qhov ntsuas).

- Teeb koj li RPi Zero W, RPi3, lossis lwm yam RPi nrog lub peev xwm bluetooth ntxiv, ua raws cov lus qhia ntawm www.raspberrypi.org.

- Tso lub blinkt! HAT ntawm RPi (thaum tawm).

- Nruab lub blinkt! thiab RuuviTag software, raws li qhia hauv cov nplooj ntawv sib xws GitHub.

- Tam sim no koj yuav tsum txheeb xyuas MAC chaw nyob ntawm koj RuuviTag

- luam qhov program Python uas txuas nrog, qhib nws nrog IDLE rau Python 3

- hloov MAC chaw nyob ntawm RuuviTag rau koj li, tom qab ntawd txuag thiab ua haujlwm qhov program.

- xav tias hloov kho thiab ua kom zoo dua qhov program. Qhov kev zov me nyuam los raws li nws yog, siv los ntawm koj tus kheej txoj kev pheej hmoo, tsis muaj kev lav phib xaub rau ib qho kev puas tsuaj.

Kauj Ruam 2: Ntaus Ntawv thiab Txoj Haujlwm

Cov cuab yeej thiab qhov program
Cov cuab yeej thiab qhov program
Cov cuab yeej thiab qhov program
Cov cuab yeej thiab qhov program
Cov cuab yeej thiab qhov program
Cov cuab yeej thiab qhov program
Cov cuab yeej thiab qhov program
Cov cuab yeej thiab qhov program

Raws li tau hais los saum toj no, lub tswv yim yog los tsim cov txheej txheem yooj yim thiab pheej yig los nyeem cov ntaub ntawv los ntawm lub teeb thiab teeb tus lej lej ntawm qhov ntsais! HAT, lossis zoo ib yam LED sawb.

Qhov ntau ntawm qhov ntsuas kub yuav raug ntsuas nrog RPi raws qhov system feem ntau yuav nyob qhov twg ntawm - 50 ° C thiab +80 ° C, rau cov av noo ntawm 0 thiab 100%. Yog li cov zaub uas tuaj yeem muab qhov tseem ceeb ntawm -100 txog +100 yuav txaus rau feem ntau daim ntawv thov. Cov lej zauv me me li 128 tuaj yeem tso tawm ua tus lej binary nrog 7 khoom (lossis LEDs). Yog li qhov kev zov me nyuam siv qhov ntsuas kub thiab av noo los ntawm RuuviTag li "ntab" tus lej thiab hloov pauv lawv mus rau tus lej binary, uas tom qab ntawd tshwm rau ntawm qhov ntsais!

Ua thawj kauj ruam, tus lej tau muab sib npaug, tshuaj xyuas yog tias zoo, tsis zoo lossis xoom, thiab tom qab ntawd hloov pauv mus rau tus lej zoo siv "abs". Tom qab ntawd tus lej zauv tau hloov pauv mus rau 7-tus lej binary tooj, feem ntau yog txoj hlua ntawm 0s thiab 1s, uas tau tshuaj xyuas thiab nthuav tawm ntawm 7 pixels kawg ntawm qhov ntsais!

Txog qhov ntsuas kub thawj pixel qhia yog tias tus nqi zoo (liab), xoom (magenta) lossis tsis zoo (xiav). Qhia cov av noo qhov tseem ceeb nws tau teeb rau ntsuab. Txhawm rau ua kom yooj yim kev ntxub ntxaug ntawm qhov kub thiab txias qhov tseem ceeb binary pixels tau teeb tsa dawb rau qhov kub thiab daj rau cov av noo. Txhawm rau txhim kho kev nyeem tau ntawm cov lej binary, "0" pixel tsis tau muab tua tag nrho, tab sis hloov pauv tau teeb tsa ntau dua li hauv "1" xeev. Raws li blinkt! pixels yog qhov ci ntsa iab, koj tuaj yeem teeb tsa qhov dav dav hloov pauv qhov ntsuas "ci"

Qhov kev zov me nyuam qhia qhov muaj nuj nqis thiab ib feem ntawm cov txheej txheem tseem nyob ntawm qhov screen. Ib qho ntxiv koj yuav pom ob peb lub suab ntsiag to (#) luam tawm cov lus qhia. Kuv tso lawv rau hauv, zoo li koj yuav pom lawv pab tau kom nkag siab cov txheej txheem yog tias tsis muaj suab npe.

Qhov tseem ceeb kuj tseem yuav muab khaws cia rau hauv cov ntaub ntawv teev cia.

Kauj Ruam 3: Txoj Cai Code

Cov cai tau debugged me ntsis thiab ua kom zoo dua. Tam sim no koj tuaj yeem pom version 3 (20_03_2017).

'Qhov haujlwm no yog npaj los nyeem qhov ntsuas kub, av noo thiab ntsuas qhov ntsuas tsim RuuviTag' 'thiab txhawm rau ntsuas qhov ntsuas kub thiab av noo raws li tus lej binary ntawm Pimorini blinkt! HAT. '' '' Nws yog raws li print_to_screen.py piv txwv los ntawm lub tsev qiv ntawv ruuvitag ntawm github. '' Yuav tsum muaj Pi Zero W, Pi 3 lossis lwm yam RPi nruab nrog bluetooth thiab txhua lub tsev qiv ntawv tsis tuaj yeem teeb tsa. '

lub sij hawm ntshuam

ntshuam os los ntawm datetime ntshuam datetime

los ntawm ruuvitag_sensor.ruuvi ntshuam RuuviTagSensor

los ntawm blinkt ntshuam set_clear_on_exit, set_pixel, meej, qhia

def temp_blinkt (bt): cov

# qhov kev niaj hnub no siv tus ntsuas kub thiab qhia nws ua tus lej binary ntawm blinkt!

meej ()

# xim thiab siv ntawm "1" pixels: dawb

r1 = 64 g1 = 64 b1 = 64

#xim thiab siv "0" pixels: dawb

r0 = 5g0 = 5b0 = 5

# Hloov thiab hloov pauv mus rau qhov tseem ceeb

r = puag ncig (bt)

# vz sawv cev rau algebraic kos npe rau qhov taw qhia pixel

yog (r> 0): vz = 1 # zoo elif (r <0): vz = 2 # tsis zoo ntxiv: vz = 0 # zero # print (vz) i = abs (r) #print (i)

# hloov pauv kom meej, 7-tus lej binary tooj

i1 = i + 128 # rau kuv ua rau hauv 8-tus lej binary lej pib nrog 1 # luam tawm (i1)

b = "{0: b}". format (i1) # hloov mus rau binary

# luam tawm (b)

b0 = str (b) # hloov mus rau txoj hlua

b1 = b0 [1: 8] #txiav thawj ntsis

print ("binary naj npawb:", b1)

# Teeb pixels ntawm blinkt!

# teeb tsa tus lej binary

rau h hauv thaj tsam (0, 7): f = (h+1) yog (b1 [h] == "1"): set_pixel (f, r1, g1, b1) # print ("ntsis", h, " yog 1, pixel ", f) lwm yam: set_pixel (f, r0, g0, b0) # print (" nil ")

# Teeb tus cim pixel

yog (vz == 1): set_pixel (0, 64, 0, 0) # liab rau qhov muaj txiaj ntsig zoo elif (vz == 2): set_pixel (0, 0, 0, 64) # xiav rau qhov tsis zoo ntxiv: set_pixel (0, 64, 0, 64) # magenta yog xoom

qhia ()

# kawg ntawm temp_blinkt ()

def hum_blinkt (bh): cov

# qhov no siv tus nqi vaum thiab qhia nws ua tus lej binary ntawm blinkt!

meej ()

# xim thiab siv ntawm "1" pixels: daj

r1 = 64 g1 = 64 b1 = 0

#xim thiab siv ntawm "0" pixels:

r0 = 5g0 = 5b0 = 0

# Hloov pauv thiab hloov pauv mus rau qhov tseem ceeb

r = puag ncig (bh)

# hloov pauv mus rau qhov tseeb, 7-tus lej binary tooj i = abs (r) #print (i)

i1 = i + 128 # rau kuv muab tus lej 8 tus lej binary pib nrog 1

# luam tawm (i1)

b = "{0: b}". hom ntawv (i1)

# luam tawm (b)

b0 = str (b)

b1 = b0 [1: 8] #txiav thawj ntsis

print ("binary naj npawb:", b1)

# Teeb pixels ntawm blinkt!

# teeb tsa tus lej binary rau pixels

rau h hauv thaj tsam (0, 7): f = (h+1) yog tias (b1 [h] == "1"): set_pixel (f, r1, g1, b1) ntxiv: # ntsiag to kom tsis muaj teeb meem LEDs set_pixel (f, r0, g0, b0) # ntsiag to LED dawb paug

# Teeb tus cim pixel

set_pixel (0, 0, 64, 0) # ntsuab rau cov av noo

qhia ()

# kawg ntawm hum_blinkt ()

set_clear_on_exit ()

# Nyeem cov ntaub ntawv los ntawm RuuviTag

mac = 'EC: 6D: 59: 6D: 01: 1C' # Hloov mus rau koj tus kheej lub cuab yeej mac-chaw nyob

print ('Pib')

sensor = RuuviTagSensor (mac)

thaum Muaj Tseeb:

cov ntaub ntawv = sensor.update ()

line_sen = str.format ('Sensor - {0}', mac)

line_tem = str.format ('Kub: {0} C', data ['kub']) line_hum = str.format ('Vaum: {0} %', data ['humidity']) line_pre = str.format ('Siab: {0}', cov ntaub ntawv ['siab'])

luam tawm ()

# tso saib qhov kub ntawm blinkt! ba = str.format ('{0}', data ['temperature']) bt = float (ba) print (bt, "C ° C") temp_blinkt (bt) print ()

time.sleep (10) # tso saib kub li 10 vib nas this

# tso cov av noo ntawm blinkt!

bg = str.format ('{0}', data ['humidity']) bh = ntab (bg) print (bh, " %") hum_blinkt (bh) print ()

# Ntshiab lub vijtsam thiab luam cov ntaub ntawv sensor rau lub vijtsam

os.system ('clear') print ('Nias Ctrl+C kom tawm. / n / n') print (str (datetime.now ()))) print (line_sen) print (line_tem) print (line_hum) print (line_pre)) print ('\ n / n / r …….')

# Tos li ob peb feeb thiab pib dua

sim: time.sleep (8) tshwj tsis yog KeyboardInterrupt: # Thaum Ctrl+C raug nias ua tiav ntawm lub sijhawm lub voj raug nres luam tawm ('Tawm') meej () qhia () so

Pom zoo: