Problema Libreria Ethernet

Ciao a tutti, spero di far giusto.
io sto cercando di creare un programma per la gestione di tutta la casa via arduino.. una delle cose che mi sta facendo diventare matto è un errore della libreria Ethernet.h. ho provato a caricare anche uno sketch dell'esempio della libreria ma l'errore rimane. è questo:

/Users/Alberto/Documents/Arduino/libraries/Ethernet/Ethernet.cpp: In member function 'void EthernetClass::begin(uint8_t*, IPAddress, IPAddress, IPAddress, IPAddress)':
/Users/Alberto/Documents/Arduino/libraries/Ethernet/Ethernet.cpp:65:39: error: no matching function for call to 'W5100Class::setIPAddress(IPAddress::<anonymous union>&)'
  W5100.setIPAddress(local_ip._address);
                                      ^
/Users/Alberto/Documents/Arduino/libraries/Ethernet/Ethernet.cpp:65:39: note: candidate is:
In file included from /Users/Alberto/Documents/Arduino/libraries/Ethernet/Ethernet.cpp:1:0:
/Users/Alberto/Documents/Arduino/libraries/Ethernet/w5100.h:392:6: note: void W5100Class::setIPAddress(uint8_t*)
void W5100Class::setIPAddress(uint8_t *_addr) {
     ^
/Users/Alberto/Documents/Arduino/libraries/Ethernet/w5100.h:392:6: note:   no known conversion for argument 1 from 'IPAddress::<anonymous union>' to 'uint8_t* {aka unsigned char*}'
/Users/Alberto/Documents/Arduino/libraries/Ethernet/Ethernet.cpp:66:38: error: no matching function for call to 'W5100Class::setGatewayIp(IPAddress::<anonymous union>&)'
  W5100.setGatewayIp(gateway._address);
                                     ^
/Users/Alberto/Documents/Arduino/libraries/Ethernet/Ethernet.cpp:66:38: note: candidate is:
In file included from /Users/Alberto/Documents/Arduino/libraries/Ethernet/Ethernet.cpp:1:0:
/Users/Alberto/Documents/Arduino/libraries/Ethernet/w5100.h:368:6: note: void W5100Class::setGatewayIp(uint8_t*)
void W5100Class::setGatewayIp(uint8_t *_addr) {
     ^
/Users/Alberto/Documents/Arduino/libraries/Ethernet/w5100.h:368:6: note:   no known conversion for argument 1 from 'IPAddress::<anonymous union>' to 'uint8_t* {aka unsigned char*}'
/Users/Alberto/Documents/Arduino/libraries/Ethernet/Ethernet.cpp:67:38: error: no matching function for call to 'W5100Class::setSubnetMask(IPAddress::<anonymous union>&)'
  W5100.setSubnetMask(subnet._address);
                                     ^
/Users/Alberto/Documents/Arduino/libraries/Ethernet/Ethernet.cpp:67:38: note: candidate is:
In file included from /Users/Alberto/Documents/Arduino/libraries/Ethernet/Ethernet.cpp:1:0:
/Users/Alberto/Documents/Arduino/libraries/Ethernet/w5100.h:376:6: note: void W5100Class::setSubnetMask(uint8_t*)
void W5100Class::setSubnetMask(uint8_t *_addr) {
     ^
/Users/Alberto/Documents/Arduino/libraries/Ethernet/w5100.h:376:6: note:   no known conversion for argument 1 from 'IPAddress::<anonymous union>' to 'uint8_t* {aka unsigned char*}'

Qualcuno sa come risolverlo? vi ringrazio intanto.

Se non metti il codice che stai usando ... sarà difficile diagnosticare qualsiasi cosa ... ::slight_smile:

Mi raccomando ... racchiuso negli appositi tag CODE come descritto al punto 7 del regolamento (il bottone è il primo a sinistra, quello fatto così : </>).

Guglielmo

Ciao Guglielmo, ecco qui uno sketch che mi da l'errore.. tutti gli sketch ethernet mi danno lo stesso errore...

#include <Ethernet.h>
#include <SPI.h>
byte mac[] = { 
  0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED};
IPAddress ip(192,168,1,20);
IPAddress gateway(192,168,1,1);	
IPAddress subnet(255, 255, 255, 0);
EthernetServer server(80);
const int PRESSURE = 0x1F;
const int PRESSURE_LSB = 0x20;
const int TEMPERATURE = 0x21;
const int dataReadyPin = 6; 
const int chipSelectPin = 7;

float temperature = 0.0;
long pressure = 0;
long lastReadingTime = 0;

void setup() {
  SPI.begin();
  Ethernet.begin(mac, ip);
  server.begin();
  pinMode(dataReadyPin, INPUT);
  pinMode(chipSelectPin, OUTPUT);

  Serial.begin(9600);
  writeRegister(0x02, 0x2D);
  writeRegister(0x01, 0x03);
  writeRegister(0x03, 0x02);
  delay(1000);
  writeRegister(0x03, 0x0A);

}

void loop() { 
  if (millis() - lastReadingTime > 1000){
    if (digitalRead(dataReadyPin) == HIGH) {
      getData();
      lastReadingTime = millis();
    }
  }
  listenForEthernetClients();
}


void getData() {
  Serial.println("Getting reading");
  int tempData = readRegister(0x21, 2);
  temperature = (float)tempData / 20.0;
  byte  pressureDataHigh = readRegister(0x1F, 1);   
  pressureDataHigh &= 0b00000111;
  unsigned int pressureDataLow = readRegister(0x20, 2);
  pressure = ((pressureDataHigh << 16) | pressureDataLow)/4;

  Serial.print("Temperature: ");
  Serial.print(temperature);
  Serial.println(" degrees C");
  Serial.print("Pressure: " + String(pressure));
  Serial.println(" Pa");
}

void listenForEthernetClients() {
  EthernetClient client = server.available();
  if (client) {
    Serial.println("Got a client");
    boolean currentLineIsBlank = true;
    while (client.connected()) {
      if (client.available()) {
        char c = client.read();
        if (c == '\n' && currentLineIsBlank) {
          client.println("HTTP/1.1 200 OK");
          client.println("Content-Type: text/html");
          client.println();
          client.print("Temperature: ");
          client.print(temperature);
          client.print(" degrees C");
          client.println("
");
          client.print("Pressure: " + String(pressure));
          client.print(" Pa");
          client.println("
");  
          break;
        }
        if (c == '\n') {
          currentLineIsBlank = true;
        } 
        else if (c != '\r') {
          currentLineIsBlank = false;
        }
      }
    }
    delay(1);
    client.stop();
  }
} 


void writeRegister(byte registerName, byte registerValue) {
  registerName <<= 2;
  registerName |= 0b00000010;
  digitalWrite(chipSelectPin, LOW); 

  SPI.transfer(registerName);
  SPI.transfer(registerValue);
  digitalWrite(chipSelectPin, HIGH); 
}

unsigned int readRegister(byte registerName, int numBytes) {
  byte inByte = 0;          
  unsigned int result = 0;  
  registerName <<=  2;
  registerName &= 0b11111100; 
  digitalWrite(chipSelectPin, LOW); 
  int command = SPI.transfer(registerName); 
  inByte = SPI.transfer(0x00); 
  
  result = inByte;
  if (numBytes > 1){
    result = inByte << 8;
    inByte = SPI.transfer(0x00); 
    result = result |inByte;
  }
  digitalWrite(chipSelectPin, HIGH); 
  return(result);
}

spero che riesci a darmi una risposta..
intanto ti ringrazio.

Che IDE usi? La libreria ethernet ufficiale è già nel core dell'IDE e quindi il percorso che si vede nell'errore che ti da è errato. In pratica questo: /Users/Alberto/Documents/Arduino/libraries/Ethernet/
Prova a togliere la cartella Ethernet da li (se non vuoi eliminarla del tutto, la sposti momentaneamente sul desktop) poi ricompili lo sketch e ti dovrebbe prendere quella che hai nel core... Se neanche così funziona riscarica l'IDE da capo.

ciao Marinaio67, ho provato ma lo stesso.. mi continua a dare gli stessi errori.. ho provato a cancellare le librerie ethernet, ricaricarla e copiarla di nuovo ma continua l'errore..

Non devi copiarla di nuovo... è già nell'IDE... devi togliere la cartella di nome Ethernet che hai in /Users/Alberto/Documents/Arduino/libraries/

ma se la tolgo mi da questo:

sketch_jun24b.ino:6:22: fatal error: Ethernet.h: No such file or directory
compilation terminated.

quindi vuol dire che non c'è la libreria.

ora ho riscaricato arduino, riprovato a far partire lo sketch ma mi dice questo:

/Users/Alberto/Downloads/Arduino.app/Contents/Java/libraries/Ethernet/src/Ethernet.cpp: In member function 'int EthernetClass::begin(uint8_t*)':
/Users/Alberto/Downloads/Arduino.app/Contents/Java/libraries/Ethernet/src/Ethernet.cpp:19:7: error: 'class SPIClass' has no member named 'beginTransaction'
   SPI.beginTransaction(SPI_ETHERNET_SETTINGS);
       ^
In file included from /Users/Alberto/Downloads/Arduino.app/Contents/Java/libraries/Ethernet/src/Ethernet.cpp:1:0:
/Users/Alberto/Downloads/Arduino.app/Contents/Java/libraries/Ethernet/src/utility/w5100.h:18:71: error: 'SPISettings' was not declared in this scope
 #define SPI_ETHERNET_SETTINGS SPISettings(4000000, MSBFIRST, SPI_MODE0)
                                                                       ^
/Users/Alberto/Downloads/Arduino.app/Contents/Java/libraries/Ethernet/src/Ethernet.cpp:19:24: note: in expansion of macro 'SPI_ETHERNET_SETTINGS'
   SPI.beginTransaction(SPI_ETHERNET_SETTINGS);
                        ^
/Users/Alberto/Downloads/Arduino.app/Contents/Java/libraries/Ethernet/src/Ethernet.cpp:22:7: error: 'class SPIClass' has no member named 'endTransaction'
   SPI.endTransaction();
       ^
/Users/Alberto/Downloads/Arduino.app/Contents/Java/libraries/Ethernet/src/Ethernet.cpp:30:9: error: 'class SPIClass' has no member named 'beginTransaction'
     SPI.beginTransaction(SPI_ETHERNET_SETTINGS);
         ^
/Users/Alberto/Downloads/Arduino.app/Contents/Java/libraries/Ethernet/src/Ethernet.cpp:34:9: error: 'class SPIClass' has no member named 'endTransaction'
     SPI.endTransaction();
         ^
/Users/Alberto/Downloads/Arduino.app/Contents/Java/libraries/Ethernet/src/Ethernet.cpp: In member function 'void EthernetClass::begin(uint8_t*, IPAddress, IPAddress, IPAddress, IPAddress)':
/Users/Alberto/Downloads/Arduino.app/Contents/Java/libraries/Ethernet/src/Ethernet.cpp:68:7: error: 'class SPIClass' has no member named 'beginTransaction'
   SPI.beginTransaction(SPI_ETHERNET_SETTINGS);
       ^
In file included from /Users/Alberto/Downloads/Arduino.app/Contents/Java/libraries/Ethernet/src/Ethernet.cpp:1:0:
/Users/Alberto/Downloads/Arduino.app/Contents/Java/libraries/Ethernet/src/utility/w5100.h:18:71: error: 'SPISettings' was not declared in this scope
 #define SPI_ETHERNET_SETTINGS SPISettings(4000000, MSBFIRST, SPI_MODE0)
                                                                       ^
/Users/Alberto/Downloads/Arduino.app/Contents/Java/libraries/Ethernet/src/Ethernet.cpp:68:24: note: in expansion of macro 'SPI_ETHERNET_SETTINGS'
   SPI.beginTransaction(SPI_ETHERNET_SETTINGS);
                        ^
/Users/Alberto/Downloads/Arduino.app/Contents/Java/libraries/Ethernet/src/Ethernet.cpp:73:7: error: 'class SPIClass' has no member named 'endTransaction'
   SPI.endTransaction();
       ^
/Users/Alberto/Downloads/Arduino.app/Contents/Java/libraries/Ethernet/src/Ethernet.cpp: In member function 'int EthernetClass::maintain()':
/Users/Alberto/Downloads/Arduino.app/Contents/Java/libraries/Ethernet/src/Ethernet.cpp:89:13: error: 'class SPIClass' has no member named 'beginTransaction'
         SPI.beginTransaction(SPI_ETHERNET_SETTINGS);
             ^
In file included from /Users/Alberto/Downloads/Arduino.app/Contents/Java/libraries/Ethernet/src/Ethernet.cpp:1:0:
/Users/Alberto/Downloads/Arduino.app/Contents/Java/libraries/Ethernet/src/utility/w5100.h:18:71: error: 'SPISettings' was not declared in this scope
 #define SPI_ETHERNET_SETTINGS SPISettings(4000000, MSBFIRST, SPI_MODE0)
                                                                       ^
/Users/Alberto/Downloads/Arduino.app/Contents/Java/libraries/Ethernet/src/Ethernet.cpp:89:30: note: in expansion of macro 'SPI_ETHERNET_SETTINGS'
         SPI.beginTransaction(SPI_ETHERNET_SETTINGS);
                              ^
/Users/Alberto/Downloads/Arduino.app/Contents/Java/libraries/Ethernet/src/Ethernet.cpp:93:13: error: 'class SPIClass' has no member named 'endTransaction'
         SPI.endTransaction();
             ^
/Users/Alberto/Downloads/Arduino.app/Contents/Java/libraries/Ethernet/src/Ethernet.cpp: In member function 'IPAddress EthernetClass::localIP()':
/Users/Alberto/Downloads/Arduino.app/Contents/Java/libraries/Ethernet/src/Ethernet.cpp:107:7: error: 'class SPIClass' has no member named 'beginTransaction'
   SPI.beginTransaction(SPI_ETHERNET_SETTINGS);
       ^
In file included from /Users/Alberto/Downloads/Arduino.app/Contents/Java/libraries/Ethernet/src/Ethernet.cpp:1:0:
/Users/Alberto/Downloads/Arduino.app/Contents/Java/libraries/Ethernet/src/utility/w5100.h:18:71: error: 'SPISettings' was not declared in this scope
 #define SPI_ETHERNET_SETTINGS SPISettings(4000000, MSBFIRST, SPI_MODE0)
                                                                       ^
/Users/Alberto/Downloads/Arduino.app/Contents/Java/libraries/Ethernet/src/Ethernet.cpp:107:24: note: in expansion of macro 'SPI_ETHERNET_SETTINGS'
   SPI.beginTransaction(SPI_ETHERNET_SETTINGS);
                        ^
/Users/Alberto/Downloads/Arduino.app/Contents/Java/libraries/Ethernet/src/Ethernet.cpp:109:7: error: 'class SPIClass' has no member named 'endTransaction'
   SPI.endTransaction();
       ^
/Users/Alberto/Downloads/Arduino.app/Contents/Java/libraries/Ethernet/src/Ethernet.cpp: In member function 'IPAddress EthernetClass::subnetMask()':
/Users/Alberto/Downloads/Arduino.app/Contents/Java/libraries/Ethernet/src/Ethernet.cpp:116:7: error: 'class SPIClass' has no member named 'beginTransaction'
   SPI.beginTransaction(SPI_ETHERNET_SETTINGS);
       ^
In file included from /Users/Alberto/Downloads/Arduino.app/Contents/Java/libraries/Ethernet/src/Ethernet.cpp:1:0:
/Users/Alberto/Downloads/Arduino.app/Contents/Java/libraries/Ethernet/src/utility/w5100.h:18:71: error: 'SPISettings' was not declared in this scope
 #define SPI_ETHERNET_SETTINGS SPISettings(4000000, MSBFIRST, SPI_MODE0)
                                                                       ^
/Users/Alberto/Downloads/Arduino.app/Contents/Java/libraries/Ethernet/src/Ethernet.cpp:116:24: note: in expansion of macro 'SPI_ETHERNET_SETTINGS'
   SPI.beginTransaction(SPI_ETHERNET_SETTINGS);
                        ^
/Users/Alberto/Downloads/Arduino.app/Contents/Java/libraries/Ethernet/src/Ethernet.cpp:118:7: error: 'class SPIClass' has no member named 'endTransaction'
   SPI.endTransaction();
       ^
/Users/Alberto/Downloads/Arduino.app/Contents/Java/libraries/Ethernet/src/Ethernet.cpp: In member function 'IPAddress EthernetClass::gatewayIP()':
/Users/Alberto/Downloads/Arduino.app/Contents/Java/libraries/Ethernet/src/Ethernet.cpp:125:7: error: 'class SPIClass' has no member named 'beginTransaction'
   SPI.beginTransaction(SPI_ETHERNET_SETTINGS);
       ^
In file included from /Users/Alberto/Downloads/Arduino.app/Contents/Java/libraries/Ethernet/src/Ethernet.cpp:1:0:
/Users/Alberto/Downloads/Arduino.app/Contents/Java/libraries/Ethernet/src/utility/w5100.h:18:71: error: 'SPISettings' was not declared in this scope
 #define SPI_ETHERNET_SETTINGS SPISettings(4000000, MSBFIRST, SPI_MODE0)
                                                                       ^
/Users/Alberto/Downloads/Arduino.app/Contents/Java/libraries/Ethernet/src/Ethernet.cpp:125:24: note: in expansion of macro 'SPI_ETHERNET_SETTINGS'
   SPI.beginTransaction(SPI_ETHERNET_SETTINGS);
                        ^
/Users/Alberto/Downloads/Arduino.app/Contents/Java/libraries/Ethernet/src/Ethernet.cpp:127:7: error: 'class SPIClass' has no member named 'endTransaction'
   SPI.endTransaction();
       ^

Sono punto a capo.. :frowning: :frowning: :frowning:

Più info.
Quale Arduino hai ?
Quale IDE hai scaricato ? Quale sistema operativo, windows, linux, mac ?

Domanda ovvia, ma... nell'IDE hai selezionata la board giusta ?
Appena provato con IDE 1.6.2 in ufficio da me e il codice che hai postato sopra mi compila (Win XP)

Risolto. Il problema era nella libreria SPI. cancellata quella ha cominciato a funzionare!
Vi ringrazio tantissimo!!!!!!

Ps. nid69ita arduino uno, 1.6.5 con sistema mac.

Spero che ora tu abbia capito che le librerie di SISTEMA non le devi aggiungere nella tua cartella delle librerie. :wink:

In quella cartella vanno SOLO librerie NON di sistema.

Per inciso, quelle di sistema (e che non devi toccare) sono quelle che trovi nelle due cartelle interne all'IDE :

/Applications/Arduino.app/Contents/Java/libraries
/Applications/Arduino.app/Contents/Java/hardware/arduino/avr/libraries

Guglielmo