โค้ดตัวอย่าง
Category: สู่เส้นทางดิจิตอล
การใช้ Arduino ร่วมกับ NodeMCU/ESP8266 จะมีด้วยกันหลายแบบ เช่น I2C, Serial เพื่อเพิ่ม I/O เช่นเพิ่มขา digital, ขา analog ในที่นี้จะยกตัวอย่างการสื่อสารแบบ Serial ก่อนเพราะเป็นตัวอย่างที่ง่ายต่อการเข้าใจ ในตัวอย่างจะเป็นการส่งค่าระหว่าง Arduino กับ NodeMCU โดยกำหนดให้ Arduino ส่งค่า int (จำนวนเต็ม) และ float (ทศนิยม) ไปยัง NodeMCU โดยสมมติว่า Arduino กำลังส่งค่าอะไรบางอย่างเป็นจำนวนเต็ม (int) และกำลังอ่านค่า Sensor เป็นทศนิยม (float) จากตัวอย่าง เราสามารถนำค่าที่ NodeMCU อ่านได้เป็น int และ float ไปใช้งานได้เลยโดยใช้ฟังก์ชั่น parseInt(), parseFloat() ในส่วนของโค้ดโปรแกรมจะมีด้วยกันสองฝั่งคือ ฝั่งArduino และ ฝั่งNodeMCU
หมายเหตุ สามารถใช้กับ Arduino รุ่นใดก็ได้ หรือจะเอาไปใช้งานในการเพิ่ม output ให้กับ Nodemcu ก็ได้
Download library arduino
LCD 16×2 : LiquidCrystal.zip
4×4 Matrix KEYPAD : HCMatrixKeypad.zip
OLED : จอ OLED :: OLED Adafuit1 และ OLED Adafuit2
DH11 : Adafuit DH11
Ultrasonic sensor HC-SR04 : Download
AM2320 : Download
MM7361 : Download
8×8 Max7219 LED Matrix : Download
การติดตั้ง Library บน Arduino : ที่นี่
โปรแกรมที่จำเป็น
โปรแกรมสร้างภาพบนจอ LCD,OLED : Download
Another illustration that demonstrate how to wire the i2c 16×2 LCD on ESP8266 12 Known as NodeMCU, as you can see the diagram below the SCL as Arduino Analog Pin A4 is connected to D1 on NodeMCU at the same time the D2 as the SDA represent as Analog Pin A5 on Arduino Board, As you may notice that the sketch code that we used it is not LUA script it is actually standard Arduino C compiled/Interpret by Arduino IDE. If you don’t have an ESP8266 runs on Arduino IDE please follow this link.
Introduction
Do you have a 3.3V I2C or SPI sensor that might go up in smoke if connected to a 5V Arduino? Or a 5V device that needs a workaround to be compatible with your 3.3V Raspberry Pi, Arduino Due or pcDuino?
To get over this obstacle you need a device that can shift 3.3V up to 5V or 5V down to 3.3V. This is called logic level shifting. Level shifting is a dilemma so common we designed a simple PCB assembly to make interfacing devices a little easier: the Bi-Directional Logic Level Converter.
IC Voltage Regulator เป็น IC ที่แปลงจากแรงดันที่สูงกว่า(Vin) ให้เป็นแรงดันที่ต่ำกว่าและเรียบคงที่(Vout) โดยในบทความนี้จะกล่าวถึง IC 78xx Series ซึ่งเป็น Fixed Linear Voltage Regulator คือไม่สามารถเปลี่ยนแรงดันเอาต์พุตได้ (มี Linear Voltage Regulator บางตัวที่สามารถเปลี่ยนค่า Vout ได้ เช่น LM317)โดยแต่ละรุ่นใน 78xx Series ก็จะมีค่า แรงดันเอาต์พุตที่ต่างกันไป โดยการดูจากเลข2หลักท้ายของชื่อ IC เช่น 7805 ก็จะมีค่า แรงดันเอาต์พุต 5V
ชื่อ IC | แรงดันเอาต์พุต(V) |
---|---|
7805 | +5 |
7806 | +6 |
7808 | +8 |
7810 | +10 |
7812 | +12 |
7815 | +15 |
7818 | +18 |
7824 | +24 |