„Tutorial - Tiva C (EK-TM4C123GXL)” változatai közötti eltérés
(Új oldal, tartalma: „ === Tutorial === <big>'''Vissza az összesítő oldalra!'''</big> === Analóg jelek 1: TMP35 analóg hőmérő === Mi az '''analóg''' jel?<br /> Hogyan t…”) |
|||
35. sor: | 35. sor: | ||
==== Program ==== | ==== Program ==== | ||
<html> | <html> | ||
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> | |||
<head> | |||
<title>/home/bkba/Dropbox/BALINT_share/energia_sketchbook/Tiva_C/Tutorial/TMP35_TivaC_TM4C123_129/TMP35_TivaC_TM4C123_129.ino</title> | |||
<meta http-equiv="content-type" content="text/html;charset=utf-8" /> | |||
<meta name="generator" content="Geany 1.24.1" /> | |||
<meta name="date" content="2015-08-08T13:05:30+0200" /> | |||
<style type="text/css"> | |||
body | |||
{ | |||
font-family: Monospace, monospace; | |||
font-size: 10pt; | |||
} | |||
.style_1 | |||
{ | |||
color: #d00000; | |||
background-color: #ffffff; | |||
} | |||
.style_2 | |||
{ | |||
color: #d00000; | |||
background-color: #ffffff; | |||
} | |||
.style_4 | |||
{ | |||
color: #007f00; | |||
background-color: #ffffff; | |||
} | |||
.style_5 | |||
{ | |||
color: #00007f; | |||
background-color: #ffffff; | |||
font-weight: bold; | |||
} | |||
.style_6 | |||
{ | |||
color: #ff8000; | |||
background-color: #ffffff; | |||
} | |||
.style_10 | |||
{ | |||
color: #301010; | |||
background-color: #ffffff; | |||
} | |||
.style_11 | |||
{ | |||
color: #000000; | |||
background-color: #ffffff; | |||
} | |||
</style> | |||
</head> | |||
<body> | |||
<p> | |||
<span class="style_1">/* </span><br /> | |||
<span class="style_1">TMP35 read data and print to serial monitor in Celsius.</span><br /> | |||
<span class="style_1">Balint Kiss; 2015.07.09</span><br /> | |||
<span class="style_1">eskolar.com</span><br /> | |||
<span class="style_1">--------------</span><br /> | |||
<br /> | |||
<span class="style_1">A TMP35 Vout laban 10 mV 1 ℃-nak felel meg.</span><br /> | |||
<span class="style_1">Ahanyszor 10 mV-unk van, anyi ℃ a homerseklet.</span><br /> | |||
<span class="style_1">Ezt az erteket olvassuk le, utanna a Serial Montor-on</span><br /> | |||
<span class="style_1">(soros porton) keresztul kirjuk.</span><br /> | |||
<br /> | |||
<span class="style_1">TMP35 (front view)</span><br /> | |||
<span class="style_1">|||</span><br /> | |||
<span class="style_1">Vin/ | \GND</span><br /> | |||
<span class="style_1">Vout</span><br /> | |||
<span class="style_1">*/</span><br /> | |||
<br /> | |||
<span class="style_2">//sorozat az E Port inicializalasahoz</span><br /> | |||
<span class="style_5">int </span><span class="style_11">E_PORT</span><span class="style_10">[] = { </span><br /> | |||
<span class="style_11">PE_0</span><span class="style_10">, </span><span class="style_11">PE_1</span><span class="style_10">, </span><span class="style_11">PE_2</span><span class="style_10">, </span><span class="style_11">PE_3</span><span class="style_10">, </span><span class="style_11">PE_4 </span><span class="style_10">};</span><br /> | |||
<br /> | |||
<span class="style_5">float </span><span class="style_11">TMP35</span><span class="style_10">; </span><span class="style_2">// A szenzor kimente -> lebegopontos leolvasott ertek</span><br /> | |||
<span class="style_5">float </span><span class="style_11">temp </span><span class="style_10">= </span><span class="style_4">0</span><span class="style_10">;</span><span class="style_2">// A ℃ fokba atalakitott ertek</span><br /> | |||
<span class="style_5">int </span><span class="style_11">sensor </span><span class="style_10">= </span><span class="style_11">PE_5</span><span class="style_10">; </span><span class="style_2">//leolvasott lab</span><br /> | |||
<br /> | |||
<span class="style_2">//inditaskor fut le</span><br /> | |||
<span class="style_5">void </span><span class="style_11">setup</span><span class="style_10">() {</span><br /> | |||
<span class="style_11">Serial</span><span class="style_10">.</span><span class="style_11">begin</span><span class="style_10">(</span><span class="style_4">9600</span><span class="style_10">); </span><span class="style_2">// Soros kapcsolat inditasa, baud rate beallitas</span><br /> | |||
<span class="style_11">pinMode </span><span class="style_10">(</span><span class="style_11">sensor</span><span class="style_10">, </span><span class="style_11">INPUT</span><span class="style_10">); </span><span class="style_2">// a leolvasott lab egy bemenet</span><br /> | |||
<br /> | |||
<br /> | |||
<span class="style_2">//Az E portot le kell zarni!</span><br /> | |||
<span class="style_2">//Mert PE_3 ra bejövő jel (zaj) zavarhatja az E portot!</span><br /> | |||
<span class="style_5">for </span><span class="style_10">(</span><span class="style_5">int </span><span class="style_11">thisPin </span><span class="style_10">= </span><span class="style_4">0</span><span class="style_10">; </span><span class="style_11">thisPin </span><span class="style_10">< </span><span class="style_4">5</span><span class="style_10">; </span><span class="style_11">thisPin</span><span class="style_10">++) {</span><br /> | |||
<span class="style_11">pinMode</span><span class="style_10">(</span><span class="style_11">E_PORT</span><span class="style_10">[</span><span class="style_11">thisPin</span><span class="style_10">], </span><span class="style_11">OUTPUT</span><span class="style_10">); </span><br /> | |||
<span class="style_11">digitalWrite</span><span class="style_10">(</span><span class="style_11">E_PORT</span><span class="style_10">[</span><span class="style_11">thisPin</span><span class="style_10">], </span><span class="style_11">LOW</span><span class="style_10">); </span><br /> | |||
<span class="style_10">}</span><br /> | |||
<span class="style_10">}</span><br /> | |||
<br /> | |||
<span class="style_2">//folyamatosan ismetlodik</span><br /> | |||
<span class="style_5">void </span><span class="style_11">loop</span><span class="style_10">() {</span><br /> | |||
<span class="style_2">//analog leolvasas (TM4C123 PE_5 = A8) (TM4C129 PE_5 = A9) </span><br /> | |||
<span class="style_11">TMP35 </span><span class="style_10">= </span><span class="style_11">analogRead</span><span class="style_10">(</span><span class="style_11">PE_5</span><span class="style_10">); </span><br /> | |||
<span class="style_11">temp </span><span class="style_10">= ((</span><span class="style_11">TMP35</span><span class="style_10">*</span><span class="style_4">3300</span><span class="style_10">)/</span><span class="style_4">4095</span><span class="style_10">)/</span><span class="style_4">10</span><span class="style_10">;</span><span class="style_2">// konvertalas mV-ba utanna ℃-ba</span><br /> | |||
<br /> | |||
<span class="style_11">Serial</span><span class="style_10">.</span><span class="style_11">print</span><span class="style_10">(</span><span class="style_6">"Analog Read ---> "</span><span class="style_10">);</span><br /> | |||
<span class="style_11">Serial</span><span class="style_10">.</span><span class="style_11">print</span><span class="style_10">(</span><span class="style_11">TMP35</span><span class="style_10">); </span><span class="style_2">//adatok kiirasa</span><br /> | |||
<span class="style_11">Serial</span><span class="style_10">.</span><span class="style_11">print</span><span class="style_10">(</span><span class="style_6">" = "</span><span class="style_10">);</span><br /> | |||
<span class="style_11">Serial</span><span class="style_10">.</span><span class="style_11">print</span><span class="style_10">(</span><span class="style_11">temp</span><span class="style_10">); </span><span class="style_2">//adatok kiirasa</span><br /> | |||
<span class="style_11">Serial</span><span class="style_10">.</span><span class="style_11">println</span><span class="style_10">(</span><span class="style_6">" C"</span><span class="style_10">);</span><br /> | |||
<span class="style_11">delay</span><span class="style_10">(</span><span class="style_4">100</span><span class="style_10">); </span><span class="style_2">// 0.1 mp szunet</span><br /> | |||
<br /> | |||
<span class="style_10">}</span><br /> | |||
<br /> | |||
<br /> | |||
<br /> | |||
<br /> | |||
<br /> | |||
</p> | |||
</body> | |||
</html> | |||
</html> | </html> | ||
=== Digitális jelek 1 === | === Digitális jelek 1 === | ||
==== Video ==== | ==== Video ==== |
A lap 2015. augusztus 8., 11:12-kori változata
Tutorial
Analóg jelek 1: TMP35 analóg hőmérő
Mi az analóg jel?
Hogyan tudjuk érzékelni az analóg feszültségváltozást?
A példában egy TMP35 lineáris hő szenzort használtam, hogy megértsük az analóg jeleket, ennek az értékét olvassuk le.
A TMP35 egy lineáris hő szenzor, ahány °C-t mér annyiszor 10 mV-ot kapcsol a 2. lába.
TMP35 datasheet
Video
Kapcsolás
TMP35 + LauchPad |
---|
TMP35 | IC | Output Voltage vs. Temperature |
---|---|---|
Program
/*
TMP35 read data and print to serial monitor in Celsius.
Balint Kiss; 2015.07.09
eskolar.com
--------------
A TMP35 Vout laban 10 mV 1 ℃-nak felel meg.
Ahanyszor 10 mV-unk van, anyi ℃ a homerseklet.
Ezt az erteket olvassuk le, utanna a Serial Montor-on
(soros porton) keresztul kirjuk.
TMP35 (front view)
|||
Vin/ | \GND
Vout
*/
//sorozat az E Port inicializalasahoz
int E_PORT[] = {
PE_0, PE_1, PE_2, PE_3, PE_4 };
float TMP35; // A szenzor kimente -> lebegopontos leolvasott ertek
float temp = 0;// A ℃ fokba atalakitott ertek
int sensor = PE_5; //leolvasott lab
//inditaskor fut le
void setup() {
Serial.begin(9600); // Soros kapcsolat inditasa, baud rate beallitas
pinMode (sensor, INPUT); // a leolvasott lab egy bemenet
//Az E portot le kell zarni!
//Mert PE_3 ra bejövő jel (zaj) zavarhatja az E portot!
for (int thisPin = 0; thisPin < 5; thisPin++) {
pinMode(E_PORT[thisPin], OUTPUT);
digitalWrite(E_PORT[thisPin], LOW);
}
}
//folyamatosan ismetlodik
void loop() {
//analog leolvasas (TM4C123 PE_5 = A8) (TM4C129 PE_5 = A9)
TMP35 = analogRead(PE_5);
temp = ((TMP35*3300)/4095)/10;// konvertalas mV-ba utanna ℃-ba
Serial.print("Analog Read ---> ");
Serial.print(TMP35); //adatok kiirasa
Serial.print(" = ");
Serial.print(temp); //adatok kiirasa
Serial.println(" C");
delay(100); // 0.1 mp szunet
}
</html>