산업 제조
산업용 사물 인터넷 | 산업자재 | 장비 유지 보수 및 수리 | 산업 프로그래밍 |
home  MfgRobots >> 산업 제조 >  >> Manufacturing Technology >> 제조공정

Arduino PC 모니터

구성품 및 소모품

Arduino Leonardo
기타 Arduino 장치 또는 UART 변환기가 있는 Atmega
× 1
LCD 16x2
× 1
점퍼 와이어(일반)
× 1

이 프로젝트 정보

소개

이 프로젝트의 아이디어는 실제로 재미와 지식의 필요성에서 태어났습니다. 이 프로젝트는 만들기 쉽고 많은 응용 프로그램이 있습니다. 예를 들어 일부 하드웨어 변수를 제어, 저장 및 표시하는 데 사용할 수 있습니다.

시작하겠습니다

먼저 LCD를 연결해야 합니다. (저는 I2C 변환기를 사용했습니다) :

이 작업을 수행하면 다음 부분으로 이동할 수 있습니다...

코드를 작성해 봅시다...

주소 0x3F로 16x2 LCD 설정 - I2C 버스 장치의 주소는 Arduino Playground에서 사용할 수 있는 간단한 스케치를 통해 스캔하여 찾을 수 있습니다.

#include  #include  LiquidCrystal_I2C lcd(0x3F,16,2);  

이제 String을 선언해야 합니다. 변수를 사용하여 직렬 입력을 저장하고 나머지 항목을 설정합니다.

문자열 inData; 무효 설정() { lcd.init(); Serial.begin(9600); lcd.backlight(); }  

문자열 변수로 직접 데이터를 보내려는 경우 문자열 크기에 따라 약 1초의 대기 시간이 있기 때문에 문제가 될 수 있습니다. 이를 방지하려면 char를 사용하십시오. 변수를 만들고 inData에 추가합니다. .

<사전><코드>문자 수신 =Serial.read(); inData +=수신됨;

좋아, 다 좋은데 데이터 수신이 중지되면? 해결책이 있습니다:

if (received =='*') { ... } 

char의 마지막이 언제 * Arduino는 다음 부분을 진행할지 알 것입니다. 이제 우리는 메시지를 처리해야 합니다. 이 *를 제거해야 합니다. char so:

<사전><코드>inData.remove(inData.length() - 1, 1);

마지막으로:

<사전><코드>lcd.setCursor(0,0); lcd.print(inData); 데이터 =""; // 버퍼 지우기

하지만... 사용하지 않은 두 번째 줄이 있습니다... 여기 해결책이 있습니다

if (received =='#') { inData.remove(inData.length() - 1, 1); lcd.setCursor(0,1); lcd.print(inData); 데이터 =""; } }  

char의 마지막이 #일 때 Arduino는 LCD의 두 번째 줄을 설정하고 다른 데이터를 인쇄합니다.

구성

C 또는 C++가 아닌 C#이 필요한 이유는 무엇입니까? C#은 쉽고 빠릅니다(빠른... 내 말은 서면으로)

우선 하드웨어 변수에 쉽게 액세스할 수 있도록 추가 라이브러리를 다운로드해야 합니다.

하드웨어 모니터 열기

압축을 풀면 라이브러리가 있습니다:OpenHardwareMonitorLib.dll

새 프로젝트 생성 -> Windows Forms 응용 프로그램 -> 솔루션 탐색기에서 참조를 마우스 오른쪽 버튼으로 클릭 -> 찾아보기 -> OpenHardwareMonitorLib.dll을 확인하고 잊지 말고 확인하십시오.

외관

양식 준비:

이제 코드를...

일부 지시문...

System.IO.Ports 사용; OpenHardwareMonitor.Hardware 사용;  

그리고 선언...

SerialPort 포트 =new SerialPort();Computer c =new Computer() { GPUEnabled =true, CPUEnabled =true }; 부동 소수점 값1, 값2;  

<코드>C 오픈 하드웨어 모니터 개체입니다. CPU와 GPU를 활성화해야 합니다. Form Load 이벤트에 다음을 입력하십시오.

<사전><코드> c.Open();

양식 생성자에서:

공개 Form1()  

추가:

<사전><코드>초기화();

그리고 어디에서나:

private void Init() { try { notifyIcon1.Visible =false; 포트.패리티 =패리티.없음; port.StopBits =StopBits.One; 포트.DataBits =8; port.Handshake =Handshake.None; 포트.RtsEnable =true; string[] 포트 =SerialPort.GetPortNames(); foreach(포트의 문자열 포트) { comboBox1.Items.Add(port); } 포트 전송 속도 =9600; } catch(예외 예외) { MessageBox.Show(ex.Message); } }  

단순... 선언된 변수를 초기화하고 열린 포트를 검색하여 comboBox1에 추가

이제 변수를 저장하고 보내는 주요 기능:

private void Status() { foreach (c.Hardware의 var hardwadre) { if (hardwadre.HardwareType ==HardwareType.GpuNvidia) { hardwadre.Update(); foreach(hardwadre.Sensors의 var 센서) if (sensor.SensorType ==SensorType.Temperature) { value1 =sensor.Value.GetValueOrDefault(); } } if (hardwadre.HardwareType ==HardwareType.CPU) { hardwadre.Update(); foreach(hardwadre.Sensors의 var 센서) if (sensor.SensorType ==SensorType.Temperature) { value2 =sensor.Value.GetValueOrDefault(); } } } { port.Write(값1 + "*" + 값2 + "#"); } catch(예외 예외) { timer1.Stop(); MessageBox.Show(예:메시지); toolStripStatusLabel1.Text ="Arduino가 응답하지 않습니다..."; }  

Status()를 추가하는 것을 잊지 마십시오. 타이머 틱 이벤트 기능.

이제 연결 버튼:

try { if (!port.IsOpen) { port.PortName =comboBox1.Text; 포트.Open(); timer1.Interval =Convert.ToInt32(comboBox2.Text); timer1.Enabled =true; toolStripStatusLabel1.Text ="데이터 전송 중..."; label2.Text ="연결됨"; } } catch(예외 예외) { MessageBox.Show(ex.Message); }  

콤보박스2에서 타이머 간격을 설정하지 않고 모든 것을 실행하지 않으면 포트가 이미 열려 있는지 확인하고 있습니다!

연결 해제 버튼:

try { port.Write("DIS*"); 포트.닫기(); } catch(예외 예외) { MessageBox.Show(ex.Message); } label2.Text ="연결 끊김"; timer1.Enabled =거짓; toolStripStatusLabel1.Text ="아두이노에 연결..."; 데이터 ="";  

Arduino에 마지막 데이터를 작성하여 완료되었다고 말하십시오.

예를 들어 다음과 같은 몇 가지 기능을 추가할 수 있습니다. 트레이 등에 숨기기(아래 전체 코드)

프로그램은 관리자 권한으로 실행해야 합니다!

<섹션 클래스="섹션 컨테이너 섹션 축소 가능" id="코드">

코드

<울>
  • Arduino 코드
  • C# 애플리케이션
  • Arduino 코드Arduino
    #include  #include LiquidCrystal_I2C lcd(0x3F,16,2);String inData;void setup() { Serial.begin(9600); lcd.init(); lcd.backlight();} 무효 루프() { while (Serial.available()> 0) { 문자 수신 =Serial.read(); inData +=수신됨; if (received =='*') { inData.remove(inData.length() - 1, 1); lcd.setCursor(0,0); lcd.print("GPU 온도:" + inData + char(223)+"C "); 데이터 =""; if(inData =="DIS") { lcd.clear(); lcd.setCursor(0,0); lcd.print("연결이 끊어졌습니다!"); } } if (received =='#') { inData.remove(inData.length() - 1, 1); lcd.setCursor(0,1); lcd.print("CPU 온도:" + inData + char(223)+"C "); 데이터 =""; } }}
    C# 애플리케이션C#
    <사전>시스템 사용, System.Collections.Generic 사용, System.ComponentModel 사용, System.Data 사용, System.Drawing 사용, System.Linq 사용, System.Text 사용, System.Threading.Task 사용, System.Windows 사용. Forms; using System.IO.Ports; using OpenHardwareMonitor.Hardware;namespace Arduino_Controll{ public partial class Form1 :Form { static string data; 컴퓨터 c =new Computer() { GPUEnabled =true, CPUEnabled =true }; 부동 소수점 값1, 값2; 개인 SerialPort 포트 =new SerialPort(); 공개 Form1() { InitializeComponent(); 초기화(); } 비공개 무효 Init() { 시도 { notifyIcon1.Visible =false; 포트.패리티 =패리티.없음; port.StopBits =StopBits.One; 포트.DataBits =8; port.Handshake =Handshake.None; 포트.RtsEnable =true; string[] 포트 =SerialPort.GetPortNames(); foreach(포트의 문자열 포트) { comboBox1.Items.Add(port); } 포트 전송 속도 =9600; } catch(예외 예외) { MessageBox.Show(ex.Message); } } 비공개 무효 button3_Click(객체 발신자, EventArgs e) { 시도 { port.Write("DIS*"); 포트.닫기(); } catch(예외 예외) { MessageBox.Show(ex.Message); } label2.Text ="연결 끊김"; timer1.Enabled =거짓; toolStripStatusLabel1.Text ="아두이노에 연결..."; 데이터 =""; } 개인 무효 button5_Click(객체 발신자, EventArgs e) { 시도 { if (!port.IsOpen) { port.PortName =comboBox1.Text; 포트.Open(); timer1.Interval =Convert.ToInt32(comboBox2.Text); timer1.Enabled =true; toolStripStatusLabel1.Text ="데이터 전송 중..."; label2.Text ="연결됨"; } } catch(예외 예외) { MessageBox.Show(ex.Message); } } 개인 무효 timer1_Tick(객체 발신자, EventArgs e) { Status(); } 개인 무효 Form1_Load(객체 발신자, EventArgs e) { c.Open(); } 개인 무효 Form1_Resize(개체 발신자, EventArgs e) { if (FormWindowState.Minimized ==this.WindowState) { notifyIcon1.Visible =true; 시도 { notifyIcon1.ShowBalloonTip(500, "Arduino", toolStripStatusLabel1.Text, ToolTipIcon.Info); }catch(예외 예외) { } this.Hide(); } } 비공개 무효 notifyIcon1_DoubleClick(객체 발신자, EventArgs e) { this.Show(); this.WindowState =FormWindowState.Normal; notifyIcon1.Visible =거짓; } private void Status() { foreach(c.Hardware의 var hardwadre) { if (hardwadre.HardwareType ==HardwareType.GpuNvidia) { hardwadre.Update(); foreach(hardwadre.Sensors의 var 센서) if (sensor.SensorType ==SensorType.Temperature) { value1 =sensor.Value.GetValueOrDefault(); } } if (hardwadre.HardwareType ==HardwareType.CPU) { hardwadre.Update(); foreach(hardwadre.Sensors의 var 센서) if (sensor.SensorType ==SensorType.Temperature) { value2 =sensor.Value.GetValueOrDefault(); } } } { port.Write(값1 + "*" + 값2 + "#"); } catch(예외 예외) { timer1.Stop(); MessageBox.Show(ex.Message); toolStripStatusLabel1.Text ="Arduino가 응답하지 않습니다..."; } } }}

    회로도


    제조공정

    1. 비행 시뮬레이터용 Arduino가 있는 LCD 패널
    2. Arduino를 사용하여 모니터 Ambilight 만들기
    3. LCD 애니메이션 및 게임
    4. IoT를 사용한 심박수 모니터
    5. 온수기 열전대 전압 모니터
    6. Arduino UNO로 LCD TFT 화면에 이미지 표시하기!
    7. 128x64 LCD 디스플레이의 DIY 10Hz-50kHz 오실로스코프
    8. 16x2 LCD의 MAX 30102 심박수 모니터
    9. 홈 모니터
    10. DS1302 RTC가 있는 간단한 알람 시계