Cov txheej txheem:

Sodial Dust Sensor ntawm Android: 6 Cov Kauj Ruam
Sodial Dust Sensor ntawm Android: 6 Cov Kauj Ruam

Video: Sodial Dust Sensor ntawm Android: 6 Cov Kauj Ruam

Video: Sodial Dust Sensor ntawm Android: 6 Cov Kauj Ruam
Video: Как это вообще работает? Разбираем совсем одноразовый мотор 1.0 Ecoboost от Ford 2024, Kaum ib hlis
Anonim
Sodial Plua Plav Sensor ntawm Android
Sodial Plua Plav Sensor ntawm Android

Ib xyoos dhau los ib tus phooj ywg ntawm kuv tau muaj lub rooj cob qhia lis xaus txog kev saib xyuas ib puag ncig. Lub hom phiaj ntawm qhov kev cob qhia yog txhawm rau txhim kho lub plua plav sensor txuas nrog rau lub rooj sib tham raspberry pi txhawm rau ntsuas cov ntaub ntawv ntawm qee tus neeg rau zaub mov uas tau muab cov ntaub ntawv qhia txog hmoov av tas li. Kuv tus phooj ywg nug yog tias muaj txoj hauv kev kom tau txais cov ntaub ntawv sensor ncaj qha ntawm nws lub xov tooj smartphone rau kev saib xyuas thiab txiav txim siab. Yog li kuv khawb internet rau cov ntawv teev tseg thiab pom tias lub sensor muaj qhov yooj yim UART interface nrog 9600Baud 8N1 raws tu qauv. Tab sis yuav ua li cas txuas UART rau lub xov tooj smartphone? Zoo, qhov yooj yim. Kuv tsuas yog tau siv ib qho ntawm cov ubiquitous me ntsis Bluetooth modules uas muab kev ua kom zoo sib xws ntawm Android. Tam sim no saib yuav ua li cas kuv ua nws.

Kauj Ruam 1: Yam Koj Xav Tau

Yam Koj Xav Tau
Yam Koj Xav Tau
Yam Koj Xav Tau
Yam Koj Xav Tau

Koj xav tau cov hauv qab no

  • Kev sib txuas sib txuas JST XH 7-pin rau Sodial interface nrog cov xov hlau. Kuv yuav kuv li ntawm Ebay.
  • Bluetooth module HC05 lossis 06 sib xws nrog UART txuas
  • USB-serial converter nrog TTL qib interface. Peb siv qhov no los muab BT-module lub npe tshwj xeeb
  • Sodial SDS011 hmoov av sensor. Kuv tau txais kuv los ntawm Ebay
  • ib qho ntawm veroboard
  • USB-B txuas
  • xaim
  • Ib daim ntoo los txhim kho txhua yam

Tom qab ntawd koj yuav xav tau qee yam cuab yeej yooj yim:

  • Ib tug bucksaw rau txiav ntoo
  • tweezers
  • solder hlau thiab solder
  • hlau txiav
  • Kub kua nplaum phom
  • Ib daim ntawm 8mm lub tes tsho silicon (tsis nyob ntawm daim duab)

Koj tuaj yeem rub tawm Sodial SDS011 cov ntawv ntawm no Sodial SDS011 cov ntawv teev npe

Kauj ruam 2: Npaj Bluetooth Module

Npaj Bluetooth Module
Npaj Bluetooth Module
Npaj Bluetooth Module
Npaj Bluetooth Module
Npaj Bluetooth Module
Npaj Bluetooth Module
Npaj Bluetooth Module
Npaj Bluetooth Module

BT-Module muaj UART interface nrog TTL-qib. Nws tuaj yeem rov kho dua nrog "AT" cov lus txib zoo li peb tau ua nrog internet modem rov qab rau hauv lub sijhawm qub. Txhawm rau txuas nws mus rau lub davhlau ya nyob twg ntawm koj lub tshuab koj yuav tsum hloov kho UART rau koj lub khoos phis tawj. Kuv siv USB-RS232 hloov pauv kuv yuav ntawm amazon. Kuv tau thov qhov txuas rau BT-module thiab xa cov 3, 3V fais fab mov thiab GND los ntawm kev hloov pauv mus rau BT-module. Tom qab ntawd kuv txuas cov kab TxD thiab RxD sib txawv hauv kev hla. TxD los ntawm USB-hloov mus rau RxD los ntawm BT-module thiab hloov pauv.

Kuv muaj lub tshuab linux thiab siv cutecom. Tom qab txuas lub USB-hloov pauv lub comport yog "ttyUSB0". Koj tuaj yeem pom cov npe comport hauv "/dev" phau ntawv teev npe ntawm koj lub tshuab linux. Rau cov neeg siv windows kuv xav kom "hterm". Nws yooj yim rau kev khiav lag luam. Ntaus "AT" thiab koj yuav tsum tau txais "AT" raws li cov lus teb. Tom qab ntawv ntaus "AT+NameSensor" los muab BT-module lub npe "Sensor"

Kauj Ruam 3: Mounting Qhov

Mounting Qhov
Mounting Qhov
Mounting Qhov
Mounting Qhov
Mounting Qhov
Mounting Qhov
Mounting Qhov
Mounting Qhov

Txiav ib daim ntoo hauv qhov loj me kom haum rau txhua qhov. Txuas txhua lub cim qhia raws li qhia hauv schematic. Nws yog lub tswv yim zoo kom muab lub tes tsho silicon nyob ib puag ncig cov xov hlau los tiv thaiv lawv. Siv lub USB-B ntsaws rau ntawm lub qhov txhab. Nws tsuas yog siv rau kev siv fais fab. Txhim kho txhua ntu nrog cov ntsia hlau ntawm lub hauv paus ntoo. Thaum kawg kub nplaum cov hlua los kho lawv ntawm ntoo.

Kauj ruam 4: Kev sib tw

Ua khub
Ua khub
Ua khub
Ua khub

Hwj chim daim ntawv thov sensor los ntawm ntsaws-hauv USB fais fab mov. Ib lub LED liab ntawm BT-module yuav pib ntsais muag. Tsis txhob sim ua ke nrog koj lub Android smartphone. Koj yuav tsum sau tus lej lej. Qhov no yog "1234". Tom qab nkag mus rau tus lej koj lub smartphone yuav tsum tau ua khub nrog BT-module.

Kauj ruam 5: Software

Kuv nyiam sau Android apps ntawm lub hom phiaj platform nws tus kheej. nws txuag koj los ntawm txhua yam khoom uas koj yuav tsum tau saib xyuas yog tias koj tab tom ua haujlwm nrog Android Studio. Kuv pom peb qhov tsim nyog tsim nyog cov cuab yeej ntawm Android nws tus kheej

  • Mintoris yooj yim. Tus neeg txhais lus yooj yim nrog ntau cov lus txib kom tinker ncig nrog yuav luag txhua yam ntawm Android. Koj tuaj yeem tsim cov ntawv luv rau koj cov apps. Mintoris yooj yim tsis muaj tus sau. Yog li koj yuav tsum tau teeb tsa Mintoris ntawm txhua lub cuab yeej koj tab tom siv. Tab sis koj tsuas yog yuav tsum tau them rau nws ib zaug (txog 7 €)
  • Yooj yim! Zoo heev Basic Tus neeg txhais lus thiab tus neeg sau (ntxiv rau qee qhov €). Yuav luag nqes ntawm txhua yam hauv Android thiab koj tuaj yeem suav sau cov apps tiag rau faib rau lawv yam tsis muaj Basic! ntawm lub hom phiaj ntaus ntawv. Tu siab kawg Basic! tsis muaj daim duab kos duab zoo tshaj ntawm Mintoris
  • AIDE yog ib nrab kws tshaj lij IDE rau ua Android kev txhim kho hauv java ntawm Android. Nrog AIDE koj muaj qhov yooj yim tshaj plaws tab sis koj yuav tsum kawm java. AIDE muaj tus nqi txhua xyoo txog 50 €

Kuv xaiv Mintoris. Hauv ntu no kuv yuav tsis qhia koj txog kev qhia ua haujlwm hauv Mintoris tab sis piav qhia luv luv ntawm cov haujlwm ua haujlwm

Hauv ib feem hauv qab no peb cov arrays tau tshaj tawm rau ob kab ntawv cov ntaub ntawv thiab cov sijhawm sib xws. Cov ntaub ntawv timestamp yog siv rau daim ntawv lo x-axis ntawm daim duab. Lub Sodial tso tawm ob cov ntaub ntawv ntws txhua qhov tshwj xeeb rau qhov loj me me tshwj xeeb. Ob lub dustdata-arrays coj cov txiaj ntsig no.

WakeLock Ib nrab

TextColor 100, 75, 10

TextColorA 50, 50, 50

TextAlign 0 NPE

TextSize ntawm 24

CLS

Popup "Meter Sensor Meter (c) ARJ 2017"

Ntiaj teb dustData (), dustDataF (), timeStamp () Ntiaj teb kev ntsuas, xaiv, maxData, fileName $

Dim lub sij hawm Stamp (59)

Dim plua plav ntaub ntawv (59)

Dim hmoov avDataF (59)

Dim Menu $ (4) = "max. 100 datasets", "max. 1000 data sets", "max. 5000 data sets", "max. 10000 data sets", "Exit"

'Pib cov arrays

Rau kuv = 0 txog 59

dustData (kuv) = 0

dustDataF (i) = 0

timeStamp (i) = kuv

Tom ntej no kuv

Tom ntej no List Menue tau teeb tsa. Qhov no muab cov neeg siv xaiv los xaiv qhov loj tshaj plaws ntawm cov ntaub ntawv los sau. Qhov no tsuas yog kev hloov pauv kev nyab xeeb txhawm rau tiv thaiv lub xov tooj smartphone los ntawm kev nqus cov ntaub ntawv tsis muaj qhov kawg. Cov Haujlwm BTgetPaired $ () muab rov qab cov npe nrog txhua cov khoom siv ua ke ntawm lub cuab yeej Android, lawv lub npe thiab BT-chaw nyob.

L ist Ntawv qhia zaub mov $ (), xaiv

'Xaiv qhov nyiaj ntau tshaj yog cov ntaub ntawv khaws cia

runLevel = 1

Xaiv xaiv

Case 0 maxData = 100

Case 1 maxDate = 1000

Case 2 maxData = 5000

Case 3 maxData = 10000

Cov ntaub ntawv 4 maxData = 0

Xeem Xaiv

'' Txuas sensor

sib npaug $ (0)

khub $ () = BTGetPaired $ ()

Yog khub $ (0) = "tsis muaj" Tom qab ntawd

Luam tawm "Tsis pom cov cuab yeej ua ke. BT puas tau qhib?" Luam tawm "Qhov program raug kaw"

Xaus

Endif

Sau tus khub $ (), ntaus ntawv $

npe $ = ItemExtract $ (ntaus ntawv $, 0)

chaw nyob $ = ItemExtract $ (ntaus ntawv $, 1)

BTC txuas 1, chaw nyob $

'Tos rau kev txuas

Kev vam meej ON

Luam "Sim txuas rau"; chaw nyob $

Rau kuv = 1 txog 20

Kev vam meej i/2

Yog BTGetstate (1) = 4 Ces Tawm Rau Tos 1000

Tom ntej no kuv

Kev kawm tawm

'Ntawm kev ua tiav txuas rau BT lub cuab yeej

Yog BTGetState (1) = 4 Tom qab ntawd Luam "Txuas" Lwm Cov Ntawv Luam "Tsis tuaj yeem txuas rau"; npe $

Luam tawm "Qhov program raug kaw"

Xaus

Endif

Qhov thaiv tom ntej qhia cov ntaub ntawv xav tau. Rau txhua qhov kev sib ntsib cov ntaub ntawv cov ntaub ntawv tau qhib thiab muaj npe tom qab lub sijhawm thiab hnub tim. Tom qab ntawd lub voj tau nyeem cov ntaub ntawv sensor. Cov ntaub ntawv tau ntim rau hauv ob peb bytes. Ib pawg ntawm bytes tau txheeb xyuas los ntawm ob lub cim ASCII 170 thiab 171. Cov ntaub ntawv hauv qab no tau rov teeb tsa thiab sau rau hauv cov hmoov av-arrays

Duab Nyob

'Qhib cov ntaub ntawv sau

fileName $ = FormatTime $ (t, "yyyy-MM-dd-kk-mm-ss") + ".dat"

Qhib 1, fileName $, "w+" Luam tawm "Qhib cov ntaub ntawv"; fileName $ Writeln 1, FormatTime $ (Sijhawm (), "yy-MM-dd")

Sau ntawv 1, "Sijhawm Dust2.5 Dust10"

'Sau array nrog cov ntaub ntawv ntsuas

cov ntaub ntawv $ = "" pob ntawv $ = ""

index = 0 os

Ua Thaum maxData> 0

BTRead 1, pob ntawv $, 10

data $ = data $+pob ntawv $

Yog Len (cov ntaub ntawv $)> = 10 Tom qab ntawd

Yog tias (ASCII (Sab laug $ (cov ntaub ntawv $, 1)) = 170) & (ASCII (Txoj Cai $ (cov ntaub ntawv $, 1)) = 171) Tom qab ntawd

dustDataF (index) = ASCII (Mid $ (cov ntaub ntawv $, 2, 1))

dustDataF (index) = (dustDataF (index)+256*ASCII (Mid $ (cov ntaub ntawv $, 3, 1)))/10

dustData (index) = ASCII (Mid $ (cov ntaub ntawv $, 4, 1))

dustData (index) = (dustData (index)+256*ASCII (Mid $ (cov ntaub ntawv $, 5, 1)))/10

Sau ntawv 1, FormatTime $ (Sijhawm (), "kk: mm: ss") + "" + Str $ (dustDataF (index)) + "" + Str $ (dustData (index)))

cov ntaub ntawv $ = ""

maxData = maxData-1

index = cov+1

Yog tias qhov ntsuas> 59 Tom qab ntawv ntsuas = 0

dustData (cov ntaub ntawv) = 0

dustDataF (index) = 0

Endif

Endif

Kos duab ()

Tos 100

Loop

Kaw 1

Duab Tawm

CLS Luam tawm "Qhov haujlwm raug kaw"

Xaus

Qhov kawg yog subroutine uas tau hu tom qab txhua qhov kev txais tos cov ntaub ntawv. Nws tshem tawm lub vijtsam, rov ua dua daim duab nrog cov ntaub ntawv tiag tiag khaws cia hauv cov hmoov av- thiab cov sijhawm teev tseg.

'Kos cov kab ke, cov ntawv cim, zuam thiab cov ntaub ntawv nkhaus

Sub DrawGraph ()

'Hauv Graphics hom lub vijtsam pom tseeb rau xim tam sim no

Xim 0, 0, 0

CLS

Xim 0, 0, 100

'Teeb cov duab xim kom siv los kos kab kab

TextColor 100, 100, 100, 50

'TextColor yog xim ntawm daim phiaj npe tseem ceeb

TextColorA 100, 100, 100

'TextColorA yog siv rau Axis lub npe thiab kab lus piav qhia.

'Teev qhov loj ntawm txoj kab ntawv lub npe

'Daim phiaj npe tseem ceeb yog 2x qhov loj me

Text loj 20

FixDecimal 0

'Teeb kom pom 2 qhov chaw sib luag

PadDigits 2

'Kos ib daim phiaj rau kab ntawv' Teem ntau yam thiab lub npe ntawm X & Y

Axis AxisX 0, 59, "Sijhawm/s"

AxisY 0, 10000, "ug/m3"

Daim phiaj 3, "Lub plua plav concentration"

'Kos Duab Plua Plav

Xim 100, 0, 0

GraphXY timeStamp (), dustDataF ()

Xim 0, 100, 0

GraphXY timeStamp (), dustData ()

TextColor 100, 0, 0

DrawText "PM2.5", 30, Int (ScreenY ()-60), 90, 1

TextColor 0, 100, 0

DrawText "PM10", 30, Int (ScreenY ()-150), 90, 1

TextColor 100, 100, 100, 50

Rov qab los

Rub tawm qhov chaws ntawm no

Kauj Ruam 6: Xeem

Image
Image
Kuaj
Kuaj
Kuaj
Kuaj
Kuaj
Kuaj

Fais fab lub sensor thiab pib lub app. Los ntawm cov npe ntawm cov khoom siv ua ke xaiv ib lub npe hu ua "Sensor". Tom qab txuas lub sensor lub vijtsam yuav pib tso tawm cov ntaub ntawv. Ib txhij cov ntaub ntawv cov ntaub ntawv raug faib. Tom qab ua tiav kev zam koj tuaj yeem siv GnuPlot los tso saib cov ntaub ntawv. Siv cov ntawv "Test.gp" hauv GnuPlot los teeb tsa GnuPlot rau kev tso saib cov ntaub ntawv npe hu ua "Test.dat". Koj cov kaus poom kuj pom nws nyob ntawm no

Saib cov vis dis aus kom paub meej ntxiv thiab sim. Muaj kev lom zem ntau thiab ntau lub tswv yim!

Pom zoo: