Translate

Arduino Ethernet TCP-IP Modul ENC28J60 Interface VB 6.0

Arduino Ethernet TCP-IP Modul ENC28J60 Interface VB 6.0


         Pada kesempatan kali ini saya akan menjelaskan mengenai bagaimana cara mengakses modul ethernet ENC28J60 dengan menggunakan arduino mega.  koneksi dari modul ENC28J60 ke arduino menggunakan pin SPI yaitu mosi miso sck vcc gnd. menurut petunjuk vcc pada modul ENC28J60 yaitu 3.3 volt bukan 5v. untuk lebih jelasnya berikut adalah komponen dan programnya.




a. Arduino Mega




b. Modul ENC28J60






c. Program Arduino Tanpa Interface VB 6.0

#include <SPI.h>
#include <UIPEthernet.h>

byte mac[] = {
0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED
};
IPAddress ip(192, 168, 1, 177);

EthernetServer server(80);

void setup() {
Serial.begin(9600);
while (!Serial) {
;
}

Ethernet.begin(mac, ip);
server.begin();
Serial.print("server is at ");
Serial.println(Ethernet.localIP());
}


void loop() {
EthernetClient client = server.available();
if (client) {
Serial.println("new client");
boolean currentLineIsBlank = true;
while (client.connected()) {
if (client.available()) {
char c = client.read();
Serial.write(c);
if (c == '\n' && currentLineIsBlank) {
client.println("HTTP/1.1 200 OK");
client.println("Content-Type: text/html");
client.println("Connection: close");
client.println("Refresh: 1");
client.println();
client.println("<!DOCTYPE HTML>");
client.println("<html>");

int dataadc1 = analogRead(A0);
int dataadc2 = analogRead(A1);
int dataadc3 = analogRead(A2);

client.print("ADC1= ");
client.print(dataadc1);
client.println("<br />");

client.print("ADC2= ");
client.print(dataadc2);
client.println("<br />");

client.print("ADC3= ");
client.print(dataadc3);
client.println("<br />");

client.println("</html>");
break;
}
if (c == '\n') {
currentLineIsBlank = true;
} else if (c != '\r') {
currentLineIsBlank = false;
}
}
}
delay(1);
client.stop();
Serial.println("client disconnected");
}
}





d. Program Arduino Kirim ke Interface VB 6.0

#include <SPI.h>
#include <UIPEthernet.h>

byte mac[] = {
0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED
};
IPAddress ip(192, 168, 1, 177);
IPAddress gateway(192, 168, 1, 1);
IPAddress subnet(255, 255, 255, 0);

EthernetServer server(80);

String readString;
char mm;

void setup() {
pinMode(13,OUTPUT);
Serial.begin(9600);
while (!Serial) {
;
}

Ethernet.begin(mac, ip);
server.begin();
Serial.print("server is at ");
Serial.println(Ethernet.localIP());
}


void loop() {
EthernetClient client = server.available();
if (client) {
Serial.println("new client");
boolean currentLineIsBlank = true;
while (client.connected()) {


if (client.available()) {
mm = client.read();
char c = client.read();
Serial.write(c);
if (c == '\n' && currentLineIsBlank) {
client.println("HTTP/1.1 200 OK");
client.println("Content-Type: text/html");
client.println("Connection: close");
client.println("Refresh: 1");
client.println();
client.println("<!DOCTYPE HTML>");
client.println("<html>");

int dataadc1 = analogRead(A0);
int dataadc2 = analogRead(A1);
int dataadc3 = analogRead(A2);

client.print("ADC1= ");
client.print(dataadc1);
client.println("<br />");

client.print("ADC2= ");
client.print(dataadc2);
client.println("<br />");

client.print("ADC3= ");
client.print(dataadc3);
client.println("<br />");

client.println("</html>");

server.println(dataadc1);
server.println(dataadc2);
server.println(dataadc3);

break;
}
if (c == '\n') {
currentLineIsBlank = true;
} else if (c != '\r') {
currentLineIsBlank = false;
}
}





}
delay(1);
client.stop();
Serial.println("client disconnected");
}

          if(mm == 'A')
          {
             digitalWrite(13, HIGH); 
          }
       
          if(mm == 'B')
          {
             digitalWrite(13, LOW);
          }
      
          if(readString.indexOf("?lightof3") >0)
          {
             digitalWrite(13, HIGH); 
          }
       
          if(readString.indexOf("?lightof4") >0)
          {
             digitalWrite(13, LOW);
          }


}





e. Program Interface VB 6.0



Option Explicit
Dim sHari As String      'Deklarasi variabel global, karena digunakan
Dim aHari                'oleh lebih dari satu prosedur
Dim jam, menit, detik
Dim iClientId As Integer

Private Sub cmd_Connect_Click()

On Error GoTo a

If Winsock.State <> sckClosed Then Winsock.Close
Winsock.RemoteHost = Text_IP
Winsock.RemotePort = Text_PORT
Winsock.Connect

sckAccept.RemoteHost = Text_IP
sckAccept.RemotePort = Text_PORT
sckAccept.Connect

cmd_Connect.Enabled = False
cmd_Disconnect.Enabled = True

Exit Sub
a:
MsgBox "error: " & Err.Description, vbCritical, "Error"

End Sub

Private Sub cmd_Disconnect_Click()
Winsock.Close
sckAccept.Close
MsgBox ("Koneksi dengan Server selesai")
cmd_Connect.Enabled = True
cmd_Disconnect.Enabled = False
End Sub


Private Sub Command_Clear_Click()
Text1.Text = ""
End Sub



Private Sub Command1_Click()
Unload Me
End Sub

Private Sub Command2_Click()
' Get the client id from the Combobox
   
    'iClientId = Split(Text_IP, " ")(1)
   
    ' Send data to client
    Winsock.SendData Text2.Text
   
    ' clear textbox
    'txtSendData.Text = ""
   
End Sub

Private Sub Command3_Click()
' Get the client id from the Combobox
   
    'iClientId = Split(Text_IP, " ")(1)
   
    ' Send data to client
    Winsock.SendData Text3.Text
   
    ' clear textbox
    'txtSendData.Text = ""
   
End Sub

Private Sub Form_Load()
aHari = Array("Minggu", "Senin", "Selasa", "Rabu", "Kamis", "Jumat", "Sabtu")
               
Timer1.Enabled = True

cmd_Connect.Enabled = True
cmd_Disconnect.Enabled = False




End Sub


Private Sub Timer1_Timer()
sHari = aHari(Abs(Weekday(Date) - 1))
lblTanggal.Caption = "" & sHari & "," & Format(Date, "dd mmmm yyyy")
LblWaktu.Caption = Format(Time, "hh:mm:ss")


End Sub

Private Sub Winsock_Connect()
MsgBox ("terkoneksi dengan server")
End Sub

Private Sub Winsock_ConnectionRequest(ByVal requestID As Long)
Winsock.Accept requestID
End Sub

Private Sub sckAccept_ConnectionRequest(ByVal requestID As Long)
sckAccept.Accept requestID
End Sub

Private Sub Winsock_DataArrival(ByVal bytesTotal As Long)

Dim buffer As String
Dim temp As String
Dim pisah() As String
Dim i As Integer

Dim data As String
data = ""
Winsock.GetData data, vbString
Text1.Text = Text1.Text & data & vbCr

buffer = data

pisah = Split(buffer, Chr$(13))

On Error Resume Next
If buffer <> " " Then
With Text5
    .SelStart = Len(.Text)
    .SelText = buffer
End With
For i = 0 To 2
    If 0 < 3 Then
        Text6(i).Text = CStr(pisah(i))
        End If
        Next i
    Else
    buffer = " "
    End If

End Sub






f. VIDEO HASILNYA








No comments:

Post a Comment