---
title: "Arduino Due Ethernet Shield W5100 Telnet server example in Microchip Studio"
url: "https://maker.wiznet.io/scarlet/projects/arduino-due-ethernet-shield-w5100-telnet-server-example-in-microchip-studio/"
markdown_url: "https://maker.wiznet.io/scarlet/projects/arduino-due-ethernet-shield-w5100-telnet-server-example-in-microchip-studio/md"
type: "UCC: User Created Content"
author: "이경진"
author_url: "https://www.youtube.com/watch?v=ZKRroDsjNCE"
editor: "WIZnet"
editor_url: "https://maker.wiznet.io/"
original_author: "이경진"
original_url: "https://www.youtube.com/watch?v=ZKRroDsjNCE"
published: "2023-11-02"
language: "en"
likes: 0
views: 331
comments: 0
source: "WIZnet Makers (https://maker.wiznet.io/)"
---

# Arduino Due Ethernet Shield W5100 Telnet server example in Microchip Studio

> We are back with the ethernet stuff, this time with WizNet W5100 and Arduino Due (SAM3X8E). In this example we will setup a Telnet server to connet with putty f

Original author: 이경진 (source: https://www.youtube.com/watch?v=ZKRroDsjNCE)

## Article

(6) Arduino Due Ethernet Shield W5100 Telnet server example in Microchip Studio - YouTube
https://www.youtube.com/watch?v=ZKRroDsjNCE

Transcript:
(00:00) a while ago we've been doing a HTTP server application and as a follow-up I got here together with the r NOA the EET shield with wisnet W 5,00 I see and uh we will create a basic tet server so we can connect with using party uh through our computer so let me show you how it works okay so first of all I'm clicking reset and let's open the port and after the insation uh we've got the IP of the board right here so we can just copy it and connect to the board using PTY so uh we want to select tet with the port
(00:56) 23 and let's paste the address so let's open it up and we see right here uh the address of the computer that connected to the board so now let's try and send something something like this so we've got the input right here so now we we will send something back to the puty console okay and we got it here okay so now let's take a look at the code okay so we are in the main file of the project and uh at the beginning we've got a function to read data from the USB port and this is a callback uh that is defined in the
(01:55) config file of the USB so as we go down we've got right here a uncommented definition of the Callback and I use uh this function which is this one so how it works is uh that uh we get data from the buffer and we write it uh by appending it to the top of the buffer so get blank and if uh it is uh in the range of the buffer it's a little bit of free space right here because we check it if it's 200 or less and uh if it is uh we simply append the data to the buffer so we get the data on
(03:00) the top of the buffer uh and uh after this we increment the length of the data that we got here uh next on we got the functions for the SPI to communicate with the Ethernet shield a function to print strings that are less than 50 size and here we got a function that is used to write uh packets uh of data to the etherate shield and uh as we see in the data sheet of the AC uh we have to start each uh write or read operation uh with a op code so for writing is this for reading is something like this uh and after the op code we
(03:58) got uh two bytes of of address to the registers of the IC and after this we got one bite of data to either to write or read uh so it looks like this so if we got the writing we send first the op code for it then the address and the data and after this we simp uh select the chip select pin into high and before it uh it selects the I see by going L and for reading uh we got the second top code and uh by the data bite we just read data from the IC and I put right here a dummy uh data to
(05:04) transfer you can use also zero for this purpose it works uh both ways and uh after that the return here from the function is just data that I got from the uh register of the IC or if I was doing a right there's one returning okay so now next on we've got uh the address of the Gateway so for example the address of your router that you are uh connected to so you send the data first there and from there uh it is sent to other devices so in my case this one next on the mask of the ethernet you are using so the addresses
(06:09) uh can change in here only and next on the Mac address for your aate Shield you can uh change it into some other addresses it doesn't really matter uh as long as they don't collide with other addresses that you got in your uh Network okay and uh right here we've got the address for your Ethernet shield so the address that you want to connect to using partty for example uh right here we got addresses uh for Destination so as we use the socket of the internet Shield as say a server uh those fields will be updated
(07:04) as soon as we got a connection established between the Ethernet shield and uh the computer uh right here we got uh a port that we will use for the socket of the Ethernet shield so this is the default for the tnet next time we got a function to write those values to the Ethernet shield so those those are uh the values for each socket in total of four sockets uh right here I select the default uh memory for each socket so each socket has uh something around uh 2,000 uh bytes uh of of uh text and receive memory next on I just read the values
(08:07) that I already wrote here to check if uh they are cor correctly uh set so there are no errors and whatsoever okay next on WE configure the socket zero so we run it in the TCP mode and and we write the input Port I mean the source port and the output Port uh as the 23 for taet and this is some default stuff and right here we got a function to send messages uh to the devices that are connected uh right now I uh copy the USB buffer to something like a temporary buffer that is of length of 100 bytes you can increase it if you
(09:09) want uh but 100 is uh pretty much okay for sending uh nor normal text messages uh next on first we have to read how much we can uh print data into the Ethernet shield so if the data that we want to send will fit into the registers of the E Shield if it does it does the code right here but if it doesn't uh you will have to try again so as soon as the Ethernet shield will send the data that it has in the registers the free space will be available so you will be able to send new data so first of all you have to read the
(10:05) address uh that you will start writing data and uh you have to after the read do a end operation with the mask so in case of 2,000 bytes of memory for the socket the mask is this so it correspond corresponds to the 2,000 value to be exact it's 2 48 bites in this case minus one uh and uh after this we have to check if there has been an uh data overflow so uh maybe let you let me show you at uh memory of the device how it works okay so this is our uh
(11:14) setup so in this case it's the text uh addresses so at the beginning we have this address and we go up and uh right here uh a over flow can be expected so if as we got the data right right here uh they will not fit here but instead they will be written right here so at the beginning and uh we have to check for this and right here we check it so if the address uh that we will be writing plus the length of the data that we want to write is higher than the address right here so if it is we have
(12:19) to get this data from the top first written and then we go back to the Base address right here and we write from here to the end of the data so the flag here is for checking what we want to write so if there's no overflow then we just uh write the data at the pointer that we got earlier here and if there was a overflow then first we write the data from the top and then we write the data at the bottom of the buffer just like so and after this we have to increase the uh pointer to the data uh with the length of the data that we have
(13:20) written so if this was something like uh uh something like around here you don't have to worry to go to right here and add the data you just simply while being here add the data so uh it will point above the limit so the chip will know that it has to switch from here into here okay so as it is written correctly it returns zero if it's not it returns one and we got the same thing uh right here for the receiving uh but here we uh check uh if we got data incoming so something in the buffer at the
(14:25) registers so if the length that is readed here is uh not equal to zero then we got data so we uh get the pointer to the data just like above we have the difference of the Base address here so let's take a look so uh this is our setup and uh those are the addresses for the receiving so this is the base and this is the limit and it works uh exactly like in the texting we also have to check for the over overflow and the the one difference here is that we want to zero the received uh length in the register so this is the
(15:24) difference and the return is the length that we write I mean read if not it returns zero and next on we got some basic commands for the socket zero only the socket zero here is used and right here I got a function to read and print the address of the device that is connected so after reconnect we check what we have there the IP address okay and uh we are at the main function so the basic stuff for the board so also use the SPI Z and the pins for the uh chip selects so on the EET Shield we got the wiznet and also we have the
(16:33) micro SD card so let's make sure that those pins are uh being uh outputs and they are set to high okay so a welcome string and we uh start up the Ethernet shield and we configur the uh socket zero uh we sent a command to the soet zero that has to open and uh as we use the atnet shield as a server we have to also type in the listen command and after this we are in the main Loop and we have to check the status of the Ethernet shield so uh this status equals to being disconnected so if it's is we just close
(17:30) the socket and uh what I do here is to reset the EET Shield so everything stays fresh you can uh not do this just uh simply uh make the start up again it will also work uh the 0 0 means it's uh just started up with no configuration so after the reset next on we got the state that uh it is open so if it is we can start listing say server so and uh right here we got the status that is equal to being uh listening and being connected so simply being connected ConEd and as we are I added here a connection flag uh in order to not
(18:37) listen I mean not print uh data that is uh being read directly after being connected to puty because uh that's just some kind of garbage you don't want to print but after uh those few passes uh we can read um data from the Ethernet shield and it is uh received into the data received buffer right here and before printing it I also print uh a sign like this uh to know uh which direction it uh goes so in this case it's a input from the computer to The alate Shield and uh right after the connect if the flag
(19:34) is two uh we print out the uh IP address of the computer that is connected to the Ethernet shield so after two passes uh no uh garbage is being printed so we are good to print the address of the colar okay and uh uh if uh we got some input uh from the USB so this value is uh more than zero uh we simply uh first uh print uh this on the uh console and uh next on we send it uh to the AET Shield so uh if there's enough space uh this variable will be zero and uh here we are checking if we
(20:39) are good to go with uh sending a send command the socket zero so if it is okay to write it the data so there's enough space uh after this we just get the send command and after uh a each Loop we uh toggle the the1 LED and wait 500 milliseconds so this is how it works okay so now maybe let's just reset the board and connect okay so we got this address now let's maybe open up a new instance of py okay so let's copy this let's select taet with the port 23 and let's open it
(21:47) up okay let's type in okay so we see this is a input from the party and let's select add new line and let's write a message from the USB console okay and we get it here okay so uh if we disconnect the partty we will see it's disconnected and we see the socket zero uh reconfiguring I mean the whole internet Shield so everything stays fresh we can connect to it
(22:51) again if we want to and it works fine thanks for watching hope you find it useful in your projects and see you in the next one

---

Source: https://maker.wiznet.io/scarlet/projects/arduino-due-ethernet-shield-w5100-telnet-server-example-in-microchip-studio/
