아두이노 우노 Q RS485

Arduino UNO Q와 TTL-to-RS485 모듈을 사용한 RS485 시리얼 통신입니다. RS485는 장거리 통신(최대 1200m), 높은 잡음 면역성, 다중 장치 버스 토폴로지를 지원하므로 산업 및 자동화 프로젝트에 이상적입니다. Bridge와 Telegram을 사용하면 Python이나 휴대폰에서 원격으로 RS485 데이터를 송수신할 수 있습니다.

이 튜토리얼에서 배울 내용:

Arduino UNO Q rs485

필요한 하드웨어

1×Arduino UNO Q 아마존
1×USB Cable for Arduino Uno Q 아마존
1×TTL-RS485 변환 모듈 쿠팡 | 아마존
1×점퍼케이블 쿠팡 | 아마존
1×(옵션) USB-RS485 변환기 쿠팡 | 아마존
1×(옵션) USB to RS485 Cable 아마존
1×(추천) 아두이노 우노용 스크루 터미널 블록 쉴드 쿠팡 | 아마존
1×(추천) Sensors/Servo Expansion Shield for Arduino Uno 쿠팡 | 아마존
1×(추천) 아두이노 우노용 브레드보드 쉴드 쿠팡 | 아마존
1×(추천) 아두이노 우노용 케이스 쿠팡 | 아마존
1×(추천) 아두이노 우노용 프로토타이핑 베이스 플레이트 & 브레드보드 키트 아마존
공개: 이 포스팅 에 제공된 일부 링크는 아마존 제휴 링크입니다. 이 포스팅은 쿠팡 파트너스 활동의 일환으로, 이에 따른 일정액의 수수료를 제공받습니다.

TTL to RS485 모듈 정보

Arduino UNO Q MCU는 TTL 로직 레벨(3.3V)을 사용한 UART로 통신합니다. TTL 신호는 범위가 제한되어 있습니다. RS485 호환 장치(센서, 드라이브, 미터, 산업 제어기)와 장거리 통신하려면 TTL 신호를 차등 RS485 표준으로 변환해야 합니다. TTL-to-RS485 모듈은 양쪽 방향으로 이 변환을 수행합니다.

RS485 주요 장점:

  • 장거리: 최대 1200미터
  • 높은 잡음 면역성
  • 다중 드롭 버스: 단일 버스에 32개 장치까지
rs485 module 사용법 핀아웃

핀아웃

  • TTL 인터페이스 (Arduino UNO Q MCU에 연결):
    • VCC: 전원 — 3.3V에 연결
    • GND: 그라운드
    • RXD: 데이터 입력 — MCU TX 핀(D6)에 연결
    • TXD: 데이터 출력 — MCU RX 핀(D7)에 연결
  • RS485 인터페이스:
    • D+ (A 또는 TR+): 차등 데이터 라인 A
    • D- (B 또는 TR-): 차등 데이터 라인 B
    • GND: 선택사항 — 노이즈 감소를 위해 연결

배선도

Arduino UNO Q ttl to rs485 module 연결 배선도

이 이미지는 Fritzing을 사용하여 만들어졌습니다. 이미지를 확대하려면 클릭하세요.

TTL-to-RS485 모듈 핀 Arduino UNO Q MCU 핀 참고
VCC 3.3V
GND GND
RXD D6 (MCU TX)
TXD D7 (MCU RX)

D+와 D-를 RS485 버스에 연결합니다. PC로 테스트할 때는 USB-to-RS485 어댑터에 연결합니다.

RS485 프로그래밍 방법

  • SoftwareSerial을 포함하고 RS485 시리얼 객체를 만듭니다:
#include <SoftwareSerial.h> SoftwareSerial rs485(7, 6); // RX: D7, TX: D6
  • 들어오는 RS485 데이터 읽기:
if (rs485.available()) { char data = rs485.read(); }
  • RS485를 통해 데이터 전송:
rs485.print("Hello from Arduino UNO Q"); rs485.println("With newline");

Arduino UNO Q 코드

/* * 이 Arduino UNO Q 코드는 newbiely.kr 에서 개발되었습니다 * 이 Arduino UNO Q 코드는 어떠한 제한 없이 공개 사용을 위해 제공됩니다. * 상세한 지침 및 연결도에 대해서는 다음을 방문하세요: * https://newbiely.kr/tutorials/arduino-uno-q/arduino-uno-q-rs485 */ #include <SoftwareSerial.h> SoftwareSerial rs485(7, 6); // RX: D7, TX: D6 void setup() { Monitor.begin(9600); // USB serial for debug output rs485.begin(9600); // RS485 module serial delay(100); } void loop() { // Forward data from RS485 to Monitor if (rs485.available()) { char data = rs485.read(); Monitor.print(data); rs485.print(data); // echo back to sender } // Forward data from Monitor to RS485 if (Monitor.available()) { char data = Monitor.read(); rs485.print(data); } }

빠른 단계

Arduino UNO Q를 처음 사용하시나요? 계속하기 전에 아두이노 우노 Q 시작하기 튜토리얼을 따르세요.

  • 연결: 배선도에 표시된 대로 TTL-to-RS485 모듈을 Arduino UNO Q MCU에 연결합니다.
  • Arduino App Lab 열기: Arduino App Lab을 시작하고 Arduino UNO Q를 감지할 때까지 기다립니다.
  • 새 앱 만들기: Create New App 버튼을 클릭합니다.
create new app in 아두이노 app lab on Arduino UNO Q
  • 앱 이름을 지정합니다(예: RS485).
  • Create를 클릭하여 확인합니다.
아두이노 app lab app folders and files on Arduino UNO Q
  • 스케치 붙여넣기: 위의 MCU 코드를 복사하여 sketch/sketch.ino에 붙여넣습니다.
  • 업로드: Arduino App Lab의 Run 버튼을 클릭합니다.
click run 버튼 in 아두이노 app lab on Arduino UNO Q

테스트

RS485 통신을 테스트하려면:

  • D+와 D- 핀을 USB-to-RS485 어댑터에 연결합니다:
Arduino UNO Q rs485 to pc communication
  • PC에서 시리얼 터미널을 엽니다(Tera Term 또는 PuTTY 같은).
  • 보드 레이트를 9600으로 설정하고 올바른 COM 포트를 선택합니다.
  • 텍스트를 입력하고 전송합니다. Arduino UNO Q가 이를 에코백합니다 — 터미널에 에코된 데이터가 표시됩니다.

Bridge: Linux + MCU

이 섹션은 Bridge를 통해 Linux 측(Python)에서 RS485 데이터를 송수신하는 방법을 보여줍니다:

  • TTL-to-RS485 모듈은 SoftwareSerial을 통해 MCU에 연결됩니다 — MCU가 모든 시리얼 I/O를 처리합니다
  • MPU는 SoftwareSerial을 직접 사용할 수 없습니다 — Bridge 함수를 호출하여 RS485 데이터를 송수신합니다
  • MPU는 Wi-Fi가 있습니다 — 전체 Debian Linux를 실행하며 RS485 데이터를 Telegram이나 웹 서비스로 릴레이할 수 있습니다
  • Arduino_RouterBridge는 두 프로세서 간의 RPC 통신을 활성화합니다
  • ⚠️ /dev/ttyHS1 (Linux)과 Serial1 (MCU)는 라우터에 의해 예약됨 — 사용자 코드에서 절대 열지 마세요

MCU 코드 (Bridge)

/* * 이 Arduino UNO Q 코드는 newbiely.kr 에서 개발되었습니다 * 이 Arduino UNO Q 코드는 어떠한 제한 없이 공개 사용을 위해 제공됩니다. * 상세한 지침 및 연결도에 대해서는 다음을 방문하세요: * https://newbiely.kr/tutorials/arduino-uno-q/arduino-uno-q-rs485 */ #include "Arduino_RouterBridge.h" #include <SoftwareSerial.h> SoftwareSerial rs485(7, 6); // RX: D7, TX: D6 String received_data = ""; String send_rs485(String arg) { rs485.println(arg); Monitor.print("Sent via RS485: "); Monitor.println(arg); return "ok:sent"; } String get_received(String arg) { String result = received_data; received_data = ""; return result; } void setup() { Bridge.begin(); Monitor.begin(); rs485.begin(9600); delay(100); Bridge.provide_safe("send_rs485", send_rs485); Bridge.provide("get_received", get_received); Monitor.println("Arduino UNO Q RS485 Bridge ready"); } void loop() { while (rs485.available()) { char c = rs485.read(); received_data += c; } }

Python 코드 (Bridge)

/* * 이 Arduino UNO Q 코드는 newbiely.kr 에서 개발되었습니다 * 이 Arduino UNO Q 코드는 어떠한 제한 없이 공개 사용을 위해 제공됩니다. * 상세한 지침 및 연결도에 대해서는 다음을 방문하세요: * https://newbiely.kr/tutorials/arduino-uno-q/arduino-uno-q-rs485 */ from arduino.app_utils import * import time def loop(): print("Sending message via RS485...") result = Bridge.call("send_rs485", "Hello from Arduino UNO Q!") print(f"Result: {result}") time.sleep(1) data = Bridge.call("get_received") if data: print(f"Received via RS485: {data}") else: print("No data received") time.sleep(2) App.run(user_loop=loop)

빠른 단계

  • 연결: 위에 표시된 대로 TTL-to-RS485 모듈을 Arduino UNO Q에 연결합니다.
  • Arduino App Lab을 열고 RS485Bridge라는 새 앱을 만듭니다.
  • MCU 스케치를 붙여넣으세요 sketch/sketch.ino에.
  • Python 코드를 붙여넣으세요 Python 파일에.
  • Install the library: Click the Add sketch library button (the open book icon with a + sign) in the left sidebar.
add sketch 라이브러리 in 아두이노 app lab on Arduino UNO Q
  • Search for Arduino_RouterBridge created by Arduino and click the Install button.
My Apps / DIYables Apps
Run
Bricks
No bricks added...
Sketch Libraries
No sketch libra...
Files
python
sketch
.gitignore
README.md
app.yaml
sketch.ino
Add sketch library
Arduino_RouterBridge Arduino

This library provides a simple RPC bridge for Arduino UNO Q boards, allowing communication between the board and other devices using MsgPack serialization.

0.4.1
Install
More Info
  • 업로드: Run 버튼을 클릭합니다. Python은 RS485를 통해 메시지를 보내고 에코된 데이터를 읽습니다.
click run 버튼 in 아두이노 app lab on Arduino UNO Q

App Lab 콘솔 출력

DIYables_Apps
Stop
sketch.ino
1#include "Arduino_RouterBridge.h"
Serial Monitor
Python
Message (Enter to send a message to "Newbiely" on usb(2820070321))
New Line
9600 baud
[2026-04-29 09:00:01] Arduino UNO Q RS485 Bridge ready [2026-04-29 09:00:06] Sent via RS485: Hello from Arduino UNO Q!
DIYables_Apps
Stop
sketch.ino
1#include "Arduino_RouterBridge.h"
Serial Monitor
Python
[2026-04-29 09:00:06] Sending message via RS485... [2026-04-29 09:00:06] Result: ok:sent [2026-04-29 09:00:07] Received via RS485: Hello from Arduino UNO Q!

Telegram

Telegram을 통해 RS485 데이터를 송수신합니다 — 산업용 센서의 메시지를 휴대폰으로 전달하거나 Telegram에서 RS485 장치로 명령을 보냅니다.

MCU 스케치: 이전 Bridge 섹션의 동일한 MCU 스케치를 유지합니다.

Python 코드 (Telegram)

/* * 이 Arduino UNO Q 코드는 newbiely.kr 에서 개발되었습니다 * 이 Arduino UNO Q 코드는 어떠한 제한 없이 공개 사용을 위해 제공됩니다. * 상세한 지침 및 연결도에 대해서는 다음을 방문하세요: * https://newbiely.kr/tutorials/arduino-uno-q/arduino-uno-q-rs485 */ from arduino.app_utils import * import requests import time TELEGRAM_BOT_TOKEN = "YOUR_TELEGRAM_BOT_TOKEN" CHAT_ID = "YOUR_CHAT_ID" last_update_id = 0 def get_updates(): global last_update_id url = f"https://api.telegram.org/bot{TELEGRAM_BOT_TOKEN}/getUpdates" params = {"offset": last_update_id + 1, "timeout": 5} try: response = requests.get(url, params=params, timeout=10) data = response.json() if data["ok"]: return data["result"] except Exception as e: print(f"Error getting updates: {e}") return [] def send_message(chat_id, text): url = f"https://api.telegram.org/bot{TELEGRAM_BOT_TOKEN}/sendMessage" payload = {"chat_id": chat_id, "text": text} try: requests.post(url, data=payload, timeout=10) except Exception as e: print(f"Error sending message: {e}") def loop(): updates = get_updates() for update in updates: last_update_id = update["update_id"] if "message" not in update: continue message = update["message"] chat_id = message["chat"]["id"] text = message.get("text", "").strip() print(f"Received: {text}") if text == "/start": send_message(chat_id, "Arduino UNO Q RS485 Bot\n" "/send <message> - Send a message via RS485\n" "/read - Read data received from RS485") elif text.startswith("/send"): parts = text.split(" ", 1) if len(parts) < 2: send_message(chat_id, "Usage: /send <message>") else: result = Bridge.call("send_rs485", parts[1]) send_message(chat_id, f"Sent via RS485: {parts[1]}") elif text == "/read": data = Bridge.call("get_received") if data: send_message(chat_id, f"Received via RS485:\n{data}") else: send_message(chat_id, "No data received yet.") else: send_message(chat_id, "Unknown command. Send /start for help.") time.sleep(0.3) App.run(user_loop=loop)

빠른 단계

  • YOUR_TELEGRAM_BOT_TOKEN을 BotFather에서 받은 실제 봇 토큰으로 바꿉니다.
  • YOUR_CHAT_ID를 Telegram 채팅 ID로 바꿉니다.
  • Python 코드를 앱의 Python 파일에 붙여넣습니다(동일한 MCU 스케치 유지).
  • Run 버튼을 클릭합니다 — Telegram에서 /send Hello를 보내 RS485를 통해 데이터를 전송합니다.

App Lab 콘솔 출력

DIYables_Apps
Stop
sketch.ino
1#include "Arduino_RouterBridge.h"
Serial Monitor
Python
[2026-04-29 09:10:05] Received: /send Hello RS485 device! [2026-04-29 09:10:09] Received: /read
Telegram
Telegram 12:45
Welcome to Telegram!
ArduinoBot 10:19
Chatting with Arduino...
telegram-botfather
BotFather Yesterday
Your bot has been created.

ArduinoBot

bot
Today
/send Hello RS485 device!
10:15 AM ✓✓
Sent via RS485: Hello RS485 device!
10:16 AM
/read
10:17 AM ✓✓
Received via RS485: Hello RS485 device!
10:18 AM

OpenClaw

You can adapt the OpenClaw to this tutorial by refering the instruction on 아두이노 우노 Q - OpenClaw Tutorial

프로젝트 아이디어

Arduino UNO Q와 RS485 통신으로 많은 유용한 프로젝트를 만들 수 있습니다:

  • 산업용 센서 네트워크: 여러 RS485 센서(온도, 습도, 유량)를 단일 버스에 연결합니다. MCU가 각 장치를 주소로 폴링하고, 판독값을 수집하며, Python은 주기적인 요약을 Telegram으로 보냅니다.
  • Modbus RTU 데이터 로거: RS485 버스를 사용하여 에너지 미터 또는 VFD에서 Modbus RTU 레지스터를 읽습니다. Python은 데이터를 파일로 기록하고 값이 임계값을 초과할 때 경고를 보냅니다.
  • 장거리 릴레이 제어: RS485 와이어를 100m 이상 원격 릴레이 보드로 실행합니다. Telegram에서 /send RELAY_ON을 보내면 Arduino UNO Q가 명령을 RS485를 통해 릴레이로 전달하여 릴레이를 트리거합니다.
  • 접근 제어 패널: RS485 접근 제어기를 모듈에 연결합니다. MCU가 도어 이벤트를 읽고, Python이 이를 Telegram 알림으로 전달합니다 — 어떤 도어가 언제 열렸는지 표시합니다.
  • 빌딩 자동화 게이트웨이: RS485 HVAC 또는 조명 제어기를 인터넷으로 연결합니다. Python은 Telegram 명령을 RS485 명령 문자열로 변환하고 send_rs485 Bridge 함수를 통해 보냅니다.

도전해보세요

Arduino UNO Q에서 RS485를 더 배우려 준비가 되셨나요? 다음 도전을 시도해 보세요:

  • 쉬움: Bridge 스케치를 확장하여 수신한 바이트를 라인으로 누적(구분 기호로 \n 사용)하고 get_last_line을 통해 가장 최근의 완전한 라인을 노출합니다 — RS485 데이터가 청크로 도착할 때 부분 읽기를 방지합니다.
  • 중간: Modbus 스타일 주소 필터를 구현합니다: MCU 수신 루프를 수정하여 특정 장치 주소 바이트(예: 0x01)로 시작하는 메시지만 수락하고, 유효한 프레임만 버퍼합니다 — 그리고 필터링된 페이로드를 get_received를 통해 노출합니다.
  • 어려움: 다중 장치 폴링 시스템을 구축합니다: Python JSON 설정 파일에 RS485 장치 주소 목록을 저장합니다. Python은 send_rs485를 통해 각 주소에 순차적으로 쿼리 명령을 보내고, get_received를 통해 회신을 기다리며, 각 응답을 타임스탬프가 있는 CSV 파일로 기록합니다 — Arduino UNO Q Linux 측에서 완전히 실행되는 경량 RS485 데이터 로거를 만듭니다.