Ethernet Library Questions

Status
Not open for further replies.

jkoffman

Well-known member
Hi all,

I'd like to start adding Ethernet based control for some of my projects. I have the WIZ820io+SD board connected to a Teensy 3.2 for testing. Nothing else has been connected at this point, I want to just try to explore the libraries, etc.

I decided to start experimenting with the Artnet examples as it's a network protocol that I'm familiar with. I loaded the basic ArtnetReceive example sketch, modified the IP address, then tried to run it. I ran in to a few issues. I've managed to get it working, but now I have a few questions!

1. When I first tried to compile I had a failure. I realized I had downloaded a different Ethernet library and put it in my Arduino folder, not the application folder (this is on OSX). Moving my library away seems to have solved that. Is there a better way to deal with this, or is it all dependent on where the libraries are?

2. In the example it uses a private class C network (like 192.168.X.X). I saw another example that showed defining a subnet, gateway, and DNS server. So conceivably I should be able to move to a class A network (like many Artnet networks use). I tried looking at the source, but I can't figure out if there's a test in there to automatically determine subnet based on the IP address. If I have to explicitly specify a non 255.255.255.0 subnet, what would I put for gateway and DNS when I don't need them. 0.0.0.0?

3. This is more of a philosophical question. How do people handle configuration for small embedded projects without things like screens? For simple projects I'll usually have a set of DIP switches, one some physically larger ones I'll put on a display. The Teensy is so small and capable, it seems a shame to add a display just for things like IP addresses. I prefer not to hard code all of the values if possible. I did find a project showing an Ethernet configuration through the web server (http://www.jo3ri.be/arduino/projects/network-settings-web-page-form-using-eeprom-to-save-submit). My issue with that type of configuration is that you must already be on the same subnet as the device. And if you don't know the current IP address, connecting can be problematic. I suppose some sort of "reset to defaults" button would be a good idea. Or perhaps some kind of USB interface that allows config? My problem there is that I have very little coding experience for computers (I only really do embedded work), so creating the config program would be tricky. What other ideas have people come up with to accomplish this?

Thank you!

Josh
 
My issue with that type of configuration is that you must already be on the same subnet as the device. And if you don't know the current IP address, connecting can be problematic. I suppose some sort of "reset to defaults" button would be a good idea.
Yes. Either default to DHCP or something like 192.168.0.1.
Or perhaps some kind of USB interface that allows config? My problem there is that I have very little coding experience for computers (I only really do embedded work), so creating the config program would be tricky.
You could use serial over USB and something like AT commands. So your 'program' can be some standard serial console.
 
Yes. Either default to DHCP or something like 192.168.0.1.

Many of the networks I use don't have DHCP servers on them. I'll have to think about this more. Since I'm using Artnet there should be a way to detect and configure using that, but that's probably beyond my coding ability on the computer side.

You could use serial over USB and something like AT commands. So your 'program' can be some standard serial console.

This is actually on my list to look into already. I was planning on doing some LCD development recently, but I don't have the right bits with me. I was debating figuring out a way to use a serial over USB connection to sort of emulate an LCD on the computer, just until I'm back somewhere I can get parts. If I managed that then a serial based menu system should be fairly possible. If you or anyone has any pointers to anyone doing something like that already I'd love to see what theirs looks like.

Thanks for the reply!
 
Many of the networks I use don't have DHCP servers on them.
You could just use a cheap router/access point that has a DHCP server or a Linux laptop with crossover cable.
I was debating figuring out a way to use a serial over USB connection to sort of emulate an LCD on the computer, just until I'm back somewhere I can get parts. If I managed that then a serial based menu system should be fairly possible. If you or anyone has any pointers to anyone doing something like that already I'd love to see what theirs looks like.
A menu system is definitely not something I would do - far too complicated. I would use AT commands like this:
http://wiki.iteadstudio.com/Serial_Port_Bluetooth_Module_(Master/Slave)_:_HC-05
and serial terminal software like Realterm, Putty, Minicom, Screen...
 
You could just use a cheap router/access point that has a DHCP server or a Linux laptop with crossover cable.

Sorry, what I meant by this was that I may have to change IPs more often than usual, so coming up with a semi-easy way to do it would be nice.

A menu system is definitely not something I would do - far too complicated. I would use AT commands like this:
http://wiki.iteadstudio.com/Serial_Port_Bluetooth_Module_(Master/Slave)_:_HC-05
and serial terminal software like Realterm, Putty, Minicom, Screen...

The nice thing about a menu system is that it would require less external documentation. Even if it's just me using it, I forget things, so having it print out a list and then pressing 1 to change IP, 2 to change subnet, etc might be nice.

Thank you for the link though, I'll probably implement something like that at the start if I decide to go the serial route!
 
I use a menu system for configuration over serial. It's really not that hard. A proper menu input function (with input error checking) is just a line or twenty of code. There are also many libraries available that make menu systems even more easy.

If you use DHCP, stuff like subnet gets set automatically. If you use manual addressing, you could calculate the subnet.

Current Arduino IDEs use a library manager that can automatically install or import libraries for you. E.g. I use a modified, non-blocking Ethernet library which I can just select from the library menu.
 
I use a menu system for configuration over serial. It's really not that hard. A proper menu input function (with input error checking) is just a line or twenty of code. There are also many libraries available that make menu systems even more easy.

Do you use a state machine to manage submenus? I found this library (https://github.com/jeroendoggen/Arduino-serial-menu) which looks interesting. Since I'm new to proper object oriented programming I have a feeling I'll try to solve this in a way that doesn't fully use the power of the language.

If you use DHCP, stuff like subnet gets set automatically. If you use manual addressing, you could calculate the subnet.

Ah, cool link! Thank you for that.

Current Arduino IDEs use a library manager that can automatically install or import libraries for you. E.g. I use a modified, non-blocking Ethernet library which I can just select from the library menu.

I should have been more clear. I think my issue was that there were multiple libraries with the same name. So the IDE just picks one somehow. I'm wondering if there's a way to influence that choice or if removing the incorrect libraries is the best way.

Thanks for the reply!
 
Hi all,

Fresh batch of questions here. Please let me know if I should be creating a new thread for this. I wasn't sure since I'm already asking Ethernet library questions, plus there's another existing thread that sort of starts talking about what I'm trying to do...

Ultimately, my goal is to use the audio library at the same time as the Ethernet library. I have both the audio and WIZ820 boards. Since they conflict on a few pins, my plan is to use the audio board unaltered then move a few of the pins between the Teensy and the WIZ820. I did a bit of searching and found this thread from a couple of years ago talking about exactly what I'm trying to do:

https://forum.pjrc.com/threads/26628-Teensy-Audio-Ethernet

Based on that thread and the link Paul posted to it, I believe I need to have the Ethernet libraries deal with a few of the connections on different ports. Namely, I need to move MOSI to pin 7, MISO looks to be the same, SCLK to pin 14, and I think I have to find a new pin for CS as well.

So here are my questions:

1. If use the setMOSI(), setMISO(), and setSCK() functions, will that work for all libraries in my program? So basically I'd use these functions and then they would work for both the SD and Ethernet libraries, correct?

2. I don't know what to do about the CS signals. Do I just have the ones labeled CS in grey on the pinout diagram to choose from, or can I choose from any pin? And once I choose, I am not clear on how to indicate which library should be using which CS.

I am fairly new to this environment, so I apologize for the beginner nature of my questions. I am still trying to wrap my head around how to deal with more complex projects with multiple libraries in use at once.

Thanks!
 
Do you use a state machine to manage submenus? I found this library (https://github.com/jeroendoggen/Arduino-serial-menu) which looks interesting. Since I'm new to proper object oriented programming I have a feeling I'll try to solve this in a way that doesn't fully use the power of the language.
Yes. I assign each menu level a number (e.g. 31 is the first subpage of the third page of the menu) and use the user input to browse through the menu (sub)pages. I actually didn't bother with the libraries but just cooked something up myself.

I should have been more clear. I think my issue was that there were multiple libraries with the same name. So the IDE just picks one somehow. I'm wondering if there's a way to influence that choice or if removing the incorrect libraries is the best way.
Actually I was wondering that myself. All my ethernet libs (default one, non-blocking one, W5500 one) have the same name, still the IDE always picks the right one. I think the IDE sets the path somewhere when you use the Include Library menu option.

1. If use the setMOSI(), setMISO(), and setSCK() functions, will that work for all libraries in my program? So basically I'd use these functions and then they would work for both the SD and Ethernet libraries, correct?
That should work yes.

2. I don't know what to do about the CS signals. Do I just have the ones labeled CS in grey on the pinout diagram to choose from, or can I choose from any pin? And once I choose, I am not clear on how to indicate which library should be using which CS.
Afaik you can use any pin for CS - if you assert it manually. The gray CS pins are for libraries that automatically assert the CS.

Don't forget to properly reset the Wiznet chip when using other SPI devices! See bottom of this page.
 
Yes. I assign each menu level a number (e.g. 31 is the first subpage of the third page of the menu) and use the user input to browse through the menu (sub)pages. I actually didn't bother with the libraries but just cooked something up myself.

Ok, good to know I'm on the right track. That's exactly what I was going to do. Are you clearing the screen when a selection is made or just scrolling up? I am thinking about screen clearing, seems a bit...cleaner (hah!).

Actually I was wondering that myself. All my ethernet libs (default one, non-blocking one, W5500 one) have the same name, still the IDE always picks the right one. I think the IDE sets the path somewhere when you use the Include Library menu option.

Ah, intriguing. I ran into my issue running an example file, so I didn't use the menu to include the library. It definitely got the wrong library. Luckily that warning tells me what it's up to, and I could see that it was specifically skipping the Teensy related one, so that's what drove me to start moving things around.

Afaik you can use any pin for CS - if you assert it manually. The gray CS pins are for libraries that automatically assert the CS.

Don't forget to properly reset the Wiznet chip when using other SPI devices! See bottom of this page.

Good tip on the reset. I will add that to the code. And I think I found the location of the CS pin at the end of w5100.h. I think my next step will be to jumper between the pins I want to use on the Teensy and the Ethernet module and see if I can get the example code to work with the new pins.

So further to the library management question above, I'm about to have two versions of w5100.h, one for the board's original configuration, and one for my hacked together version. I guess I just have to make sure I have the correct one in the correct place when building the project?

Thank you!

Josh
 
Ok, good to know I'm on the right track. That's exactly what I was going to do. Are you clearing the screen when a selection is made or just scrolling up? I am thinking about screen clearing, seems a bit...cleaner (hah!).
My top level pages use clearing to emulate the terminal feeling. It's meant to be used with Putty mainly.
Code:
      Serial.write(27);                               // ESC
      Serial.print("[2J");                            // clear screen
      Serial.write(27);                               // ESC
      Serial.print("[H");  
      *Your display lines go here*

So further to the library management question above, I'm about to have two versions of w5100.h, one for the board's original configuration, and one for my hacked together version. I guess I just have to make sure I have the correct one in the correct place when building the project?
Imo it's easier to just copy the existing library to a new one and making your modifications there. I use a modified w5100.h too (for WIZ5500 support). I've put this into a (copied) library that I call Ethernet5 and then use Include library > Ethernet5. That way you still keep the original library, which is better for legacy sketches or upgrading. Mind you that the included h files are still named Ethernet.h etc., as we talked about above.
 
My top level pages use clearing to emulate the terminal feeling. It's meant to be used with Putty mainly.
Code:
      Serial.write(27);                               // ESC
      Serial.print("[2J");                            // clear screen
      Serial.write(27);                               // ESC
      Serial.print("[H");  
      *Your display lines go here*

Makes total sense.

Imo it's easier to just copy the existing library to a new one and making your modifications there. I use a modified w5100.h too (for WIZ5500 support). I've put this into a (copied) library that I call Ethernet5 and then use Include library > Ethernet5. That way you still keep the original library, which is better for legacy sketches or upgrading. Mind you that the included h files are still named Ethernet.h etc., as we talked about above.

Makes sense to me...sadly I just failed at it. I copied the Teensy Ethernet library (/hardware/teensy/avr/libraries/Ethernet), modified w5100.h (line 325 through 327), and went to try it. I used the "Include Library" menu option in case it was setting some path in the background. It failed. The Teensy is still using pin 10 as the CS line, even though I changed those lines to reference pin 6. Which makes me wonder if the correct library is being referenced. However I can't figure out a way to check, I don't know where Arduino saves any build files, etc. So I moved all other Ethernet libraries out of the Library folder (both in the Teensy section and higher up), but to no avail.

At this point I don't know what library Arduino is using for sure, but I do know my modifications to w5100.h either aren't working correctly or the wrong library is being referenced.

Any thoughts?

Josh
 
Aha, I just fixed it. It turns out there's a definition for the W5100 SS pin and the W5200 SS pin separately. In different files.

In W5100.cpp line 30 there is a definition for the W5200 SS pin. Changing that has worked. Next I will try adding the other libraries back and seeing what choices the IDE makes regarding what to include in the compile.
 
Status
Not open for further replies.
Back
Top