Essentials

Started by tha, November 13, 2023, 09:48:47 AM

Previous topic - Next topic

tha

https://docs.arduino.cc/hardware/uno-r4-wifi

                                                          Essentials

First Steps

Quickstart Guide

ทุกอย่างที่คุณต้องรู้เพื่อเริ่มต้นใช้งานบอร์ด Arduino ใหม่ของคุณ.

Getting Started with UNO R4 WiFi แปลไปแล้วตามลิ้งค์ตรงนี้ครับ

https://www.electoday.com/index.php/topic,17123.32.html

tha

Suggested Libraries

Wire

library นี้ช่วยให้คุณสามารถสื่อสารกับ I2C / TWI devices.

SPI

The SPI library นี้ช่วยให้คุณสามารถสื่อสารกับ SPI devices, ด้วย the Arduino board เป็น the controller device.

Servo

The Servo library ช่วยให้ an Arduino board ควบคุม RC (hobby) servo motors.

tha

https://www.arduino.cc/reference/en/language/functions/communication/wire/
Reference > Language > Functions > Communication > Wire

Wire

[Communication]

Description

ไลบรารีนี้ช่วยให้คุณสามารถสื่อสารกับอุปกรณ์ I2C/TWI บนบอร์ด Arduino ที่มี the R3 layout (1.0 pinout), the SDA (data line) และ SCL (clock line) อยู่บน the pin headers ใกล้กับ AREFpin. Arduino Due มีอินเทอร์เฟซ I2C/TWI สองตัว SDA1 และ SCL1 ใกล้กับพิน AREF และอีกอันอยู่บนพิน 20 และ 21

ตามข้อมูลอ้างอิง ตารางด้านล่างแสดงตำแหน่งของ TWI pins บนบอร์ด Arduino ต่างๆ



ตั้งแต่ Arduino 1.0 ไลบรารีจะสืบทอดมาจาก the Stream functions, ทำให้มันสอดคล้องกับ read/write libraries อื่นๆ ด้วยเหตุนี้ send() และ receive() จึงถูกแทนที่ด้วย read() และ write()

เวอร์ชันล่าสุดของ the Wire library สามารถใช้ timeouts เพื่อป้องกันการล็อกเมื่อเผชิญกับปัญหาบางอย่างบน the bus, แต่ไม่ได้เปิดใช้งานโดยค่าเริ่มต้น (ยัง)ในเวอร์ชันปัจจุบัน. ขอแนะนำให้เปิดใช้งาน timeouts เหล่านี้เสมอเมื่อใช้ the Wire library. ดู the Wire.setWireTimeout function สำหรับรายละเอียดเพิ่มเติม.

Note: มีทั้งเวอร์ชั่น 7 และ 8-bit ของ I2C addresses. 7 bits ระบุ the device, และบิตที่ 8 กำหนดว่าอุปกรณ์นั้นถูกเขียนถึงหรืออ่านจาก. The Wire library ใช้ 7 bit addresses ตลอด. ถ้าคุณมี a datasheet หรือโค้ดตัวอย่างที่ใช้ 8-bit address, คุณจะต้องทิ้งบิตต่ำ (เช่น เลื่อนค่าไปทางขวาหนึ่งบิต), โดยได้ค่า an address ระหว่าง 0 และ 127. อย่างไรก็ตาม the addresses จาก 0 ถึง 7 ไม่ถูกใช้เนื่องจากถูกสงวนไว้ ดังนั้น the first address ที่สามารถถูกใช้คือ 8. โปรดทราบว่า a pull-up resistor ถูกต้องการเมื่อต่อ SDA/SCL pins. โปรดดูตัวอย่างสำหรับข้อมูลเพิ่มเติม บอร์ด MEGA 2560 มี pull-up resistors บน pins 20 and 21 onboard.

The Wire library implementation ใช้ a 32 byte buffer, ดังนั้นการสื่อสารใดๆ ควรอยู่ภายในขีดจำกัดนี้ ไบต์ที่เกินในการส่งข้อมูลครั้งเดียวจะถูกทิ้ง.

เพื่อใช้ library นี้:

#include <Wire.h>



tha

https://www.arduino.cc/reference/en/language/functions/communication/spi/
Reference > Language > Functions > Communication > Spi

SPI

[Communication]

Description

library นี้ช่วยให้คุณสามารถสื่อสารกับ SPI devices, โดยมี the Arduino board เป็น the controller device. ไลบรารีนี้มาพร้อมกับแพลตฟอร์ม Arduino ทุกแพลตฟอร์ม (avr, megaavr, mbed, samd, sam, arc32) ดังนั้นคุณไม่จำเป็นต้องติดตั้งไลบรารีแยกต่างหาก.

เพื่อใช้ library นี้:

#include <SPI.h>

เพื่ออ่านเกี่ยวกับ Arduino และ SPI, คุณสามารถเยี่ยมชม the Arduino & Serial Peripheral Interface (SPI) guide.


tha

https://www.arduino.cc/reference/en/libraries/servo/
Reference > Libraries > Servo

Servo

Device Control

ช่วยให้ Arduino boards ควบคุม servo motors ได้หลากหลาย.
ไลบรารีนี้สามารถควบคุมเซอร์โวจำนวนมากได้. ต้องระมัดระวังในการใช้ timers: the library สามารถควบคุม 12 servos โดยใช้เพียง 1 timer. บน the Arduino Due คุณสามารถควบคุมได้มากถึง 60 servos.

ไปที่พื้นที่เก็บข้อมูล

Compatibility

library นี้เข้ากันได้กับ the avr, megaavr, sam, samd, nrf52, stm32f4, mbed, mbed_nano, mbed_portenta, mbed_rp2040, renesas, renesas_portenta, renesas_uno architectures ดังนั้นคุณสามารถใช้มันบน the following Arduino boards:



Compatibility Note

หมายเหตุ: แม้ว่าไลบรารีควรจะคอมไพล์อย่างถูกต้องบนสถาปัตยกรรมเหล่านี้ แต่มันอาจต้องการคุณสมบัติฮาร์ดแวร์เฉพาะที่อาจมีให้ใช้งานเฉพาะบนบอร์ดบางรุ่นเท่านั้น

tha

Usage

library นี้ช่วยให้ an Arduino board ควบคุม RC (hobby) servo motors. Servos ได้รวม gears และ a shaft ที่สามารถถูกควบคุมได้อย่างแม่นยำ. Standard servos ช่วยให้ the shaft สามารถวางตำแหน่งได้หลายมุม, โดยปกติจะอยู่ระหว่าง 0 ถึง 180 องศา. Continuous rotation servos ช่วยให้การหมุนของ the shaft ถูกตั้งค่าเป็นความเร็วต่างๆ.

The Servo library รองรับได้มากถึง 12 motors บน Arduino boards ส่วนใหญ่และ 48 บน the Arduino Mega. บนบอร์ดอื่นที่ไม่ใช่ Mega, การใช้ the library นี้จะปิดการใช้งาน analogWrite() (PWM) functionality บน pins 9 และ 10, ไม่ว่าจะมี a Servo อยู่บนพินเหล่านั้นหรือไม่ก็ตาม. บน the Mega, มากถึง 12 servos สามารถถูกใช้โดยไม่รบกวน PWM functionality; การใช้ 12 ถึง 23 motors จะปิดการใช้งาน PWM บน pins 11 และ 12.

เพื่อใช้ library นี้:

#include <Servo.h>

tha

Circuit

Servo motors มีสายสามเส้น: power, ground, และ signal. The power wire โดยทั่วไปจะเป็นสีแดง และควรถูกต่อกับพิน 5V บน the Arduino board. The ground wire โดยทั่วไปจะเป็นสีดำหรือน้ำตาลและควรถูกต่อกับ a ground pin บน the Arduino board. The signal pin โดยทั่วไปจะเป็นสีเหลือง, ส้มหรือขาวและควรถูกต่อกับ a digital pin บน the Arduino board. โปรดทราบว่าเซอร์โวใช้พลังงานมาก ดังนั้นหากคุณจำเป็นต้องขับมากกว่าหนึ่งหรือสองตัว, คุณอาจต้องจ่ายไฟจากแหล่งจ่ายไฟแยกต่างหาก (เช่น ไม่ใช่พิน 5V บน Arduino ของคุณ). ตรวจสอบให้แน่ใจว่าได้ต่อ the grounds ของ the Arduino และของ external power supply เข้าด้วยกัน.

Examples

  •  Knob: ควบคุม the shaft ของ a servo motor โดยการหมุน a potentiometer
  •  Sweep: กวาด the shaft ของ a servo motor ไปมา


tha

Arduino Basics

Built-in Examples

Built-in Examples คือ sketches ที่รวมใน the Arduino IDE และสาธิตทุก basic Arduino commands.

Learn

ค้นพบบทความ หลักการ และเทคนิคที่น่าสนใจที่เกี่ยวข้องกับ the Arduino ecosystem.

Language References

Arduino programming language สามารถถูกแบ่งออกได้เป็น 3 ส่วนหลัก ได้แก่: functions, values (ตัวแปรและค่าคงที่), และ structure.