<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Pythogun on Medium]]></title>
        <description><![CDATA[Stories by Pythogun on Medium]]></description>
        <link>https://medium.com/@Pythogun?source=rss-8afaf524a207------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*fwZ35X1fAlv_K7u2.</url>
            <title>Stories by Pythogun on Medium</title>
            <link>https://medium.com/@Pythogun?source=rss-8afaf524a207------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Thu, 19 Nov 2026 07:24:06 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@Pythogun/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[ตอนที่ 4 : การประยุกต์ใช้ ESP8266 ทางด้าน IoT ( Internet of Things )]]></title>
            <link>https://medium.com/@Pythogun/%E0%B8%95%E0%B8%AD%E0%B8%99%E0%B8%97%E0%B8%B5%E0%B9%88-4-%E0%B8%81%E0%B8%B2%E0%B8%A3%E0%B8%9B%E0%B8%A3%E0%B8%B0%E0%B8%A2%E0%B8%B8%E0%B8%81%E0%B8%95%E0%B9%8C%E0%B9%83%E0%B8%8A%E0%B9%89-esp8266-%E0%B8%97%E0%B8%B2%E0%B8%87%E0%B8%94%E0%B9%89%E0%B8%B2%E0%B8%99-iot-internet-of-things-5a1bf16e80b3?source=rss-8afaf524a207------2</link>
            <guid isPermaLink="false">https://medium.com/p/5a1bf16e80b3</guid>
            <dc:creator><![CDATA[Pythogun]]></dc:creator>
            <pubDate>Wed, 26 Apr 2017 10:12:18 GMT</pubDate>
            <atom:updated>2017-04-26T10:12:18.904Z</atom:updated>
            <content:encoded><![CDATA[<p>จากการเรียนรู้ในตอนที่ 3 สำหรับคำสั่งต่างๆเรียบร้อยแล้ว</p><p>ในตอนนี้เราจะลองนำตัวอย่างบางคำสั่งของตอนที่ 3 มาใช้งานจริงในด้าน IoT</p><p>Concept : เราต้องการเปิดปิดหลอด led ที่ต่อกับ ESP8266 ผ่านทาง internet โดย เราจะใช้ MQTT ในการส่งค่า</p><h4>ขั้นตอนแรก : ทดลองใช้ MQTT Broker (ฝั่งของผู้ส่ง)</h4><p>เว็บที่ใช้ในการทดลอง <a href="http://www.hivemq.com/demos/websocket-client/">http://www.hivemq.com/demos/websocket-client/</a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ORgORmp99QEnUovApCHFzg.png" /></figure><p>Host : ชื่อของ Server ที่เราจะใช้ในการส่งข้อมูล</p><p>Port : default ของ MQTT ตั้งไว้ที่ 8000</p><p>ClientID : ชื่อของผู้ใช้งานเอง (ตั้งเป็นอะไรก็ได้)</p><p>และทำการกด connect เพื่อเชื่อมต่อ</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*313kalhNaqEIz9_hqmfvcQ.png" /><figcaption>หลังจากกด connect แล้ว</figcaption></figure><p>Topic : ตั้งชื่ออะไรก็ได้เปรียบเสมือนชื่ีอ Channel ที่เราอยากใช้</p><p>QoS : set ให้เป็น 0</p><p>Retain : กดเลือกเพื่อให้ เป็นการเก็บค่าสุดท้ายที่ส่งไว้บน server</p><p>Message : ข้อความที่ต้องการส่งขึ้น Server</p><h4>ขั้นตอนที่ 2 : รับค่าเพื่อสั่งเปิดปิด led ผ่าน ESP8266 (ฝั่งของผู้รับ)</h4><p>ทางเราเลือกใช้ ผ่านทางโปรแกรม Putty</p><p>เราจะใช้ Code ในการรอรับคำสั่งเปิดปิดไฟจาก Server</p><p><strong>from umqtt.simple import MQTTClient</strong></p><p><strong>from machine import Pin</strong></p><p><strong>import ubinascii</strong></p><p><strong>import machine</strong></p><p><strong>import micropython</strong></p><p><strong># ESP8266 ESP-12 modules have blue, active-low LED on GPIO2, replace</strong></p><p><strong># with something else if needed.</strong></p><p><strong>led = Pin(5, Pin.OUT, value=1) </strong><em>#Pin(เป็นขาที่ต่อกับ led บน ESP,พินขาออก, set value = 1 )</em></p><p><strong># Default MQTT server to connect to</strong></p><p><strong>SERVER = “broker.mqttdashboard.com”</strong> <em>#server = ชื่อของ Server ที่เราจะใช้ในการส่งข้อมูล (Host) ที่เราตั้งบน MQTT Broker</em></p><p><strong>CLIENT_ID = ubinascii.hexlify(machine.unique_id())</strong></p><p><strong>TOPIC = b”testtopic/eiei” </strong><em>#ใช้ Topic ที่เราตั้งไว้บน MQTT Broker</em></p><p><strong>state = 0</strong></p><p><strong>def sub_cb(topic, msg):</strong></p><p><strong>global state</strong></p><p><strong>print((topic, msg))</strong></p><p><strong>if msg == b”on”:</strong></p><p><strong>led.value(1)</strong></p><p><strong>state = 1</strong></p><p><strong>elif msg == b”off”:</strong></p><p><strong>led.value(0)</strong></p><p><strong>state = 0</strong></p><p><strong>elif msg == b”toggle”:</strong></p><p><strong># LED is inversed, so setting it to current state</strong></p><p><strong># value will make it toggle</strong></p><p><strong>led.value(state)</strong></p><p><strong>state = 1 — state</strong></p><p><strong>def main(server=SERVER):</strong></p><p><strong>c = MQTTClient(CLIENT_ID, server)</strong></p><p><strong># Subscribed messages will be delivered to this callback</strong></p><p><strong>c.set_callback(sub_cb)</strong></p><p><strong>c.connect()</strong></p><p><strong>c.subscribe(TOPIC)</strong></p><p><strong>print(“Connected to %s, subscribed to %s topic” % (server, TOPIC))</strong></p><p><strong>try:</strong></p><p><strong>while 1:</strong></p><p><strong>#micropython.mem_info()</strong></p><p><strong>c.wait_msg()</strong></p><p><strong>finally:</strong></p><p><strong>c.disconnect()</strong></p><h4>ขั้นตอนที่ 3 : เป็นการส่งค่าจาก จาก MQTT ในการเพื่อเปิดปิดไฟ</h4><p>หลอด led ปิดอยู่หลังจากต่อวงจรเสร็จ</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/640/1*k9fOVTTo1xLQI2YjUf6flQ.jpeg" /><figcaption>ภาพการต่อ แบบทดลอง</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ofUMNxtU0ybs6Q2PITAxYA.png" /></figure><p>โดยเราจะพิม on เป็นการส่งค่าตามที่เขียนไว้ใน Code เพื่อสั่งเปิดไฟ</p><p>หลังจากกด Publish เพื่อส่งค่า</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*0kT7YTgxQUISLhtPMQG38g.jpeg" /></figure><p>หลอดไฟ led จะติด</p><p>จบการนำเสนอวิธีการนำ ESP8266 ประยุกต์ใช้กับ IoT</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=5a1bf16e80b3" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[ตอนที่ 3 : วิธีการใช้งานเบื้องต้น]]></title>
            <link>https://medium.com/@Pythogun/%E0%B8%95%E0%B8%AD%E0%B8%99%E0%B8%97%E0%B8%B5%E0%B9%88-3-%E0%B8%A7%E0%B8%B4%E0%B8%98%E0%B8%B5%E0%B8%81%E0%B8%B2%E0%B8%A3%E0%B9%83%E0%B8%8A%E0%B9%89%E0%B8%87%E0%B8%B2%E0%B8%99%E0%B9%80%E0%B8%9A%E0%B8%B7%E0%B9%89%E0%B8%AD%E0%B8%87%E0%B8%95%E0%B9%89%E0%B8%99-7cb68979ec57?source=rss-8afaf524a207------2</link>
            <guid isPermaLink="false">https://medium.com/p/7cb68979ec57</guid>
            <dc:creator><![CDATA[Pythogun]]></dc:creator>
            <pubDate>Fri, 21 Apr 2017 08:16:01 GMT</pubDate>
            <atom:updated>2017-05-11T13:07:19.935Z</atom:updated>
            <content:encoded><![CDATA[<p>จากตอนที่ 2 ที่เราได้ทำการติดตั้ง firmware ให้กับ esp8266 ไปเรียบร้อยเเล้ว ในตอนนี้เราจะมาเริ่มวิธีการใช้งาน micropython เบื้องต้น เเละ คำสั่งที่คุณควรรู้เกี่ยวกับการใช้งาน</p><ul><li>คำสั่งควบคุมบอร์ดพื้นฐาน</li></ul><p>จะมีการเรียกใช้งาน machine module ซึ่งเป็น libraries พื้นฐานเพื่อใช้ในการควบคุมสิ่งต่างๆบนบอร์ด</p><pre><strong>import</strong> machine</pre><pre>machine.freq() <br>machine.freq(160000000) </pre><p>การใช้งาน esp module</p><pre><strong>import</strong> esp</pre><pre>esp.osdebug(None) <br>esp.osdebug(0)</pre><ul><li>คำสั่งใช้งานในส่วนของเครือข่าย</li></ul><p>การใช้งาน network module</p><p>เริ่มเเรกด้วยการใช้งานคำสั่ง</p><pre><strong>import</strong> network</pre><p>โดยการใช้งานในรูปเเบบเครือข่ายนั้นจะสามารถทำได้ 2 รูปเเบบ ดังนี้</p><ol><li>การใช้งานเเบบ Station หรือก็คือการที่เรานำบอร์ดไปเชื่อต่อกับ access-point wifi มีอยู่ในบริเวณรอบๆ เพื่อใช้ในการทำงาน</li></ol><pre>wlan = network.WLAN(network.STA_IF) <br>wlan.active(True) <br>wlan.scan() <br>wlan.isconnected()<br>wlan.connect(‘essid’, ‘password’) <br>wlan.config(‘mac’) <br>wlan.ifconfig()</pre><p>2.การใช้งานเเบบ access-point โดยจะเป็นการที่เราจะให้บอร์ดของเรานั้น เป็นตัวกระจายสัญญาณ wifi</p><pre>ap = network.WLAN(network.AP_IF) <br>ap.active(True) <br>ap.config(essid=’ESP-AP’)</pre><ul><li>คำสั่งใช้งานในส่วนของ Delay เเละ Timing</li></ul><p>โดยเราจะมีการเรียกใช้งาน time module เพื่อเปิดการใช้งาน ดังนี้</p><pre><strong>import</strong> time</pre><pre>time.sleep(1) <br>time.sleep_ms(500) <br>time.sleep_us(10) <br>start = time.ticks_ms()<br>delta = time.ticks_diff(time.ticks_ms(), start)</pre><ul><li>คำสั้งการใช้งาน Timer</li></ul><p>โดยส่วนการทำงานของ timer นั้นจะเป็น function เสริมจากส่วนของ machine module จึงจำเป็นต้องมีการ เรียกใช้งาน machine ก่อน เเละใช้งานคำสั่ง machine.Timer เพื่อเรียกใช้การทำงาน</p><pre><strong>import</strong> machine</pre><pre>tim = machine.Timer(-1)<br>tim.init(period=5000, mode=machine.Timer.ONE_SHOT, callback=lambda t:print(1))<br>tim.init(period=2000, mode=machine.Timer.PERIODIC, callback=lambda t:print(2))</pre><ul><li>คำสั่งใช้งานในส่วน Pins เเละ GPIO</li></ul><p>โดยการทำงานของ Pins กัย GPIO นั้นจะมีการทำงานพื้นฐานอยู่บน การใช้งาน machine module</p><p>ซึ่งก็จำเป็นต้องเรียกใช้งาน machine ก่อนทุกครั้งเสมอ จะเรียกใช้โดยคำสั่ง machine.Pin</p><pre><strong>import</strong> machine</pre><pre>p0 = machine.Pin(0, machine.Pin.OUT) <br>p0.high() <br>p0.low() <br>p0.value(1)</pre><pre>p1 = machine.Pin(1, machine.Pin.IN) <br>print(p1.value())</pre><pre>p2 = machine.Pin(2, machine.Pin.IN, machine.Pin.PULL_UP) <br>p3 = machine.Pin(3, machine.Pin.OUT, value=1)</pre><ul><li>คำสั่งใช้งานในส่วนของ PWM ( pulse width modulation )</li></ul><p>PWN นั้นสมารถใช้งานได้ทุกขา ของ PIN เเต่ยกเว้นเพียงเเค่ ขา 16 PIN(16) เท่านั้น โดย PWM สามารถตั้งค่าช่วงความถี่ให้อยู่ในระหว่าง 1 ถึง 1000 Hz เเละ จะมี duty cycle อยู่ในระหว่าง 0 ถึง 1023</p><p>ซึ่งการทำงานของ PWM นั้นก็จำเป็นต้องเรียกใช้งาน machine module ก่อนเช่นกันเพราะเป็นการควบคุมการทำงานบนบอร์ด คำสั่งที่ใช้จึงเป็น machine.PWM</p><pre><strong>import</strong> PWM</pre><pre>pwm0 = machine.PWM(Pin(0)) <br>pwm0.freq() <br>pwm0.freq(1000) <br>pwm0.duty() <br>pwm0.duty(200) <br>pwm0.deinit()</pre><pre>pwm2 = machine.PWM(Pin(2), freq=500, duty=512)</pre><ul><li>คำสั่งใช้งานในส่วน ADC ( analog to digital conversion )</li></ul><p>โดยในใช้งานในส่วนของ ADC นั้นจะต้องมีการกำหนด input ของศักย์ไฟฟ้าที่เข้ามาใน ADC นั้นให้อยู่ระหว่าง 0 ถึง 1.0V เเละเป็นการใช้งานบนบอร์ดที่เรียกใช้งานได้ดังนี้ machine.ADC</p><pre>import ADC</pre><pre>adc = machine.ADC(0)<br>adc.read()</pre><ul><li>คำสั่งการใช้งานในส่วนของ Software SPI bus</li></ul><p>โดยงานของส่วน SPI driver จะมีในส่วนของ software (bit-banging) เเละ มีในการทำงานของถุกๆขา (pin) บนบอร์ด ดังนั้การทำงานของ SPI ก็จะเป็นการทำงานบนบอร์ดที่ต้องเรียก machine module เช่นกัน ใช้งานได้ด้วยคำสั้่ง machine.SPI</p><pre><strong>import</strong> machine</pre><pre>spi = machine.SPI(-1, baudrate=100000, polarity=1, phase=0, sck=machine.Pin(0), mosi=machine.Pin(2), miso=machine.Pin(4))</pre><pre>spi.init(baudrate=200000)</pre><pre>spi.read(10) <br>spi.read(10, 0xff)</pre><pre>buf = bytearray(50) <br>spi.readinto(buf) <br>spi.readinto(buf, 0xff)</pre><pre>spi.write(b’12345&#39;)</pre><pre>buf = bytearray(4) <br>spi.write_readinto(b’1234&#39;, buf) <br>spi.write_readinto(buf, buf)</pre><ul><li>คำสั่งในส่วนการใช้งาน Hardware SPI bus</li></ul><pre><strong>import</strong> machine</pre><pre>hspi = machine.SPI(1, baudrate=80000000, polarity=0, phase=0)</pre><ul><li>คำสั่งการใช้งาน ISC bus</li></ul><pre><strong>import </strong>machine</pre><pre>i2c = machine.I2C(scl=machine.Pin(5), sda=machine.Pin(4), freq=100000)</pre><pre>i2c.readfrom(0x3a, 4)<br>i2c.writeto(0x3a, ‘12’)</pre><pre>buf = bytearray(10) <br>i2c.writeto(0x3a, buf)</pre><ul><li>คำสั่งการใช้งานใน่ส่วนของ Deep-sleep mode</li></ul><pre><strong>import</strong> machine</pre><pre>rtc = machine.RTC()<br>rtc.irq(trigger=rtc.ALARM0, wake=machine.DEEPSLEEP)</pre><pre>if machine.reset_cause() == machine.DEEPSLEEP_RESET:<br> print(‘woke from a deep sleep’)</pre><pre>rtc.alarm(rtc.ALARM0, 10000)</pre><pre>machine.deepsleep()</pre><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=7cb68979ec57" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[ตอนที่ 2 : ขั้นตอนการ Flash Firmware]]></title>
            <link>https://medium.com/@Pythogun/%E0%B8%95%E0%B8%AD%E0%B8%99%E0%B8%97%E0%B8%B5%E0%B9%88-2-%E0%B8%82%E0%B8%B1%E0%B9%89%E0%B8%99%E0%B8%95%E0%B8%AD%E0%B8%99%E0%B8%81%E0%B8%B2%E0%B8%A3-flash-firmware-32a7f98fb1ef?source=rss-8afaf524a207------2</link>
            <guid isPermaLink="false">https://medium.com/p/32a7f98fb1ef</guid>
            <dc:creator><![CDATA[Pythogun]]></dc:creator>
            <pubDate>Tue, 21 Mar 2017 07:56:55 GMT</pubDate>
            <atom:updated>2017-04-26T09:49:36.942Z</atom:updated>
            <content:encoded><![CDATA[<p>จากที่กล่าวมาใน ตอนที่ 1 แล้ว ในการใช้ Micropython นั้นจะมีการใช้ควบคู่กับ hardware esp8266 เพื่อใช้ในการ run code โดยไม่ต้องผ่านการ compile และสามารถทำได้ผ่าน module wifi โดยในวันนี้เราจะมาพูดถึงสิ่งที่จำเป็นในการติดตั้ง ที่จำเป็นกับ hardware</p><p>โดยในส่วนนี้เราจะมาพูดถึง การทำ Flash firmware บน Micropython</p><p>สามารถ download ได้จากเว็บไซต์หลักของ micropython ได้ <a href="http://micropython.org/download">http://micropython.org/download</a></p><p>โดยทำการโหลดในหัวข้อของ Firmware for esp8266 boards</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/624/1*j_nSXsh8hAMOMSj_JYKn5A.png" /></figure><p>และทำการโหลด version ล่าสุดมาเพื่อทำการติดตั้ง ลง ใน esp8266</p><h4>ขั้นตอนที่ 1 : Set path</h4><ul><li>พิมพ์คำว่า path ในช่อง Search ของ Windows</li><li>คลิก Edit the system environment variables</li><li>คลิก environment variables</li><li>ตรงช่อง System variables ให้ เลือกที่ Path แล้ว Edit</li><li>คลิกปุ่ม new จากนั้นใส่path C:\Python27\Scripts</li></ul><h4>ขั้นตอนที่2 : install pip</h4><p>เราจำเป็นต้องทำการ install pip เพื่อเป็นส่วนช่วยให้เราดาวน์โหลด esptool.py ในการทำ flash ได้</p><ul><li>เริ่มจาก เข้า command-line</li></ul><p>&gt;easy_install pip</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/412/1*SdCWktoMVHHyK7VyAPkMRA.png" /></figure><ul><li>เพื่อทำการลง pip ให้แก่ระบบ และ ทำการดาวน์โหลด esptool ด้วยคำสั่ง</li></ul><p>&gt; pip install –esptool</p><ul><li>ในกรณีที่ ที่เคยลง esptool ไปแล้ว แต่อยาก update version ของ</li></ul><p>&gt; pip install –upgrade esptool</p><h4>ขั้นตอนที่ 3 : ขั้นตอนการ Flash Firmware</h4><p>หลังจากทำการ install แล้ว จะทำให้เราสามารถ ใช้ esptool ได้แล้ว เพื่อใช้ในการ flash firmware</p><p>ขั้นตอนการ flash ที่ยกมาใช้ในตอนนี้จะมีขั้นตอนการ flash อยู่ 2 ขั้นตอน ซึ่งจะต้องเริ่มต้น โดยเชื่อมต่อกับ esp8266 ผ่านทาง serial port จากนั้นให้เข้า flash mode ของ esp8266 ก่อนการเรียกใช้งานคำสั่ง</p><ul><li>การลบ firmware ที่เก็บไว้ใน esp8266 โดยจะใช้คำสั่งใน cmd ดังนี้</li></ul><p>&gt;python esptool.py –p ตามด้วย port ที่ ESP8266 เชื่อมต่อกับคอมพิวเตอร์ของเราอยู่ และตามด้วย erase_flash</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/573/1*wVyXxTt6OeuZebj6MRCKtQ.png" /></figure><p>เพื่อเป็นการเคลียร์ firmware ที่มีอยู่ใน ตัวของ esp8266 เพื่อทำการเขียน firmware ลงไปใหม่ *จำเป็นต้องทำเพื่อความชัวร์*</p><ul><li>การเขียน firmware ลงไปใน esp8266 จะใช้โดยการเรียกคำสั่ง</li></ul><p>&gt;python esptool.py –p com3 write_flash 0 ตามด้วย path ของ file Firmware micropython</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/815/1*MDjb-tkSINtzG4nK_Erwnw.png" /></figure><p>เมื่อทำตามขั้นตอนเสร็จสิ้น แล้วแสดงผลตามรูปข้างต้น ก็จะสามารถใช้งาน Micropython ได้ทันที โดยสามาถใช้งานผ่านทาง Serial port</p><p>โดยทางเราเลือกใช้งานผ่าน โปรแกรม Putty</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/602/1*g6J2mOGE7jizXPLU9s_SAw.png" /></figure><p>Serial line : port ที่ ESP8266 เชื่อมต่ออยู่</p><p>Speed(baudrate) : โดยปกติแล้วหลังจาก flash จะมีค่า default เป็น 115200</p><p>หลังจากนั้นกด Open และเริ่มต้นใช้งานได้ทันที</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/825/1*pKO1JxCkxoZvWoAW-hOW2Q.png" /><figcaption>หน้าตา REPL ของ micropython</figcaption></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=32a7f98fb1ef" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[ตอนที่ 1 : What is Micropython & ESP 8266]]></title>
            <link>https://medium.com/blogs-194/what-is-micropython-esp-8266-f1a54c6fbadd?source=rss-8afaf524a207------2</link>
            <guid isPermaLink="false">https://medium.com/p/f1a54c6fbadd</guid>
            <dc:creator><![CDATA[Pythogun]]></dc:creator>
            <pubDate>Wed, 08 Mar 2017 06:58:56 GMT</pubDate>
            <atom:updated>2017-04-21T08:17:23.199Z</atom:updated>
            <content:encoded><![CDATA[<h3>What is Micropython ?</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/960/1*mhtG4A0pDbL0eOu1T32edA.jpeg" /></figure><p>Micropython เป็นการใช้ภาษา Python ในการเขียนโปรแกรมขนาดเล็ก ที่สามารถทำงานได้โดยเชื่อมต่อบน development boards ด้วย Micropython นั้น คุณสามารถเขียนโปรแกรมได้อย่างเรียบง่าย และ สามารถใช้การเขียนภาษา python ขั้นพื้นฐานเพื่อควบคุมการทำงานในส่วนของ hardware ได้เลย ซึ่งมีความซับซ้อนน้อยกว่า การใช้ภาษา C,C++</p><p>ความเรียบง่ายของการเขียนโปรแกรมโดยใช้ภาษา Python ทำให้ Micropython เป็นทางเลือกที่ดีสำหรับผู้เริ่มต้นที่ยังใหม่กับ การเขียนโปรแกรมและhardware อย่างไรก็ตาม Micropython ยังค่อนข้างมีความสามารถในการสนับสนุนการทำงานหลายรูปแบบและการสนับสนุนมากที่สุดในด้านของ syntax ซึ่งแทบไม่มีความแตกต่างจากการใช้ภาษา python นอกเหนือจากความสะดวกในการใช้งาน</p><p>Micropython มีคุณสมบัติพิเศษบางอย่างที่ทำให้มันแตกต่างจากระบบ embedded ตัวอื่น ๆ ดังนี้</p><ul><li>Interactive REPL, or read-evaluate-print loop.</li></ul><p>โดยในส่วนนี้จะช่วยให้คุณสามารถเชื่อมต่อไปยังบอร์ด รวมถึงเขียนโค้ดแล้วรันได้โดยไม่จำเป็นต้อง compile โค้ดชุดนั้นๆ ซึ่งจะเหมาะสำหรับผู้ที่เพิ่งเริ่มต้นและใช้ในการทดลองกับ hardware</p><ul><li>Extensive software library.</li></ul><p>เช่นเดียวกับการเขียนโปรแกรมปกติด้วยภาษา Python การเขียนด้วยภาษา Micropython คือการรวมข้อมูลและสร้างขึ้นใน library เพื่อสนับสนุนงานเป็นจำนวนมาก ยกตัวอย่างเช่นการแยก JSON ข้อมูลจากบริการเว็บค้นหาข้อความ ที่มีการแสดงออกปกติ หรือ แม้กระทั่งการทำโปรแกรม socket network ซึ่งเป็นเรื่องง่ายที่ที่สามารถสร้างได้ใน library ของ Micropython</p><ul><li>Extensibility.</li></ul><p>สำหรับผู้ใช้ในระดับขั้นสูงขึ้นมาหน่อย Micropython จะขยายขอบเขตของการทำงาน สำหรับภาษาที่มีที่มีระดับต่ำ เช่น C / C ++ โดยจะมีฟังก์ชั่นเพื่อให้สามารถใช้ภาษา Micropython ระดับสูงที่ทำให้สามารถแสดงผล/ประมวลผลได้ได้เร็วขึ้น</p><h3>What is ESP 8266 ?</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/700/1*WiloT6Je2RZzNFffsX-VNQ.jpeg" /><figcaption><a href="https://www.arduitronics.com/product/1032/esp-12f-esp8266-serial-wifi-transceiver-module">https://www.arduitronics.com/product/1032/esp-12f-esp8266-serial-wifi-transceiver-module</a></figcaption></figure><p><strong>ESP 8266</strong> คือ โมดูล WiFi ที่ผลิตโดย ประเทศจีน ซึ่งมีความพิเศษอยู่ที่ตัวมันนั้นสามารถรันโปรแกรมลงไปได้เลย ทำให้สามารถนำไปใช้งานแทนไมโครคอนโทรลเลอร์ได้เลย และมีพื้นที่ในการเก็บโปรแกรมมากถึง 4 MB ทำให้มีพื้นที่ค่อนข้างมากในการเขียนโปรแกรมใช้งาน</p><p>ESP 8266 เป็นหนึ่งในชื่อของชิปไอซี บนบอร์ดของโมดูล ซึ่งในตัวไอซี ESP 8266 นี้ ไม่มีพื้นที่โปรแกรม ( Flash Memory ) ในตัว ทำให้ต้องใช้ไอซีจากภายนอก ( External Flash Memory ) ในการเก็บโปรแกรม โดยใช้การเชื่อมต่อผ่านโปรโตคอล SPI ซึ่งเป็นเหตุผลที่ว่า โมดูล ESP 8266 มีพื้นที่โปรแกรมมากกว่าไอซีไมโครคอนโทรลเลอร์เบอร์อื่นๆนั่นเอง</p><p>ESP 8266 ทำงานที่แรงดันไฟฟ้า 3.3V-3.6V ดังนั้นการนำไปใช้งานร่วมกับเซ็นเซอร์อื่นๆที่ใช้แรงดัน 5V ต้องใช้วงจรแบ่งแรงดันมาช่วย เพื่อไม่ให้โมดูลพังเสียหาย กระแสที่โมดูลใช้งานสูงสุดคือ 200mA ความถี่คริสตอล 40MHz ทำให้เมื่อนำไปใช้งานกับอุปกรณ์ที่ทำงานรวดเร็วตามความถี่ เช่น LCD ทำให้การแสดงผลข้อมูลรวดเร็วกว่าไมโครคอนโทรลเลอร์ยอดนิยมอย่าง Arduino เป็นอย่างมาก</p><p>ขาของ NodeMCU แบ่งได้ดังนี้</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*shC03qi3SNlX0eP2cJKT3g.png" /><figcaption><a href="http://aj-bee.blogspot.com/2015/09/nodemcu-v2-esp8266-part-1.html">http://aj-bee.blogspot.com/2015/09/nodemcu-v2-esp8266-part-1.html</a></figcaption></figure><ul><li><strong>VCC</strong> เป็นขาสำหรับจ่ายไปเข้าเพื่อให้โมดูลทำงานได้ ซึ่งแรงดันที่ใช้งานได้คือ 3.3–3.6V</li><li><strong>GND </strong>เป็นขา ground หรือขาที่ต่อสายดิน</li><li><strong>Reset</strong> และ CH_PD (หรือ EN) เป็นขาที่ต่อเข้ากับไฟขั้วบวก (Pull-up) เพื่อให้โมดูลสามารถทำงานได้ ทั้ง 2 ขานี้สามารถนำมาใช้รีเซ็ตโมดูลได้เหมือนกัน แต่แตกต่างตรงที่ขา Reset สามารถปล่อยลอยไว้ได้ แต่ขา CH_PD (หรือ EN) จำเป็นต้องต่อเข้ากับไฟขั้วบวก (Pull-up) เพราะเมื่อขานี้ไม่ต่อเข้ากับไฟขั้วบวก โมดูลจะไม่ทำงานทันที</li><li><strong>GPIO</strong> เป็นขาดิจิตอลอินพุต / เอาต์พุต ทำงานที่แรงดัน 3.3V</li><li><strong>GPIO15</strong> เป็นขาที่ต้องต่อลง GND เท่านั้น เพื่อให้โมดูลทำงานได้</li><li><strong>GPIO0</strong> เป็นขาทำหรับการเลือกโหมดทำงาน หากนำขานี้ลง GND จะเข้าโหมดโปรแกรม หากปล่อยลอยไว้ หรือนำเข้ากับไฟขั้วบวก จะเข้าโหมดการทำงานปกติ</li><li><strong>ADC</strong> เป็นขาอนาล็อกอินพุต รับแรงดันได้สูงสุดที่ 1V ขนาด 10 บิต การนำไปใช้งานกับแรงดันที่สูงกว่าต้องใช้วงจรแบ่งแรงดันเข้าช่วย</li></ul><p><strong>ESP 8266</strong> มีลักษณะการทำงานเป็น Serial-to-WiFi โดยเป็นการช่วยให้อุปกรณ์อื่นๆ เช่น MCU สามารถต่อเข้ากับ internet ได้โดยใช้ port serial( ขา Tx, ขา Rx ) และใช้คำสั่ง AT ในการควบคุมการทำงาน</p><p>source by <a href="https://learn.adafruit.com/micropython-basics-what-is-micropython/overview">https://learn.adafruit.com/micropython-basics-what-is-micropython/overview</a> &amp; <a href="http://www.ioxhop.com/article/13/esp8266-%E0%B8%95%E0%B8%AD%E0%B8%99%E0%B8%97%E0%B8%B5%E0%B9%88-1-%E0%B8%A3%E0%B8%B9%E0%B9%89%E0%B8%88%E0%B8%B1%E0%B8%81%E0%B8%81%E0%B8%B1%E0%B8%9A-esp-%E0%B9%81%E0%B8%A5%E0%B8%B0%E0%B8%A3%E0%B8%B8%E0%B9%88%E0%B8%99%E0%B8%97%E0%B8%B5%E0%B9%88%E0%B8%99%E0%B8%B4%E0%B8%A2%E0%B8%A1%E0%B9%83%E0%B8%8A%E0%B9%89%E0%B8%87%E0%B8%B2%E0%B8%99">http://www.ioxhop.com/article/13/esp8266-ตอนที่-1-รู้จักกับ-esp-และรุ่นที่นิยมใช้งาน</a></p><h4>สามารถหาซื้อ Nodemcu ได้จาก</h4><ul><li><a href="https://www.arduino.in.th/product/474/nodemcu-development-kit-v3">https://www.arduino.in.th/product/474/nodemcu-development-kit-v3</a></li><li><a href="http://www.io-shop.com/product/30/nodemcu-development-board-iot">http://www.io-shop.com/product/30/nodemcu-development-board-iot</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f1a54c6fbadd" width="1" height="1" alt=""><hr><p><a href="https://medium.com/blogs-194/what-is-micropython-esp-8266-f1a54c6fbadd">ตอนที่ 1 : What is Micropython &amp; ESP 8266</a> was originally published in <a href="https://medium.com/blogs-194">Technologies For Everyone</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>