Friday, 30 March 2012 14:21

DINo NETSTARTER Pinout definition

Written by

 

 

Pinout definition

 

 

//============DINo NETSTARTER Pinout definition============//
//==============Relays================//
const int Relay1 = 8;
const int Relay2 = 7;
const int Relay3 = 6;
const int Relay4 = 5;
//==============Digital Inputs================//
const int In1 = A5;
const int In2 = A4;
const int In3 = A3;
const int In4 = A2;
//=============RS485 TX/RX control=====//
const int RS485_control = 3;
//Set this pin to high when you want to send data from RS485//
//=====================================//
void setup() {
  // initialize the serial communication:
  Serial.begin(9600);
  // initialize the Relay pin as an output:
  pinMode(Relay1, OUTPUT);  
  pinMode(Relay2, OUTPUT);    
  pinMode(Relay3, OUTPUT);    
  pinMode(Relay4, OUTPUT);     
 
  // initialize the input pins as an input:
  pinMode(In1, INPUT);    
  pinMode(In2, INPUT);
  pinMode(In3, INPUT);
  pinMode(In4, INPUT);
}

void loop(){
 
 if (digitalRead(In1)) digitalWrite(Relay1, HIGH);
 //Read the status of the input and turn on the Relay1 if its "1"
 else digitalWrite(Relay1, LOW); // Turn it off when it's "0"
 
 if (digitalRead(In2)) digitalWrite(Relay2, HIGH);
 //Read the status of the input and turn on the Relay2 if its "1"
 else digitalWrite(Relay2, LOW); // Turn it off when it's "0"
 
 if (digitalRead(In3)) digitalWrite(Relay3, HIGH);
 //Read the status of the input and turn on the Relay3 if its "1"
 else digitalWrite(Relay3, LOW); // Turn it off when it's "0"
 
 if (digitalRead(In4)) digitalWrite(Relay4, HIGH);
 //Read the status of the input and turn on the Relay4 if its "1"
 else digitalWrite(Relay4, LOW); // Turn it off when it's "0"

 Serial.println("DINo NETSTARTER TEST");
 delay(1000);
 
}

Wednesday, 28 March 2012 09:54

Receiving UDP data from Arduino

Written by

 

 

 

Receiving UDP data from Arduino

 

 

When any packet is received it is keep in burref.

 

So after function who read pakets we need to check is packet received is UDP.

 

Some information:

IP_PROTO_P = HEX 0x17 (DEC 23)

IP_PROTO_UDP_V =  HEX 0x11 (DEC 17)

 

We must check if in buffer possition 23 we have 17

 

Code:

 

    // read packet, handle ping and wait for a tcp packet:
    dat_p=es.ES_packetloop_icmp_tcp(buf,es.ES_enc28j60PacketReceive(BUFFER_SIZE, buf));
    
  
    if (buf[IP_PROTO_P]==IP_PROTO_UDP_V){   // ==     if (buf[23]==17)

     // We have UDP paket received

   }

 

 

 

Exsample UDP packet, buffer positions and values:

 

 

Buffer HEX DEC
position
0 cf 207
1 70 112
2 7c 124
3 e4 228
4 8a 138
5 b8 184
6 0 0
7 26 38
8 18 24
9 f9 249
10 71 113
11 a2 162
12 8 8
13 0 0
14 45 69
15 0 0
16 0 0
17 21 33
18 a6 166
19 eb 235
20 0 0
21 0 0
22 80 128
23 11 17
24 fe 254
25 12 18
26 c0 192
27 a8 168
28 0a 10
29 64 100
30 c0 192
31 a8 168
32 0a 10
33 19 25
34 30 48
35 39 57
36 30 48
37 39 57
38 0 0
39 0d 13
40 70 112
41 2d 45
42 31 49
43 32 50
44 33 51
45 34 52
46 35 53

 

 

 

 

 

 

 

 

Wednesday, 28 March 2012 09:19

Base 64 Encoder

Written by

 

 

Base 64 Encoder

 

 

 

 

 

 

Username
Password

                    

 

 

 

 

 

 

Wednesday, 28 March 2012 07:04

Wireshark network protocol loger analyzer

Written by

 

 

 

Wireshark network protocol loger analyzer

 

 

 

 

 

Download

www.wireshark.org

 

 

 

 

 

 

 

Tuesday, 27 March 2012 16:02

Understanding the UDP Protocol

Written by

 

 

 

 

Logged with Wireshark network protocol loger analyzer

http://info.kmtronic.com/wireshark-network-protocol-loger-analyzer.html

 

 

Example UDP packet send from PC to DINo 4 relay board

0000  cf 70 7c e4 8a b8 00 26  18 f9 71 a2 08 00 45 00   .p|....& ..q...E.
0010  00 21 a6 eb 00 00 80 11  fe 12 c0 a8 0a 64 c0 a8   .!...... .....d..
0020  0a 19 30 39 30 39 00 0d  70 2d 31 32 33 34 35      ..0909.. p-12345

 

 

 

DINo MAC address (destination)

HEX: cf 70 7c e4 8a b8

PC MAC address (source)

HEX: 00 26 18 f9 71 a2

 

DINo IP address (destination)

HEX: c0 a8 0a 19 (DEC:192.168.10.25)

PC IP address (source)

HEX: c0 a8 0a 64 (DEC:192.168.10.100)

 

DINo port (destination)

HEX: 30 39 (DEC:12345)

PC port (source)

HEX: 30 39 (DEC:12345)

 

Protocol identificator (UDP)

HEX: 11 (DEC:17)

 

Length

HEX: 00 0d (DEC:13)

 

Data

HEX: 31 32 33 34 35 (DEC:49 50 51 52 53, ASCII: 1 2 3 4 5)

 

 

 

Serial Watcher

 

Serial Watcher is a small piece of program from PCRemote Control that can watch the data

flow through any of your serial ports live and save the flowing data.

It’s main use is during the testing of serial data receiver devices.

 

 

 

 

 

Download

https://www.info.kmtronic.com/software/SerialWatcher/SerialWatcher.zip

 

Change USB Virtual COM port number

https://www.info.kmtronic.com/change-usb-relay-comport-number.html

 

 

 

 

Tuesday, 27 March 2012 10:52

Read ENC28J60 Revision from Arduino

Written by

 

Quick way to check is

ENC28J60 Ethernet shield is present

 

 

For Ethernet shields with ENC28J60 we using this sketch for test:

 

----------------------------------------------------------------------------------------------------------

#include "EtherShield.h"

static uint8_t mymac[6] = {0x54,0x55,0x58,0x10,0x00,0x25}; 

EtherShield es=EtherShield();

void setup(){

  Serial.begin(9600);
  es.ES_enc28j60Init(mymac);
  
}

void loop(){
    Serial.println(es.ES_enc28j60Revision(),HEX);
    delay(500);
}

----------------------------------------------------------------------------------------------------------

 

Upload to Arduino and open Serial Monitor.

 

If it return zero, that would be an indication of a missing or failed shield (chip).

Our ENC28J60 chip when is connected return “6".

 

 

 

 

 

 

 

 

DINo Internet/Ethernet Relay I/O board

 

Web Server control example

 

Android MID tablet PC
 



 

 

Download and unzip in your Arduino libraries folder "ENC28J60 EtherShield Library"s

http://www.info.kmtronic.com/software/DINo/EtherShield_Arduino_v2.zip
 

 

 

Download and unzip KMtronic DINo Web Server example:

http://www.info.kmtronic.com/software/DINo/WebServer_exsample/KMtronic_DINo_Web_Server_Example.zip

 

Connect board to USB, modify if necessary MAC and IP address and upload to board


Connect to your Router or PC Network Card and check for PING

 


 

 

Demo username and password:

username: admin

password: admin

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

DINo Internet/Ethernet Relay I/O board

 

Web Server control example



 

 

Download and unzip in your Arduino libraries folder "ENC28J60 EtherShield Library"s

http://www.info.kmtronic.com/software/DINo/EtherShield_Arduino_v2.zip
 

 

 

Download and unzip KMtronic DINo Web Server example:

http://www.info.kmtronic.com/software/DINo/WebServer_exsample/KMtronic_DINo_Web_Server_Example.zip

 

Connect board to USB, modify if necessary MAC and IP address and upload to board


Connect to your Router or PC Network Card and check for PING

 


 

 

Demo username and password:

username: admin

password: admin

 

 

 

 

 

 

 

 
 

DINo Internet/Ethernet Relay I/O board

 

UDP control example



 

Download and unzip in your Arduino libraries folder "ENC28J60 EtherShield UDP Library"s

http://www.info.kmtronic.com/software/DINo/EtherShield_Arduino_v2.zip
 

 

 

Download and unzip "KMtronic_UDP_Example.ino"

http://www.info.kmtronic.com/software/DINo/UDP_Example/KMtronic_UDP_Example.zip

 

Connect board to USB, modify if necessary MAC and IP address and upload to board


Connect to your Router or PC Network Card and check for PING

 


 

UDP Commands:

 

FF 00 00 - Status Read command

FF 01 00 - Relay 1 OFF command
FF 01 01 - Relay 1 ON command
FF 02 00 - Relay 2 OFF command
FF 02 01 - Relay 2 ON command
FF 03 00 - Relay 3 OFF command
FF 03 01 - Relay 3 ON command
FF 04 00 - Relay 4 OFF command
FF 04 01 - Relay 4 ON command

 



UDP Test Software example including source code (C#)

KMTronic DINo 4 Relay UDP Test Software.zip
KMTronic DINo 4 Relay UDP Test Software Source Code.zip



Download, unzip and run software

 


Click on Open button and send FF0000 (Status request command)



If everything is okay you will receive IP DINo board and Status

 

 

UDP example code

--------------------------------------------------------------

           

  #include "EtherShield.h"

            uint8_t mymac[6] = {0xCF,0x70,0x7C,0xE4,0x8A,0xB8};
            uint8_t myip[4] = {192,168,1,25};
            uint16_t MYWWWPORT = 80;

            #define BUFFER_SIZE 750
            static uint8_t buf[BUFFER_SIZE+1];

            char reply[]="00000000";

            EtherShield es=EtherShield();

            uint16_t plen, dat_p;

            ///----------------------------------------------------------
            void setup(){

            Setup_Pins();
            es.ES_enc28j60Init(mymac);
            es.ES_init_ip_arp_udp_tcp(mymac,myip, MYWWWPORT);

            } // end setup


            ///----------------------------------------------------------
            void loop(){

            // read packet, handle ping and wait for a tcp packet:
            dat_p=es.ES_packetloop_icmp_tcp(buf,es.ES_enc28j60PacketReceive(BUFFER_SIZE, buf));

            if (buf[IP_PROTO_P]==IP_PROTO_UDP_V){
            Relay_Control();
            Status_Reply();
            es.ES_make_udp_reply_from_request(buf,reply,8,12345);
            buf[IP_PROTO_P]=0;
            }

            } // end loop


            ///----------------------------------------------------------
            void Setup_Pins(){

            pinMode(5, OUTPUT); digitalWrite(5, 0);
            pinMode(6, OUTPUT); digitalWrite(6, 0);
            pinMode(7, OUTPUT); digitalWrite(7, 0);
            pinMode(8, OUTPUT); digitalWrite(8, 0);

            } // end Setup_Pins


            ///----------------------------------------------------------
            void Relay_Control(){

              char* recv = (char*)buf + 42;

            if (strncmp(recv, "FF0100", 6) == 0) digitalWrite(8, 0);
            else if (strncmp(recv, "FF0101", 6) == 0) digitalWrite(8, 1);
            else if (strncmp(recv, "FF0200", 6) == 0) digitalWrite(7, 0);
            else if (strncmp(recv, "FF0201", 6) == 0) digitalWrite(7, 1);
            else if (strncmp(recv, "FF0300", 6) == 0) digitalWrite(6, 0);
            else if (strncmp(recv, "FF0301", 6) == 0) digitalWrite(6, 1);
            else if (strncmp(recv, "FF0400", 6) == 0) digitalWrite(5, 0);
            else if (strncmp(recv, "FF0401", 6) == 0) digitalWrite(5, 1);
            } // end Relay_Control


            ///----------------------------------------------------------
            void Status_Reply(){

              // Inputs
            reply[0] = digitalRead(A2) ? 0x31 : 0x30;
            reply[1] = digitalRead(A3) ? 0x31 : 0x30;
            reply[2] = digitalRead(A4) ? 0x31 : 0x30;
            reply[3] = digitalRead(A5) ? 0x31 : 0x30;

            // Outputs
            reply[4] = digitalRead(5) ? 0x31 : 0x30;
            reply[5] = digitalRead(6) ? 0x31 : 0x30;
            reply[6] = digitalRead(7) ? 0x31 : 0x30;
            reply[7] = digitalRead(8) ? 0x31 : 0x30;

            } // end Status_Reply
            ///----------------------------------------------------------


 
--------------------------------------------------------------

 

 

 

back to Arduino DINo projects

 

Page 29 of 33