Dopo qualche mese di assenza, riprendo questa serie di tutorial per qualche nuovo progetto… oggi però vi voglio parlare di una libreria un po’ particolare…
Tutti gli esempi che vi ho mostrato si basano sulla libreria Ethercard di JeeLabs – nel primo post vi ho anche spiegato come installarla all’interno dell’IDE.
Questa libreria ha dato prova di essere molto ben realizzata, stabile e supportata dagli sviluppatori.
Ho trovato una diversa libreria, sempre per il controller enc28j60, chiamata UIPEthernet (pagina ufficiale su Github). Questa libreria ha il grosso vantaggio di essere compatibile con gli sketch scritti per la libreria ufficiale.
L’unica modifica necessaria è modificare tutti gli include, sostituendo Ethernet.h con UIPEthernet.h.
Come esempio, carichiamo lo sketch WebServer ed effettuiamo la modifica sopra descritta:
Con questa piccola modifica, lo sketch ora viene correttamente compilato e funziona con il nostro shield:
Nell’utilizzarla, dobbiamo però tenere conto delle differenze hardware tra i due controller (W5100 e enc28j60), ricordando in particolare che il secondo utilizza delle risorse del chip ATMega e che quindi ha sicuramente dei limiti maggiori.
In particolare ho riscontrato che alcuni sketch non funzionano (Arduino continua a resettarsi) perché viene saturata la memoria RAM del microcontrollore… è il caso ad esempio della libreria per collegarsi a database MySQL.
I’m experiencing a similar problem, I have a MEGA2560 clone, and I’m using the UIPEthernet and MySQL libraries. Mine tends to hang (instead of resetting), though.
Have you been able to find a solution yet? I really want to be able to implement this, but I can’t if it won’t keep running.
Thanks.
Hi Noam,
unfortunately not, I moved to Arduino Yun: the connection to the MySql server is performed by the linux “part” of that board: easier (using PHP or Python driver) and more reliable.
Ciao Luca, grazie mille per i tuoi preziosi consigli. Ho iniziato a seguire il tuo blog da pochi giorni. Da poche ore sto testando la shield ethernet (w5100) su arduino uno r3. Vorrei collegare ad essa delle sonde di umidità e temperatura e inviare i dati in tempo reale su un server MySQL o comunque su internet sfruttando la connessione wifi di casa (router tp-link distante circa 300 mt lineari da arduino). Per questo motivo vorrei utilizzare un altro router tp-link con openwrt (impostato come client wds) e collegato alla shield lan arduino nella postazione dove dovrò installare le sonde, in modo da creare una connessione punto-punto tra i due router tp-link il primo connesso ad internt, il secondo connesso ad arduino ethernet. Non conosco bene MySQL. Mi puoi aiutare in questa mia ardua impresa?? Grazie mille.
Ciao Enzo
Il controller W5100 è diverso da quello che utilizzo io e non ne possiedo uno, quindi non ho modo di aiutarti…
Very interesting. For the enc28J60 there were/are in fact 2 official libraries: the EtherShield and the Ethercard.
The Ethernet library was for the WIZ5100.
The example from TomIgoe that you showed, as fat as I know is for the WIZ5100 not for the ENC28J60.
The github page for the UIPEthernet libray that you link to indeed confimrs it is for the ENC28J60, but the example they give of replacing “Ethernet.h” with “UIPEthernet.h” points to : http://arduino.cc/en/Reference/Ethernet
and that is the page for the WIZ5100 library.
So do i understand correct that the UIPEthernet libray makes the sketches for the W5100 board available for the ENC28J60 board?
Exactly, with some limitations due to the different capabilities of the two chips… but most of the sketches written for the W5100 should work also with UIPEthernet on enc28j60 shields.
Thanks for confirmation. good t know and thanks for pointing out this library 🙂
hi luca,
UIPEthernet library does not compactible with my arduino ide s o what i do i am using version r2 -1.0.5
Hi! It should.. which error do you get?
Dear Luca,
Thanks a lot for the wonderful library. I am facing the following problem using UIPEthernet library.
1. When we restart the router that is connected to enc28j60, webserver parsing example stops working.
Can you please confirm if you are facing the same problem.
Cheers
Hi Lali,
mmm no, so it seems that when you reboot the router you’re no longer able to reach the Arduino? What if you ping the ip address of Arduino? No response too?
Ciao, non so se leggi ancora i commenti, ma ho un piccolo problema nel funzionamento di uno sketch passando dal w5100 all’ENC28J60. Si tratta di un semplice rilevatore di temperatura ed umidità che oltre a quello fa da server in modo da poter essere monitorato e controllato (fa’ anche da “termostato”) via internet dovrebbe fare da client verso EMONCMS (un sito di raccolta dati tipo Xively per intenderci) mandandogli un semplice GET con i valori da salvare.
Col w5100 funzionava tutto bene, con l’ENC28J60 invece le due parti server e client funzionano bene finché le uso da sole, ma nel momento in cui il server ha una richiesta mentre l’Arduino sta inviando dati come client o viceversa il tutto smette di rispondere.
Presumo sia legato al fatto che anche dopo il client.stop() in realtà una parte dei dati sia ancora da inviare e quindi il server quando riceve la connessione dall’altro client “sovrapponga le due cose mandando in crisi l’ENC28J60. Per me non sarebbe un problema sospendere gli invii delle letture durante l’accesso di un client esterno, ma non ho trovato il modo di scindere le due cose, dato che dopo il client.stop() secondo la libreria il client è chiuso anche se ha ancora dati da inviare, per cui un semplice:
if (!client1) { //se client1 non è più connesso
if (client2.connect(server2, 80)) { //apri client2
non funziona, perché il primo if restituisce vero anche se ci sono ancora dati da inviare al client1 già formalmente chiuso.
Ciao Davide, non ho molta esperienza con la libreria UIPethernet che immagino tu stia utilizzando… un appassionato mi ha però passato un esempio completo (che pubblicherò a breve) e il primo suggerimento è quello di aggiornare la libreria all’ultima versione perché hanno risolto molti bugs.
Ciao Luca, sto seguendo con interesse i tuoi tutorial, ma non riesco a capire come si fa con il metodo browseurl ad interrogare una pagina che ho su un server in locale (192.168.1.10/pagina.php) anzichè con un indirizzo internet.
Ciao Fabrizio, è molto semplice: invece che fare la richiesta al DNS per avere l’IP del server, se già lo conosci puoi configurarlo direttamente tu così:
ether.copyIp(myipaddress, ether.hisip);
dovemyipaddress
è un array (4 bytes) contenente l’IP del tuo server.Ciao Luca, ho da poco acquistato il modulo ethernet ENC28J60, ho seguito le tue guide, provando sia la libreria ether, sia quella di questo articolo, ma quando provo a fare il ping mi esce scritto che l’host non è raggiungibilem anche se dal monitor seriale tutto va bene, ho anche provato il test DHCP della ether, ma non mi da errori da seriale. Per collegare la scheda ethernet al pc utilizzo un router netgear. Sto facendo delle prove sia con arduino UNO, sia con il MEGA, ma con il medesimo risultato. Preferirei usare la libreria UIP, visto che ho già alcuni progetti realizzati con la ethernet ufficiale. Grazie.
Claudio, anche gli esempi più banali (IP fisso, DHCP…) non vanno? Sembra proprio un problema di “interazione” tra il modulo e il router: prova a cambiare il mac address (è una variabile dello sketch) mettendone uno “simile” a quello di un tuo PC (lo vedi su Win con ipconfig /all)
Ciao Luca, anch’io ho lo stesso problema di Claudio… non riesco a pingare il modulo ethernet.
Se lo collego direttamente al PC lo pingo, ma se lo collego al mio router Netgear non lo pingo più. Ho cambiato il MAC, ma niente.
Non so se è un problema di modulo e di configurazione router…
Ciao! Dopo aver fatto il comando ping prova a digitare “arp -a” e vedi se il PC è riuscito a risolvere il mac address dello shield…
ciao vorrei fare un ping verso il modem: cioe vorrei vedere se l ‘arduino e collegato al modem, e quando riceve il ping entro un tieout mi scrive sul display connesso. mi potresti aiutare?
Hello !
I’m using an arduino uno. I loaded the web server sketch, but it is not connected to the internet (ping is not responding). Previous examples worked with Ethercard, but not with UIPEthernet. I forced a static IP, the serial monitor displays the correct IP, but Ping is still not responding, weird… Any idea ?
Hi Mickael, try loading a simpler sketch (for example PING): does it work?
Hello !
I’m using an arduino uno. I loaded the web server sketch, but it is not connected to the internet (ping is not responding). when i used UIPEthernet library. i got the ip what we are giving in the program but Ping is still not responding, weird… iam using enc28j60.hoping for your reply.
Hi! Make sure the IP address you’re assigning to Arduino is “compatible” with your network (i.e. it’s in the same subnet). Try also the “arp -a” commnand to verify if your PC can retrieve the MAC address of Arduino given its IP.
Hi luca, i’am from Venezuela… I just bought one arduino mega 2560 clone, and 2 separate modules which I tried to connect via spi ( enc28j60 + microSD reader LVC125A chip ). I’ve been able to connect both shields separately, and even load some html scripts using the UIPEthernet libs, i think it works pretty cool just plug and play, right!? unfortunately I haven’t been able to make them work both together, i would like to create a file in the sd and load it when needed, i’ve been fooling around with SPI for a while and I have just realized that maybe my connections are wrong, I am doing the connection for both modules by separate, i mean ether is wired on pines 50-53 and sd card is wired on pines 10-13 when they are both connected, my question to you is: do i have to wire MISO / MOSI / SCK of both shields in 50-52 pines and just use pines I decide like 10 and 4 for SS? thanks for your answer!
Hi! SPI bus works as it follows: wire MOSI/MISO/SCK to ALL the SPI devices in parallel and use a different arduino PIN as “chip select” (SS) for each device.