Home
JAQForum Ver 24.01
Log In or Join  
Active Topics
Local Time 07:32 15 Nov 2025 Privacy Policy
Jump to

Notice. New forum software under development. It's going to miss a few functions and look a bit ugly for a while, but I'm working on it full time now as the old forum was too unstable. Couple days, all good. If you notice any issues, please contact me.

Forum Index : Microcontroller and PC projects : Ethernet Library for Micromite

     Page 1 of 2    
Author Message
yobortsa
Newbie

Joined: 12/12/2011
Location: Australia
Posts: 37
Posted: 03:42am 07 Jun 2015
Copy link to clipboard 
Print this post

Howdy,

Here is the beginnings of a library for TCP/IP support on the Micromite using the Wiznet W5100 module - readily available cheaply on eBay, eg:

eBay listing for Wiznet W5100 module

This library of functions and subroutines has support for TCP server and client with an example of both. It could be used to run a small embedded webserver, or post measurements to a webserver periodically.



Receiving data from the Wiznet is a bit slow - byte by byte over SPI. It would ideally be rewritten in C if better performance were required. Although, I don't expect many embedded applications would require much in the way of data transfer - short messages periodically only.

The datasheet for the Wiznet W5100 module is available from here (there are later versions around if you search, but figured this should be a reliable link to publish):

W5100_Datasheet_v1_1_6.pdf

There is no DHCP support, only static IP address - the Wiznet W5100 doesn't support DHCP but you could add DHCP support to this library in MM-Basic.

Hope it's helpful to somebody.

Regards,

David

2015-06-07_133729_ip_micromite_v2.2.zipEdited by yobortsa 2015-06-08
 
viscomjim
Guru

Joined: 08/01/2014
Location: United States
Posts: 925
Posted: 09:19am 07 Jun 2015
Copy link to clipboard 
Print this post

Damn it!!! Another module I have to have... Thanks Yorbortsa for the code, when I get my module, I will give it a whirl. Keep up the good work!!!!
 
jman

Guru

Joined: 12/06/2011
Location: New Zealand
Posts: 711
Posted: 09:55am 07 Jun 2015
Copy link to clipboard 
Print this post

Well done
This is an awesome addition to the Mite.

Hint Prod @Peter Maybe this can be done using CFunctions

Jman
 
yobortsa
Newbie

Joined: 12/12/2011
Location: Australia
Posts: 37
Posted: 11:24am 07 Jun 2015
Copy link to clipboard 
Print this post

Hi All,

I've written some brief documentation for the Micromite Wiznet W5100 Library, see below.

Regards,

David

2015-06-07_212241_micromite_wiznet_library_David_and_Jacqui's_Wiki.pdf
 
Grogster

Admin Group

Joined: 31/12/2012
Location: New Zealand
Posts: 9755
Posted: 03:37pm 07 Jun 2015
Copy link to clipboard 
Print this post

I use the WizNet 107SR in my other big board, but it is a native serial port rather then raw data on an SPI channel - each to their own. This method(this thread here) has more flexibility for custom solutions etc.

In my case, I just used the 107SR connected to the console so that I could control the MM console remotely over the LAN or WAN(with correct port-forwarding setup).

I'm interested in this method though, so please keep us posted on your developments! Edited by Grogster 2015-06-09
Smoke makes things work. When the smoke gets out, it stops!
 
yobortsa
Newbie

Joined: 12/12/2011
Location: Australia
Posts: 37
Posted: 09:41am 15 Jun 2015
Copy link to clipboard 
Print this post

Hi all,

I found the Guidelines for Creating Libraries for MMBasic over here and have updated the Wiznet W5100 ethernet module MM-Basic library accordingly. I also fixed a few things, made some improvements and added UDP support.

2015-06-15_193612_micromite_wiznet_library_2015-06-16.pdf

Example Webserver:


'-------------------------------------------------------------------------
' Wiznet W5100 Micromite Examples
'
' Hardware Connections
'
' +--------+--------------------------------------------+
' | Wiznet | Micromite |
' +--------+--------------------------------------------+
' | Ground | Pin 19 |
' | +5V | +5V |
' | RST | Pin 23 (Wiznet W5100 Reset) |
' | SS | Pin 15 (SPI Slave Select) |
' | CLK | Pin 25 (SPI Clock) |
' | MO | Pin 3 (SPI MOSI - Master Out, Slave In) |
' | MI | Pin 14 (SPI MISO - Master In, Slave Out) |
' | Gnd | not used |
' | PoE+ | not used |
' | PoE- | not used |
' +--------+--------------------------------------------+

Option explicit
Option base 1

dim ip1%, ip2%, ip3%, ip4%
Dim example$
Dim txstring$
Dim curLineBlank%, curFirstLine%
Dim char%
Dim firstLine$
Dim i%
Dim conversationStart%

' Call with pin used for Wiznet Reset and SPI Slave Select of Wiznet:
WN.Init 23, 15

' Set a pin as analog input for testing webserver
SetPin 26, ain

' Set up the IP address to use
ip1%=192
ip2%=168
ip3%=1
ip4%=65

' Set static MAC address/IP address/subnet mask/gateway

WN.SetMAC &H00,&HFE,ip1%,ip2%,ip3%,ip4%
WN.SetIP ip1%,ip2%,ip3%,ip4%
WN.SetMask 255,255,255,0
WN.SetGateway ip1%,ip2%,ip3%,1

WN.Start ' Sets various internal registers for Wiznet

Do
If WN.SockClosed(3) Then
If WN.SockTCPInit(3, 80) Then
Print "Socket initialized on local port 80"
Else
Error "Failed to initialize socket"
End If
If WN.SockTCPListen(3) Then
Print "Server is at "+WN.GetIP$()
curLineBlank%=1
curFirstLine%=1
firstLine$=""
conversationStart%=0
Else
Error "Failed to listen on socket"
End If
End If

Do While WN.SockEstablished(3)
If conversationStart%=0 Then conversationStart%=Timer
For i%=1 To WN.sockData(3)
char%=WN.sockRead(3)
Print Chr$(char%);
If char%=&H0D Then
If curLineBlank%=1 Then
Print firstLine$
WN.SockWrite 3,"HTTP/1.1 200 OK"+WN_CrLf$
WN.SockWrite 3,"Content-Type: text/html"+WN_CrLf$
WN.SockWrite 3,""+WN_CrLf$
WN.SockWrite 3,"<!DOCTYPE HTML>"+WN_CrLf$
WN.SockWrite 3,"<html>"+WN_CrLf$
WN.SockWrite 3,"<h3>Micromite Webserver</h3>"+WN_CrLf$
WN.SockWrite 3,"<p>Pin 26: "+Str$(Pin(26))+" volts</p>"+WN_CrLf$
WN.SockWrite 3,"</html>"+WN_CrLf$
WN.SockWrite 3,""+WN_CrLf$
WN.SockClose 3
End If
End If
If char%=&H0D Then
curLineBlank%=1
curFirstLine%=0
Else If char%<>&H0A Then
curLineBlank%=-1
If curFirstLine%=1 Then
firstLine$=firstLine$+Chr$(char%)
End If
End If
Next i%
Loop
If conversationStart%>0 Then
Print "Time: "+Str$((Timer-conversationStart%)/1000)+" seconds"
conversationStart%=0
End If
Loop

End

<include library here>


Browse to http://192.168.1.65/

2015-06-15_193929_Webserver_and_UDP_Examples.zip

Regards,

David
 
jman

Guru

Joined: 12/06/2011
Location: New Zealand
Posts: 711
Posted: 11:19pm 15 Jun 2015
Copy link to clipboard 
Print this post

Hi David

This is fantastic well done


Jman
 
bigmik

Guru

Joined: 20/06/2011
Location: Australia
Posts: 2971
Posted: 12:27am 16 Jun 2015
Copy link to clipboard 
Print this post

OMG David,

I wish you didn't create this monster ...

Look what I have gone and done now.

http://mickls.gotdns.org/

Regards,

Mick

PS.. I love it... now to see a list of commands that this module can do... I have had to scrape the last few brain cells from the bottom of my skull to find the correct syntax to display links and pictures etc.. but in a relatively short time... Hey I have a web-server (Almost)

And running on a MicroMite to boot.

Mik
Mick's uMite Stuff can be found >>> HERE (Kindly hosted by Dontronics) <<<
 
yobortsa
Newbie

Joined: 12/12/2011
Location: Australia
Posts: 37
Posted: 06:17pm 17 Jun 2015
Copy link to clipboard 
Print this post

Here is a multi-page webserver example:


'-------------------------------------------------------------------------
' Wiznet W5100 Micromite Examples
'
' Hardware Connections
'
' +--------+--------------------------------------------+
' | Wiznet | Micromite |
' +--------+--------------------------------------------+
' | Ground | Pin 19 |
' | +5V | +5V |
' | RST | Pin 23 (Wiznet W5100 Reset) |
' | SS | Pin 15 (SPI Slave Select) |
' | CLK | Pin 25 (SPI Clock) |
' | MO | Pin 3 (SPI MOSI - Master Out, Slave In) |
' | MI | Pin 14 (SPI MISO - Master In, Slave Out) |
' | Gnd | not used |
' | PoE+ | not used |
' | PoE- | not used |
' +--------+--------------------------------------------+

Option explicit
Option base 1

Dim ip1%, ip2%, ip3%, ip4%
Dim example$
Dim txstring$
Dim curLineBlank%, curFirstLine%
Dim char%
Dim firstLine$
Dim i%
Dim conversationStart%

' Call with pin used for Wiznet Reset and SPI Slave Select of Wiznet:
WN.Init 23, 15

' Set a pin as analog input for testing webserver
SetPin 26, ain

' Set up the IP address to use
ip1%=192
ip2%=168
ip3%=1
ip4%=65

' Set static MAC address/IP address/subnet mask/gateway

WN.SetMAC &H00,&HFE,ip1%,ip2%,ip3%,ip4%
WN.SetIP ip1%,ip2%,ip3%,ip4%
WN.SetMask 255,255,255,0
WN.SetGateway ip1%,ip2%,ip3%,1

WN.Start ' Sets various internal registers for Wiznet

Do
If WN.SockClosed(3) Then
If WN.SockTCPInit(3, 80) Then
Print "Socket initialized on local port 80"
Else
Print "Failed to initialize socket"
End If
If WN.SockTCPListen(3) Then
Print "Server is at "+WN.GetIP$()
curLineBlank%=1
curFirstLine%=1
firstLine$=""
conversationStart%=0
Else
Print "Failed to listen on socket"
End If
End If

Do While WN.SockEstablished(3)
If conversationStart%=0 Then conversationStart%=Timer
For i%=1 To WN.sockData(3)
char%=WN.sockRead(3)
Print Chr$(char%);
If char%=&H0D Then
If curLineBlank%=1 Then
Print firstLine$
If Instr(1, firstLine$, "?on") Then
SendHeader
WN.SockWrite 3,"<h3>Lights turned On!</h3>"+WN_CrLf$
SendFooter
Else If Instr(1, firstLine$, "?off") Then
SendHeader
WN.SockWrite 3,"<h3>Lights turned Off!</h3>"+WN_CrLf$
SendFooter
Else
SendHeader
SendFooter
End If
End If
End If
If char%=&H0D Then
curLineBlank%=1
curFirstLine%=0
Else If char%<>&H0A Then
curLineBlank%=-1
If curFirstLine%=1 Then
firstLine$=firstLine$+Chr$(char%)
End If
End If
Next i%
Loop
If conversationStart%>0 Then
Print "Time: "+Str$((Timer-conversationStart%)/1000)+" seconds"
conversationStart%=0
End If
Loop

End

Sub SendHeader
WN.SockWrite 3,"HTTP/1.1 200 OK"+WN_CrLf$
WN.SockWrite 3,"Content-Type: text/html"+WN_CrLf$
WN.SockWrite 3,""+WN_CrLf$
WN.SockWrite 3,"<!DOCTYPE HTML>"+WN_CrLf$
WN.SockWrite 3,"<html>"+WN_CrLf$
WN.SockWrite 3,"<h3>Micromite Webserver</h3>"+WN_CrLf$
WN.SockWrite 3,"<p>Pin 26: "+Str$(Pin(26))+" volts</p>"+WN_CrLf$
End Sub

Sub SendFooter
WN.SockWrite 3,"<p><a href='./?on'>Turn lights On</a> | "
WN.SockWrite 3,"<a href='./?off'>Turn lights Off</a></p>"+WN_CrLf$
WN.SockWrite 3,"</html>"+WN_CrLf$
WN.SockWrite 3,""+WN_CrLf$
WN.SockClose 3
End Sub

<include library here>
 
bigmik

Guru

Joined: 20/06/2011
Location: Australia
Posts: 2971
Posted: 01:12pm 18 Jun 2015
Copy link to clipboard 
Print this post

GDay All,

  bigmik said  
Look what I have gone and done now.

http://mickls.gotdns.org/


David has done a pretty good job with his library to the WizNet board..

Now the following could be pretty boring to those who already know this but I post it to maybe assist others get their own WizNet boards live on the net..

Lets get a whole heap of them going around the world..

The above was done fairly simply by looking at HTML code and playing with it in Daivds WN.xxx syntax. I know nothing at all about HTML code and whilst the command syntax is not quite exact it is very close and is basically the " marks in different locations.

I have attached the basic code here if someone was interested in setting up one for them selves.

2015-06-18_225341_mick_webserver_v1.bas.zip

You need to set up a STATIC IP for the WIzNet board (defined in lines 45-48) this should then work on your local network, set these to suit a static IP on your network.

To get the WizNet board to be seen on your WWW network you need to set your Modem/router to `port forward' requests to port 80 through to the IP address of the WizNet module... There are heaps of tutorials on how to do that if you consult Dr. Google.

Now WizNet should be able to be seen externally by using your `real world ISP assigned IP address' in my case (you will have your own set of numbers... Goto myip.dk to see what yours is set to) this, for me, is currently 120.144.191.64 so you can just enter those numbers into your browser from anywhere in the world..

Now, as is the case for me this real world IP can and does change from time to time (such as a restart of my modem or a loss of power etc) so that is where a site like DYNDNS.ORG can help.. you can apply for an acct with them (I think its about $10 per year) which gives you a `pseudo domain name' and then you run a `ticker' on your PC (a small file that sits on your pc to periodically tell dyndns what your ISP assigned IP is and dyndns will update its records and assign your IP to your domain name.. in my case its mickls.gotdns.org so you never need to know what your IP actually is as it all happens in the background.

All that aside my WizNet setup is locking up from time to time, I dont know why, but it seems to be once per day.. I reckon I need to setup a watch dog timer to reset in the event of a lockup/error.

I am going away for about 2 weeks on the weekend so mickls.gotdns.org will probably be offline until I get back.. I may leave it going if I can get a watchdog going.

Regards,

Mick


EDIT***

I have added a watchdog timer to hopefully catch any lockups etc..

If it looks stable I will leave it up whilst I am away.

Mick
Edited by bigmik 2015-06-20
Mick's uMite Stuff can be found >>> HERE (Kindly hosted by Dontronics) <<<
 
bigmik

Guru

Joined: 20/06/2011
Location: Australia
Posts: 2971
Posted: 03:35pm 19 Jun 2015
Copy link to clipboard 
Print this post

Hi All,

I have still been experiencing lock ups with my uMite Powered WizNet board..
After consultation with David, he thinks it may be the SETTICK routine is interrupting the SPI communications with the WizNet board..

I was trying to show a `real world' situation where you could remotely read the status of various pins.

Goes to show why I shouldn't be allowed near a programming console and should stick to my soldering iron..

In any case, I have modified the code to use Pin(26) as a PWM 20Hz 50% output and read this in on pin(2)..

Please test Mickls `Wiz-Bang' Server and let me know if it falls over.

If it does fall over I will put it aside until I get back from Overseas (Fiji)..

Regards,

Mick

Mick's uMite Stuff can be found >>> HERE (Kindly hosted by Dontronics) <<<
 
viscomjim
Guru

Joined: 08/01/2014
Location: United States
Posts: 925
Posted: 05:00pm 19 Jun 2015
Copy link to clipboard 
Print this post

Just tried it. Seems to be working quite well!!!
 
bigmik

Guru

Joined: 20/06/2011
Location: Australia
Posts: 2971
Posted: 06:15pm 19 Jun 2015
Copy link to clipboard 
Print this post

Nope!

Stopped working again...

I am pulling it off air until I get back.. It is most likely something I did adding to David's code.. I really am a lousy programmer so it isn't my expertise...

Anyway I will go and have a 10 day long hangover and get sunburned in Lovely Fiji and forget the cold of Melbourne's Winter....

Bye All,

Catch ya all soon.

Regards,

Mick


Mick's uMite Stuff can be found >>> HERE (Kindly hosted by Dontronics) <<<
 
Chris Roper
Senior Member

Joined: 19/05/2015
Location: South Africa
Posts: 280
Posted: 11:23pm 19 Jun 2015
Copy link to clipboard 
Print this post

Have a good Holiday Mick.
My wife is off to the south of France for a month too.

I will sit here shivering in Cape Town, complaining that the Beer is too cold, and think of you both sunning yourselves :(

On the up side, the wine is good, the soldering Iron is hot, and I get a month to concentrate on projects, full time, with no family commitments :)

Cheers
Chris

http://caroper.blogspot.com/
 
paceman
Guru

Joined: 07/10/2011
Location: Australia
Posts: 1329
Posted: 11:52pm 20 Jun 2015
Copy link to clipboard 
Print this post

Sounds like a fair swap Chris

GregEdited by paceman 2015-06-22
 
MarKoZaKKa
Newbie

Joined: 14/02/2015
Location: Italy
Posts: 7
Posted: 10:51am 19 Oct 2018
Copy link to clipboard 
Print this post

Hello,
I started playing with micromite years ago, but never did a complete project up to now. Now I would like to use that amazing piece of hardware to build a web-based home heating control for my house (just as a startpoint) and I get this quite old thread.

I saw that wiznet device used here is no more available; instead, there's a lot of different vendor serialTTL-to-LAN devices, for cheap prices (I've found a clone of the UsrIOT model USR-TCP232-T2 on italian eBay for 7,50€).

My question:
Do this wiznet have specific Ethernet or TCP/IP-related features that UsrIOT module doesn't have, so it's not possible to use that one, even adapting the code?(except for communication interface between uMite and module, i know these are different)

Sorry, I know the first answer that come to your mind is "Why you didn't read the thread?". I did, but I did not understood that. English is not my native language, maybe I'm misunderstand some thing. You can just answer YES or NOT without explanation.
Thank you, greetings from Italy.
 
Grogster

Admin Group

Joined: 31/12/2012
Location: New Zealand
Posts: 9755
Posted: 03:02am 20 Oct 2018
Copy link to clipboard 
Print this post

Welcome to the forums.

I suggest you go for the 107SR serial-based network module, which is still available.
This one uses a standard UART serial connection instead of SPI, so you can buffer whatever the module sends to the MM in one of it's COM port buffers, then deal with whatever has arrived as part of your main DO/LOOP, safe in the knowledge that nothing will be missed, as the buffer looks after that for you.

The 107SR can use static IP address, or DHCP if you choose.

Have a look at this link for the latest version - about twenty bucks each. These are the genuine onese. If you wanted rock bottom, there are probably clones on eBay cheaper, but I cannot vouch for their quality or reliability. The Wiznet ones work well with the MM.
Smoke makes things work. When the smoke gets out, it stops!
 
MarKoZaKKa
Newbie

Joined: 14/02/2015
Location: Italy
Posts: 7
Posted: 06:34am 21 Oct 2018
Copy link to clipboard 
Print this post

Thank you, Grogster, it’s quite expensive (from my POV) but ok, quality matter.
But my question was: it’s mandatory to use wiznet because embedded functions of this module, or it can be replaced? I already have an ESP WiFi module, for instance. I usually work via serial connections, point to point or via CAN transceivers, no experience on networking OF MCUs
 
Kabron

Regular Member

Joined: 30/11/2017
Location: Germany
Posts: 65
Posted: 08:49am 27 Oct 2020
Copy link to clipboard 
Print this post

Hello, yobortsa
what dialect of mmbasic did you use?
I' surprizing witn
SPI open 4000000, 0, 8, 15
command.
Obviously, you mean to define pin 15 as SS in this command.
But my BackPack170 with 5.0.5.0.3 FW does not recognize it.
If I use SPI open 4000000, 0, 8
and add PIN(15)=0 at the beginning and PIN(15)=1 at the end of wiznetRead/Write subs it works.
 
twofingers

Guru

Joined: 02/06/2014
Location: Germany
Posts: 1677
Posted: 12:36pm 27 Oct 2020
Copy link to clipboard 
Print this post

  Kabron said  Hello, yobortsa
what dialect of mmbasic did you use?

Please read the date of this thread!
I'm afraid Yobortsa won't read your question.
Regards
Michael
causality ≠ correlation ≠ coincidence
 
     Page 1 of 2    
Print this page
The Back Shed's forum code is written, and hosted, in Australia.
© JAQ Software 2025