Components and supplies
LCD 16x2
Jumper wires (generic)
Arduino Leonardo
Project description
Code
C# Application
csharp
1using System; 2using System.Collections.Generic; 3using System.ComponentModel; 4using System.Data; 5using System.Drawing; 6using System.Linq; 7using System.Text; 8using System.Threading.Tasks; 9using System.Windows.Forms; 10using System.IO.Ports; 11using OpenHardwareMonitor.Hardware; 12 13namespace Arduino_Controll 14{ 15 public partial class Form1 : Form 16 { 17 static string data; 18 Computer c = new Computer() 19 { 20 GPUEnabled = true, 21 CPUEnabled = true 22 }; 23 24 float value1, value2; 25 26 private SerialPort port = new SerialPort(); 27 public Form1() 28 { 29 InitializeComponent(); 30 Init(); 31 } 32 33 34 private void Init() 35 { 36 try 37 { 38 notifyIcon1.Visible = false; 39 port.Parity = Parity.None; 40 port.StopBits = StopBits.One; 41 port.DataBits = 8; 42 port.Handshake = Handshake.None; 43 port.RtsEnable = true; 44 string[] ports = SerialPort.GetPortNames(); 45 foreach (string port in ports) 46 { 47 comboBox1.Items.Add(port); 48 } 49 port.BaudRate = 9600; 50 51 } 52 catch (Exception ex) 53 { 54 MessageBox.Show(ex.Message); 55 } 56 } 57 58 59 private void button3_Click(object sender, EventArgs e) 60 { 61 try 62 { 63 port.Write("DIS*"); 64 port.Close(); 65 } 66 catch (Exception ex) 67 { 68 MessageBox.Show(ex.Message); 69 } 70 label2.Text = "Disconnected"; 71 timer1.Enabled = false; 72 toolStripStatusLabel1.Text = "Connect to Arduino..."; 73 data = ""; 74 } 75 76 77 private void button5_Click(object sender, EventArgs e) 78 { 79 try 80 { 81 if (!port.IsOpen) 82 { 83 port.PortName = comboBox1.Text; 84 port.Open(); 85 timer1.Interval = Convert.ToInt32(comboBox2.Text); 86 timer1.Enabled = true; 87 toolStripStatusLabel1.Text = "Sending data..."; 88 label2.Text = "Connected"; 89 } 90 91 } 92 catch (Exception ex) 93 { 94 MessageBox.Show(ex.Message); 95 } 96 } 97 98 99 private void timer1_Tick(object sender, EventArgs e) 100 { 101 Status(); 102 } 103 104 private void Form1_Load(object sender, EventArgs e) 105 { 106 c.Open(); 107 } 108 109 private void Form1_Resize(object sender, EventArgs e) 110 { 111 if (FormWindowState.Minimized == this.WindowState) 112 { 113 notifyIcon1.Visible = true; 114 try 115 { 116 notifyIcon1.ShowBalloonTip(500, "Arduino", toolStripStatusLabel1.Text, ToolTipIcon.Info); 117 118 }catch(Exception ex) 119 { 120 121 } 122 this.Hide(); 123 } 124 125 126 } 127 128 129 private void notifyIcon1_DoubleClick(object sender, EventArgs e) 130 { 131 132 this.Show(); 133 this.WindowState = FormWindowState.Normal; 134 notifyIcon1.Visible = false; 135 } 136 137 138 private void Status() 139 { 140 foreach (var hardwadre in c.Hardware) 141 { 142 143 if (hardwadre.HardwareType == HardwareType.GpuNvidia) 144 { 145 hardwadre.Update(); 146 foreach (var sensor in hardwadre.Sensors) 147 if (sensor.SensorType == SensorType.Temperature) 148 { 149 150 value1 = sensor.Value.GetValueOrDefault(); 151 } 152 153 } 154 155 if (hardwadre.HardwareType == HardwareType.CPU) 156 { 157 hardwadre.Update(); 158 foreach (var sensor in hardwadre.Sensors) 159 if (sensor.SensorType == SensorType.Temperature) 160 { 161 value2 = sensor.Value.GetValueOrDefault(); 162 163 } 164 165 } 166 167 } 168 try 169 { 170 port.Write(value1 + "*" + value2 + "#"); 171 }catch(Exception ex) 172 { 173 timer1.Stop(); 174 MessageBox.Show(ex.Message); 175 toolStripStatusLabel1.Text = "Arduino's not responding..."; 176 } 177 } 178 179 } 180} 181 182 183 184
Arduino Code
arduino
1#include <Wire.h> 2#include <LiquidCrystal_I2C.h> 3 4LiquidCrystal_I2C 5 lcd(0x3F,16,2); 6String inData; 7 8void setup() { 9 Serial.begin(9600); 10 11 lcd.init(); 12 lcd.backlight(); 13} 14 15void loop() { 16 17 while 18 (Serial.available() > 0) 19 { 20 char recieved = Serial.read(); 21 22 inData += recieved; 23 24 if (recieved == '*') 25 { 26 27 inData.remove(inData.length() - 1, 1); 28 lcd.setCursor(0,0); 29 30 lcd.print("GPU Temp.: " + inData + char(223)+"C "); 31 inData 32 = ""; 33 34 if(inData == "DIS") 35 { 36 37 lcd.clear(); 38 lcd.setCursor(0,0); 39 lcd.print("Disconnected!"); 40 41 } 42 } 43 44 if (recieved == '#') 45 { 46 47 inData.remove(inData.length() - 1, 1); 48 lcd.setCursor(0,1); 49 50 lcd.print("CPU Temp.: " + inData + char(223)+"C "); 51 inData 52 = ""; 53 } 54 } 55}
C# Application
csharp
1using System; 2using System.Collections.Generic; 3using System.ComponentModel; 4using System.Data; 5using System.Drawing; 6using System.Linq; 7using System.Text; 8using System.Threading.Tasks; 9using System.Windows.Forms; 10using System.IO.Ports; 11using OpenHardwareMonitor.Hardware; 12 13namespace Arduino_Controll 14{ 15 public partial class Form1 : Form 16 { 17 static string data; 18 Computer c = new Computer() 19 { 20 GPUEnabled = true, 21 CPUEnabled = true 22 }; 23 24 float value1, value2; 25 26 private SerialPort port = new SerialPort(); 27 public Form1() 28 { 29 InitializeComponent(); 30 Init(); 31 } 32 33 34 private void Init() 35 { 36 try 37 { 38 notifyIcon1.Visible = false; 39 port.Parity = Parity.None; 40 port.StopBits = StopBits.One; 41 port.DataBits = 8; 42 port.Handshake = Handshake.None; 43 port.RtsEnable = true; 44 string[] ports = SerialPort.GetPortNames(); 45 foreach (string port in ports) 46 { 47 comboBox1.Items.Add(port); 48 } 49 port.BaudRate = 9600; 50 51 } 52 catch (Exception ex) 53 { 54 MessageBox.Show(ex.Message); 55 } 56 } 57 58 59 private void button3_Click(object sender, EventArgs e) 60 { 61 try 62 { 63 port.Write("DIS*"); 64 port.Close(); 65 } 66 catch (Exception ex) 67 { 68 MessageBox.Show(ex.Message); 69 } 70 label2.Text = "Disconnected"; 71 timer1.Enabled = false; 72 toolStripStatusLabel1.Text = "Connect to Arduino..."; 73 data = ""; 74 } 75 76 77 private void button5_Click(object sender, EventArgs e) 78 { 79 try 80 { 81 if (!port.IsOpen) 82 { 83 port.PortName = comboBox1.Text; 84 port.Open(); 85 timer1.Interval = Convert.ToInt32(comboBox2.Text); 86 timer1.Enabled = true; 87 toolStripStatusLabel1.Text = "Sending data..."; 88 label2.Text = "Connected"; 89 } 90 91 } 92 catch (Exception ex) 93 { 94 MessageBox.Show(ex.Message); 95 } 96 } 97 98 99 private void timer1_Tick(object sender, EventArgs e) 100 { 101 Status(); 102 } 103 104 private void Form1_Load(object sender, EventArgs e) 105 { 106 c.Open(); 107 } 108 109 private void Form1_Resize(object sender, EventArgs e) 110 { 111 if (FormWindowState.Minimized == this.WindowState) 112 { 113 notifyIcon1.Visible = true; 114 try 115 { 116 notifyIcon1.ShowBalloonTip(500, "Arduino", toolStripStatusLabel1.Text, ToolTipIcon.Info); 117 118 }catch(Exception ex) 119 { 120 121 } 122 this.Hide(); 123 } 124 125 126 } 127 128 129 private void notifyIcon1_DoubleClick(object sender, EventArgs e) 130 { 131 132 this.Show(); 133 this.WindowState = FormWindowState.Normal; 134 notifyIcon1.Visible = false; 135 } 136 137 138 private void Status() 139 { 140 foreach (var hardwadre in c.Hardware) 141 { 142 143 if (hardwadre.HardwareType == HardwareType.GpuNvidia) 144 { 145 hardwadre.Update(); 146 foreach (var sensor in hardwadre.Sensors) 147 if (sensor.SensorType == SensorType.Temperature) 148 { 149 150 value1 = sensor.Value.GetValueOrDefault(); 151 } 152 153 } 154 155 if (hardwadre.HardwareType == HardwareType.CPU) 156 { 157 hardwadre.Update(); 158 foreach (var sensor in hardwadre.Sensors) 159 if (sensor.SensorType == SensorType.Temperature) 160 { 161 value2 = sensor.Value.GetValueOrDefault(); 162 163 } 164 165 } 166 167 } 168 try 169 { 170 port.Write(value1 + "*" + value2 + "#"); 171 }catch(Exception ex) 172 { 173 timer1.Stop(); 174 MessageBox.Show(ex.Message); 175 toolStripStatusLabel1.Text = "Arduino's not responding..."; 176 } 177 } 178 179 } 180} 181 182 183 184
Arduino Code
arduino
1#include <Wire.h> 2#include <LiquidCrystal_I2C.h> 3 4LiquidCrystal_I2C lcd(0x3F,16,2); 5String inData; 6 7void setup() { 8 Serial.begin(9600); 9 lcd.init(); 10 lcd.backlight(); 11} 12 13void loop() { 14 15 while (Serial.available() > 0) 16 { 17 char recieved = Serial.read(); 18 inData += recieved; 19 20 if (recieved == '*') 21 { 22 inData.remove(inData.length() - 1, 1); 23 lcd.setCursor(0,0); 24 lcd.print("GPU Temp.: " + inData + char(223)+"C "); 25 inData = ""; 26 27 if(inData == "DIS") 28 { 29 lcd.clear(); 30 lcd.setCursor(0,0); 31 lcd.print("Disconnected!"); 32 } 33 } 34 35 if (recieved == '#') 36 { 37 inData.remove(inData.length() - 1, 1); 38 lcd.setCursor(0,1); 39 lcd.print("CPU Temp.: " + inData + char(223)+"C "); 40 inData = ""; 41 } 42 } 43}
Downloadable files
Schematics
Schematics
Comments
Only logged in users can leave comments
zakrzu
0 Followers
•0 Projects
41
0