Pengetahuan Dasar Membuat Grafik Real Time VB.Net Data Serial Port Arduino

Pengetahuan Dasar Membuat Grafik Real Time Data Serial Port

Aplikasi yg dibutuhkan
VB.Net
Codevision atau Arduino

ARDUINO_MODUL

Hardware yg dibutuhkan
Usb to Serial
Mikrocontroller board AVR atau Arduino board

Tahapan Pembuatan aplikasi VB.Net

-Buka project baru

-pada form tambahkan komponen Chart,timer, textbox,listbox  dan button

-Atur tata letak komponen chart,textbox,buton pada form

graph

Kode ProgramVB.Net 2010
Imports System
Imports System.IO.Ports
Imports System.Threading
Imports System.Threading.Thread
Imports System.Windows.Forms.DataVisualization.Charting
Public Class Form1
Dim data As String
Dim frek As String
Dim RXArray(2047) As Char
Dim RXCnt As Integer ‘
Dim time As String
Dim frekwensi As String
Dim engChart As New Series

Dim WithEvents COMPort As New SerialPort

Private Sub ComboBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboBox1.SelectedIndexChanged

End Sub
Private Sub ClosePort()
If COMPort.IsOpen Then
COMPort.Close()
End If
End Sub

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
If COMPort.IsOpen Then
COMPort.Close()
Label3.Text = “koneksi berhasil ditutup”

End If
End Sub

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
For Each COMString As String In My.Computer.Ports.SerialPortNames
ComboBox1.Items.Add(COMString)
Next
Chart1.Series.Clear()
Chart1.Titles.Add(“data serial real time”)
engChart.Name = “analog in”
engChart.ChartType = SeriesChartType.Line
Chart1.Series.Add(engChart)
Chart1.ForeColor = Color.Cyan
ComboBox1.Focus()
RXCnt = 0

End Sub

‘=================================================================

‘=================================================================
Private Sub Receiver(ByVal sender As Object, ByVal e As SerialDataReceivedEventArgs) Handles COMPort.DataReceived
Dim RXByte As Byte

Do
RXByte = COMPort.ReadByte
RXArray(RXCnt) = Chr(RXByte)

If Chr(RXByte) = Chr(13) Then
Me.Invoke(New MethodInvoker(AddressOf Display))
RXCnt = 0
End If
RXCnt = RXCnt + 1

Loop Until (COMPort.BytesToRead = 0)
End Sub

Private Sub Display()
data = (New String(RXArray, 1, RXCnt))

TextBox1.Text = data

DoUpdate()
End Sub

Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
time = TimeOfDay
End Sub
Public Sub DoUpdate()

Try
engChart.Points.AddXY(time, data)
Catch ex As Exception

Label3.Text = ex.Message
Finally

End Try
End Sub

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
If COMPort.IsOpen Then
COMPort.RtsEnable = False
COMPort.DtrEnable = False
ClosePort()

Application.DoEvents()
Sleep(200)
End If
COMPort.PortName = ComboBox1.Text
COMPort.BaudRate = 9600
COMPort.WriteTimeout = 2000
Try
COMPort.Open()
Catch ex As Exception
MsgBox(ex.Message)
End Try

If COMPort.IsOpen Then
COMPort.RtsEnable = True
COMPort.DtrEnable = True

Label3.Text = “koneksi berhasil dibuka”
End If
End Sub
End Class

kode program Arduino
void setup() {
Serial.begin(9600);
}
void loop() {
// baca  analog pin 0:
int sensorValue = analogRead(A0);
// kirim hasil ke serial
Serial.println(sensorValue);
delay(1000);
}

Kode progrtam AVR codevision

/*****************************************************
Date : 13/08/2016
Chip type : ATmega16
Clock frequency : 11,059200 MHz
kontinyu kirim data :50987<0D>60734<0D>dst..
*****************************************************/

#include <mega16.h>
#include <stdio.h>
#include <delay.h>

unsigned int i;
void main(void)
{
// 8 Data, 1 Stop, No Parity
// Baud rate: 9600
UCSRA=0x00;
UCSRB=0x08;
UCSRC=0x86;
UBRRH=0x00;
UBRRL=0x47;

while (1)
{
i++;
putchar(i/1000 %10 + 0x30);
putchar( i/100 %10 + 0x30);
putchar(i/10 %10 + 0x30);
putchar(‘.’);
putchar(i % 10 + 0x30);
putchar(‘\r’) ;
delay_ms(600);

};
}

promoarduinovbnet

About pccontrol

Berisi Tutorial Menggunakan PC untuk mengontrol Peralatan dengan cara mudah & praktis.

Posted on 25/08/2016, in Arduino, AVR, Daftar isi, Visual Basic . Net. Bookmark the permalink. Leave a comment.

Komentar ,Saran atau Pertanyaan

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: