Cov txheej txheem:

Arduino Magnetometer: 5 Kauj Ruam (nrog Duab)
Arduino Magnetometer: 5 Kauj Ruam (nrog Duab)

Video: Arduino Magnetometer: 5 Kauj Ruam (nrog Duab)

Video: Arduino Magnetometer: 5 Kauj Ruam (nrog Duab)
Video: How to Use 9-Axis Sensors on the Arduino - Ultimate Guide to the Arduino #44 2024, Hlis ntuj nqeg
Anonim
Arduino Magnetometer
Arduino Magnetometer

Peb tsim dab tsi?

Tib neeg tsis tuaj yeem txheeb xyuas cov chaw sib nqus, tab sis peb siv cov cuab yeej uas vam khom cov hlau nplaum txhua lub sijhawm. Cov cav, cov ntsuas hluav taws xob, cov ntsuas ntsuas tig, thiab cua tshuab cua, piv txwv li, txhua tus xav tau cov hlau nplaum rau kev ua haujlwm. Phau ntawv qhia no piav qhia yuav ua li cas tsim Arduino raws li lub tshuab ntsuas hluav taws xob uas hnov lub suab sib nqus siv peb Hall effect sensors. Cov duab sib nqus sib nqus ntawm qhov chaw tau tshwm ntawm lub vijtsam me me uas siv isometric projection.

Arduino yog dab tsi?

Arduino yog qhov qhib me me-tus neeg siv-phooj ywg microcontroller. Nws muaj cov tswv yim digital thiab tso tawm pins. Nws kuj tseem muaj cov lej nkag sib piv, uas muaj txiaj ntsig zoo rau kev nyeem ntawv nkag los ntawm cov ntsuas. Cov qauv sib txawv ntawm Arduino muaj. Cov ntawv qhia no piav qhia yuav siv Arduino Uno lossis Arduino MKR1010 li cas. Txawm li cas los xij lwm cov qauv tuaj yeem siv tau ib yam nkaus.

Ua ntej koj pib qhov kev qhia no, rub tawm Arduino kev txhim kho ib puag ncig nrog rau txhua lub tsev qiv ntawv xav tau rau koj tus qauv tshwj xeeb. Kev txhim kho ib puag ncig muaj nyob ntawm https://www.arduino.cc/en/main/software, thiab cov lus qhia teeb tsa muaj nyob ntawm

Dab tsi yog qhov chaw sib nqus?

Cov hlau nplaum ruaj khov siv lub zog ntawm lwm cov hlau nplaum ruaj khov. Kev nqa cov xov hluav taws xob tam sim no siv zog ntawm lwm cov xov hluav taws xob tam sim no. Cov hlau nplaum ruaj khov thiab cov xov hluav taws xob tam sim no siv zog ib leeg ib yam nkaus. Qhov quab yuam ntawm ib chav ntsuas tam sim no yog qhov sib nqus.

Yog tias peb ntsuas qhov ntim ntawm ib yam khoom, peb tau txais tus lej scalar nkaus xwb. Txawm li cas los xij, cov hlau nplaum tau piav qhia los ntawm thaj chaw vector, ntau qhov nyuaj dua. Ua ntej, nws txawv nrog txoj haujlwm thoob plaws txhua qhov chaw. Piv txwv li, daim teb sib nqus ib centimeter los ntawm cov hlau nplaum ruaj khov zoo li yuav loj dua li cov hlau nplaum kaum centimeters deb.

Tom ntej no, qhov sib nqus ntawm txhua qhov chaw hauv qhov chaw yog sawv cev los ntawm vector. Qhov loj ntawm vector sawv cev rau lub zog ntawm cov hlau nplaum. Cov kev taw qhia yog sib npaug rau ob qho kev taw qhia ntawm lub zog thiab cov kev taw qhia ntawm qhov ntsuas tam sim no.

Peb tuaj yeem pom daim duab sib nqus ntawm ib qho chaw raws li xub. Peb tuaj yeem pom daim duab sib nqus thoob plaws qhov chaw los ntawm cov xub ntawm ntau qhov chaw sib txawv, tejzaum nws txawv qhov sib txawv thiab taw qhia hauv cov lus qhia sib txawv. Kev pom tau zoo muaj nyob ntawm https://www.falstad.com/vector3dm/. Lub tshuab ntsuas hluav taws xob uas peb tab tom tsim qhia txog thaj chaw sib nqus ntawm qhov chaw ntawm lub ntsuas cua zoo li tus xub ntawm lub vijtsam.

Dab tsi yog Hall effect sensor, thiab nws ua haujlwm li cas?

Hall effect sensor yog lub cuab yeej me me, pheej yig uas ntsuas lub zog ntawm cov hlau nplaum raws txoj kev tshwj xeeb. Nws yog tsim los ntawm ib daim ntawm semiconductor doped nrog cov nqi ntau dua. Cov zis ntawm qee qhov Hall effect sensors yog analog voltage. Lwm qhov Hall effect sensors muaj kev sib xyaw ua ke thiab tsim tawm digital. Lwm qhov Hall effect sensors tau koom ua ke rau hauv cov cuab yeej loj dua uas ntsuas tus nqi ntws, kev sib hloov nrawm, lossis lwm yam.

Kev siv lub cev tom qab Hall cov txiaj ntsig tau sau tseg los ntawm Lorentz quab yuam sib npaug. Qhov sib npaug no piav qhia txog kev quab yuam ntawm kev txav mus los vim yog hluav taws xob sab nraud thiab sib nqus.

Duab
Duab

Daim duab hauv qab no qhia txog Hall effect. Piv txwv tias peb xav ntsuas lub zog ntawm qhov sib nqus hauv qhov taw qhia ntawm xub xub xiav. Raws li tau qhia nyob rau sab laug ntawm daim duab, peb siv qhov tam sim no los ntawm ib qho ntawm cov khoom siv hluav taws xob ib leeg mus rau qhov kev taw qhia ntawm thaj chaw uas yuav ntsuas. Tam sim no yog ntws ntawm cov nqi, yog li tus nqi hauv cov khoom siv hluav taws xob txav nrog qee qhov nrawm. Qhov kev them nqi no yuav hnov lub zog vim yog thaj chaw sab nraud, raws li qhia hauv ib nrab ntawm daim duab. Cov nqi yuav txav mus los vim yog lub zog thiab sib sau ua ke ntawm cov npoo ntawm cov semiconductor. Cov nqi tsub kom txog thaum quab yuam vim kev tsub nqi sib npaug ntawm qhov quab yuam vim sab nraud sib nqus. Peb tuaj yeem ntsuas qhov ntsuas hluav taws xob hla cov semiconductor, raws li qhia hauv ntu sab xis ntawm daim duab. Qhov ntsuas hluav taws xob yog sib piv rau lub zog ntawm lub tshuab nqus hlau, thiab nws yog nyob rau hauv cov lus qhia ib puag ncig mus rau qhov tam sim no thiab cov kev taw qhia ntawm qhov chaw sib nqus.

Duab
Duab

Isometric projection yog dab tsi?

Ntawm txhua qhov chaw hauv qhov chaw, qhov sib nqus tau piav qhia los ntawm peb qhov duab vector. Txawm li cas los xij, peb lub vijtsam zaub yog ob qho tib si. Peb tuaj yeem kwv yees peb daim duab vector rau hauv ob lub dav hlau dav dav kom peb tuaj yeem kos nws ntawm qhov screen. Muaj ntau txoj hauv kev kom ua tiav qhov no xws li isometric projection, orthographic projection, lossis oblique projection.

Hauv isometric projection, x, y, thiab z axes yog 120 degrees sib nrug, thiab lawv zoo ib yam li luv luv. Cov ntaub ntawv ntxiv txog kev kwv yees isometric, nrog rau cov qauv xav tau, tuaj yeem nrhiav tau ntawm Wikipedia nplooj ntawv ntawm cov ncauj lus.

Kauj Ruam 1: Sau cov khoom siv

Arduino thiab Cable

Arduino yog lub hlwb ntawm lub tshuab ntsuas hluav taws xob. Cov lus qhia no piav qhia yuav siv Arduino Uno lossis Arduino MKR1010 li cas. Hauv ob qho xwm txheej, xav tau txoj hlua txuas txuas nws mus rau lub khoos phis tawj.

Kev Xaiv 1: Arduino Uno thiab USB AB Cable

www.digikey.com/product-detail/en/arduino/A000066/1050-1024-ND/2784006

www.digikey.com/product-detail/en/stewart-connector/SC-2ABE003F/380-1424-ND/8544570

Qhov Xaiv 2: Arduino MKR1010 thiab microUSB cable

www.digikey.com/product-detail/en/arduino/ABX00023/1050-1162-ND/9486713

www.digikey.com/product-detail/en/stewart-connector/SC-2AMK003F/380-1431-ND/8544577

TFT Zaub

TFT sawv rau Thin Film Transistor. Qhov 1.44 zaub no muaj 128 x 128 pixels. Nws yog qhov me me, ci, thiab muaj xim zoo nkauj. Nws los txuas rau ntawm lub rooj sib cais. xav tau.)

www.digikey.com/product-detail/en/adafruit-industries-llc/2088/1528-1345-ND/5356830

    Duab
    Duab
  • Analog Hall Effect Sensors

Peb yuav tsum tau ua kom pom kev zoo nrog Hall. Qhov txuas hauv qab no yog rau Allegro tus lej A1324LUA-T. Rau qhov ntsuas no, tus pin 1 yog qhov muab hluav taws xob, tus pin 2 yog hauv av, thiab tus pin 3 yog qhov tso tawm. Lwm Lub Tsev Sensor yuav tsum ua haujlwm ib yam nkaus, tab sis nco ntsoov tias lawv zoo ib yam, tsis yog digital. Yog tias koj siv lub ntsuas cua sib txawv, txheeb xyuas qhov pinout thiab kho qhov thaiv yog tias xav tau. (Kuv tau siv lub ntsuas sib txawv los ntawm tib lub tuam txhab rau kev ntsuas lub hom phiaj.

www.digikey.com/product-detail/en/allegro-microsystems-llc/A1324LUA-T/620-1432-ND/2728144

Me Creadboard thiab Hlau

www.digikey.com/product-detail/en/adafruit-industries-llc/239/1528-2143-ND/7244929

Cov Hlau nplaum ruaj khov rau Kev Xeem

Cov hlau nplaum tub yees yuav ua haujlwm zoo.

Kauj ruam 2: Kev thaiv kab

Thaiv
Thaiv

Muab cov taub hau tso rau ntawm cov zaub.

Duab
Duab

Muab cov ntsuas hluav taws xob tso rau ntawm ib kawg ntawm daim ntawv qhia zaub mov, thiab tso cov zaub thiab Arduino ntawm qhov kawg rov qab. Tam sim no nyob rau hauv cov xov hlau hauv Arduino thiab tso saib tsim cov chaw sib nqus, uas peb tsis xav kom cov ntsuas nyeem ntawv. Ib qho ntxiv, peb yuav xav tso lub ntsuas hluav taws xob nyob ze cov hlau nplaum tas mus li, uas tuaj yeem cuam tshuam tsis zoo rau tam sim no hauv cov xov hlau ntawm cov zaub thiab lub sensor. Vim li no, peb xav tau lub ntsuas cua nyob deb ntawm cov zaub thiab Arduino. Tsis tas li rau cov laj thawj no, lub tshuab ntsuas hluav taws xob no yuav tsum tau nyob deb ntawm cov chaw sib nqus muaj zog heev.

Muab cov ntsuas ntsuas sib dhos rau ib leeg tab sis ze rau ib leeg ib yam li ua tau. Maj mam khoov cov sensors kom tau lawv nyob ib puag ncig. Txhua tus pin ntawm txhua lub ntsuas yuav tsum nyob hauv kab sib cais ntawm lub khob cij kom nws tuaj yeem sib cais sib txuas.

Duab
Duab

Cov xov hlau sib txawv me ntsis ntawm MKR1010 thiab Uno rau ob qho laj thawj. Ua ntej, Arduino thiab nthuav qhia kev sib tham los ntawm SPI. Cov qauv sib txawv ntawm Arduino muaj ntau tus pin tshwj xeeb rau qee cov kab SPI. Qhov thib ob, cov tswv yim sib piv ntawm Uno tuaj yeem lees txais txog 5 V thaum sib piv cov tswv yim ntawm MKR1010 tuaj yeem lees txais tsuas yog txog 3.3 V. Cov lus pom zoo muab hluav taws xob rau Hall effect sensors yog 5 V. Lub sensor tso tawm tau txuas nrog Arduino analog inputs, thiab cov no tuaj yeem loj npaum li cov khoom siv hluav taws xob. Rau Uno, siv qhov pom zoo 5 V muab rau cov ntsuas. Rau MKR1010, siv 3.3 V kom cov lus sib piv ntawm Arduino yeej tsis pom qhov hluav taws xob loj dua nws tuaj yeem ua tau.

Ua raws cov kab kos thiab cov lus qhia hauv qab no rau Arduino koj tab tom siv.

Txuas nrog Arduino Uno

Duab
Duab

Cov zaub muaj 11 tus pin. Txuas lawv mus rau Arduino Uno raws li hauv qab no. (NC txhais tau tias tsis txuas nrog.)

  • Vin → 5 V
  • 3.3 → NCO
  • GND thiab GND
  • NCO → 13
  • SO → NC
  • SIb → 11
  • TSI → 10
  • RST -9 TSI
  • D/C → 8
  • CCS → NCO
  • Lite → NCO

Txuas Vin ntawm cov ntsuas mus rau 5V ntawm Arduino. Txuas hauv av ntawm lub sensor mus rau hauv av ntawm Arduino. Txuas cov txiaj ntsig ntawm lub ntsuas hluav taws xob mus rau cov tswv yim analog A1, A2, thiab A3 ntawm Arduino.

Duab
Duab

Txuas nrog Arduino MKR1010

Duab
Duab

Cov zaub muaj 11 tus pin. Txuas lawv mus rau Arduino raws li hauv qab no. (NC txhais tau tias tsis txuas nrog.)

  • Vin → 5 V
  • 3.3 → NCO
  • GND thiab GND
  • SCK → SCK 9
  • SO → NC
  • SI -MOSI 8
  • TSI → 5
  • TSI → 4
  • D/C → 3
  • CCS → NCO
  • Lite → NCO

Txuas Vin ntawm cov ntsuas mus rau Vcc ntawm Arduino. Tus pin no yog 3.3V, tsis yog 5V. Txuas hauv av ntawm lub sensor mus rau hauv av ntawm Arduino. Txuas cov txiaj ntsig ntawm lub ntsuas hluav taws xob mus rau cov tswv yim analog A1, A2, thiab A3 ntawm Arduino.

Duab
Duab

Kauj Ruam 3: Txheeb Tawm Cov Zaub

Cia peb tau txais TFT zaub ua haujlwm. Hmoov zoo, Adafruit muaj qee tus neeg siv nyiam siv lub tsev qiv ntawv thiab kev qhia zoo tshaj plaws mus nrog lawv. Cov lus qhia no ua raws cov lus qhia no, Qhib Arduino kev txhim kho ib puag ncig. Mus rau Cov Cuab Yeej → Tswj Cov Tsev Qiv Ntawv. Nruab Adafruit_GFX, Adafruit_ZeroDMA, thiab Adafruit_ST7735 tsev qiv ntawv. Rov pib dua Android ib puag ncig kev txhim kho.

Cov duab piv txwv zoo tshaj plaws suav nrog cov tsev qiv ntawv. Qhib nws. Cov ntaub ntawv → Piv txwv → Adafruit ST7735 thiab ST7789 Library → graphicstest. Txhawm rau xaiv 1.44 tso saib cov lus tawm kab 95 thiab kab tsis pom zoo 98.

Thawj version:

94 // Siv qhov pib no yog siv 1.8 TFT screen:

95 tft.initR (INITR_BLACKTAB); // Init ST7735S nti, tab dub 96 97 // LOSSIS siv qhov pib ua haujlwm (tsis pom zoo) yog siv 1.44 TFT: 98 //tft.initR(INITR_144GREENTAB); // Init ST7735R nti, tab ntsuab

Kho qhov tseeb rau 1.44 zaub:

94 // Siv qhov pib no yog siv 1.8 TFT screen:

95 //tft.initR(INIT_BLACKTAB); // Init ST7735S nti, tab dub 96 97 // LOS YOG siv qhov pib ua haujlwm no (tsis pom zoo) yog siv 1.44 TFT: 98 tft.initR (INITR_144GREENTAB); // Init SST35R nti, tab ntsuab

Cov lus sib txuas lus siv SPI, thiab tus qauv sib txawv Arduinos siv tus pin tshwj xeeb sib txawv rau qee txoj kab kev sib txuas lus. Cov duab piv txwv zoo tshaj plaws tau teeb tsa los ua haujlwm nrog Uno pins. Yog tias koj siv MKR1010, ntxiv cov kab hauv qab no ntawm kab 80 thiab 81.

Kev kho rau MKR1010:

80

#define TFT_CS 5 #define TFT_RST 4 #define TFT_DC 3 #define TFT_MOSI 8 #define TFT_SCLK 9 Adafruit_ST7735 tft = Adafruit_ST7735 (TFT_CS, TFT_DC, TFT_MOSI, TFT_SCLK, TFT_RST); 81 ntab p = 3.1415926;

Txuag qhov piv txwv hloov kho tshiab tshaj plaws. Txuas lub Arduino rau hauv computer yog tias koj tseem tsis tau ua li ntawd. Mus rau Cov Cuab Yeej → Pawg Thawj Coj thiab Cov Cuab Yeej → Chaw nres nkoj los txheeb xyuas tias lub khoos phis tawj tuaj yeem pom Arduino. Mus rau Sketch → Upload. Yog tias qhov piv txwv ua haujlwm, cov zaub yuav pom kab, duab plaub, ntawv nyeem, thiab ua tiav daim duab. Kev qhia Adafruit qhia ntau ntxiv yog tias xav tau kev daws teeb meem.

Kauj Ruam 4: Txoj Cai Magnetometer

Rub tawm cov kab ntawv txuas, thiab qhib nws hauv Arduino ib puag ncig kev txhim kho.

Txoj haujlwm no siv rau lub luag haujlwm:

Teeb () initializes cov zaub

Loop () muaj lub ntsiab lus tseem ceeb ntawm txoj haujlwm. Nws blacks tawm lub vijtsam, kos cov axes, nyeem cov tswv yim, thiab kos cov xub sawv cev rau qhov chaw sib nqus sib nqus. Nws muaj qhov hloov tshiab ntawm ib vib nas this uas tuaj yeem hloov pauv los ntawm kev hloov kab 127

DrawAxes3d () kos thiab sau cov x, y, thiab z axes

DrawArrow3d () siv rau hauv x, y, thiab z cov tswv yim xws li 0 txog 1023. Los ntawm cov txiaj ntsig no, nws suav qhov kawg ntawm cov xub hauv qhov chaw. Tom ntej no, nws siv isometricxx () thiab isometricyy () ua haujlwm los laij cov ntsiab lus kawg ntawm qhov screen. Thaum kawg, nws kos tus xub thiab luam tawm qhov hluav taws xob nyob hauv qab ntawm qhov screen

Isometricxx () pom qhov x ua haujlwm ntawm isometric projection. Nws siv sijhawm x, y, thiab z tswj hwm ntawm ib qho taw tes thiab xa rov qab sib xws x pixel qhov chaw ntawm lub vijtsam

Isometricyy () pom cov y ua haujlwm ntawm isometric projection. Nws siv sijhawm x, y, thiab z tswj hwm ntawm ib qho taw tes thiab xa rov qab qhov sib thooj y pixel qhov chaw ntawm lub vijtsam

Ua ntej siv txoj cai, peb yuav tsum qhia kom paub tus pin twg los siv rau SPI kev sib txuas lus nrog cov zaub, thiab peb yuav tsum tau hais qhia qhov ntsuas qhov hluav taws xob rau lub ntsuas cua. Yog tias koj tab tom siv MKR1010, tawm lus kab 92-96 ntxiv rau kab 110. Tom qab ntawd, kab lus tsis txaus siab 85-89 ntxiv rau kab 108. Yog tias koj siv Uno, tawm kab tawm 85-89 ntxiv rau kab 108 Tom qab ntawd, kab tsis pom zoo 92-96 ntxiv rau kab 110.

Upload cov cai, Sketch → Upload.

Koj yuav tsum pom x, y, thiab z axes liab. Lub xub xub ntsuab nrog lub voj voos xiav rau qhov taw qhia nruab nrab yog cov duab sib nqus sib nqus ntawm cov ntsuas. Kev nyeem hluav taws xob tau tshwm ntawm sab laug sab laug. Raws li koj nqa cov hlau nplaum ze rau cov ntsuas, qhov ntsuas hluav taws xob yuav tsum hloov pauv, thiab qhov xub ntawm qhov xub yuav tsum loj tuaj.

Duab
Duab

Kauj Ruam 5: Ua Haujlwm Yav Tom Ntej

Kev Ua Haujlwm Yav Tom Ntej
Kev Ua Haujlwm Yav Tom Ntej

Cov kauj ruam tom ntej yuav yog ntsuas cov cuab yeej. Qhov sensor cov ntaub ntawv muab cov ntaub ntawv qhia yuav ua li cas hloov pauv cov khoom siv hluav taws xob ntsuas qhov ntsuas mus rau lub zog sib nqus. Kev ntsuas ntsuas tuaj yeem txheeb xyuas tau los ntawm kev sib piv rau qhov ntsuas qhov tseeb ntau dua.

Cov hlau nplaum ruaj khov cuam tshuam nrog cov xov hluav taws xob tam sim no. Cov xov hlau nyob ze cov zaub thiab hauv Arduino tsim cov chaw sib nqus uas tuaj yeem cuam tshuam rau kev nyeem ntawv. Ib qho ntxiv, yog tias lub cuab yeej no tau siv los ntsuas ze ntawm cov hlau nplaum ruaj khov, lub tshuab nqus hlau los ntawm lub cuab yeej hauv kev sim yuav cuam tshuam nrog, qhia suab nrov rau hauv, thiab tej zaum ua rau Arduino puas tsuaj thiab tso tawm. Kev tiv thaiv tuaj yeem ua rau lub tshuab ntsuas hluav taws xob muaj zog dua. Arduino tuaj yeem tiv taus thaj chaw sib nqus loj dua yog tias nws tau thaiv hauv lub thawv hlau, thiab yuav tsis muaj suab nrov dua yog tias cov kab hluav taws xob tiv thaiv txuas lub ntsuas hluav taws xob tsis txhob siv lub xov tooj liab liab.

Sib nqus teb yog txoj haujlwm ntawm txoj haujlwm, yog li nws txawv ntawm txhua qhov chaw hauv qhov chaw. Cov cuab yeej no siv peb lub ntsuas ntsuas, ib qho los ntsuas x, y, thiab z tivthaiv ntawm qhov chaw sib nqus ntawm qhov chaw. Cov ntsuas nyob ze rau ib leeg tab sis tsis nyob ntawm ib qho taw tes, thiab qhov no txwv qhov ntsuas qhov ntsuas hluav taws xob. Nws yuav txias kom txuag tau cov hlau nplaum nyeem ntawm cov ntsiab lus sib txawv tom qab ntawd tso saib lawv raws li cov kab ntawm cov xub ntawm qhov chaw sib xws. Txawm li cas los xij, qhov ntawd yog txoj haujlwm rau lwm hnub.

Cov neeg ua tim khawv

Cov ntaub ntawv ntawm Adafruit Arduino Graphics cov tsev qiv ntawv

https://learn.adafruit.com/adafruit-1-44-color-tft-with-micro-sd-socket/overview

Sib nqus pom kev pom

https://www.falstad.com/vector3dm/

Cov ntaub ntawv ntawm Hall effect thiab Hall effect sensors

  • https://sensing.honeywell.com/index.php?ci_id=47847
  • https://www.allegromicro.com/~/media/Files/Datasheets/A1324-5-6-Datasheet.ashx

Cov ntaub ntawv ntawm isometric projection

  • https://en.wikipedia.org/wiki/3D_projection
  • https://en.wikipedia.org/wiki/Isometric_projection

Pom zoo: