w5100 and ledcontrol.h not working...

Hi, I have a project where I have a W5100 and 4 7 segment displays. I use ledcontrol.h for the leds and thats where I hit the problem of compiling.

#include <SPI.h>
#include <Ethernet.h>
#include <ICMPPing.h> 
#include <OneWire.h>
#include <DallasTemperature.h>
//#include <LedControl.h>    // For the 7 Segment LED display driven by MAX7219

//LedControl lc=LedControl(8,7,6,2);    

//tempsensors
OneWire ds_1(2);   //sensor 2 (utomhus) on pin 4
OneWire ds_2(3);  //sensor 3 (vatten) on pin 5
OneWire ds_3(4);  //sensor 1 (bastun) on pin 6
OneWire ds_4(5);  //sensor 4 (badtunnevattnet) on pin 7

//Temperatures
int temp_ute = 0;
int temp_vatten = 0;
int temp_bastu = 0;
int temp_badtunna = 0;

boolean lanstatus;

//Lan constants
SOCKET pingSocket = 0; 
char buffer [256];
ICMPPing ping(pingSocket, (uint16_t)random(0, 255));

//Lan static values
byte mac[] = { 0x90, 0xA2, 0xDA, 0x0D, 0x7D, 0x54 };  
//byte ip[] = {192,168,1,20}; // ip address for ethernet shield
IPAddress pingAddr(192,168,1,106); // ip address to ping
char domoticz_server[] = "192.168.1.106";
EthernetClient domoticz_client;

String part1_1 = "GET /json.htm?type=command&param=udevice&idx=36&nvalue=0&svalue="; //update bastu temp
String part1_2 = "GET /json.htm?type=command&param=udevice&idx=9&nvalue=0&svalue="; //update ute temp
String part1_3 = "GET /json.htm?type=command&param=udevice&idx=37&nvalue=0&svalue="; //update vatten temp
String part1_4 = "GET /json.htm?type=command&param=udevice&idx=35&nvalue=0&svalue="; //update badtunnevatten temp
String part2 = "";
String part3 = " HTTP/1.1";  
String datainput = "777";

void setup() 
{
Serial.begin(9600);
Serial.println("Booting..");
//  int devices=lc.getDeviceCount();
//  for(int address=0;address<devices;address++) {
//    lc.shutdown(address,false);
//    lc.setIntensity(address,13);
//    lc.clearDisplay(address);
//  }  
networkSetup();
}

void loop (){
Serial.println("Start of sensor check");
//lanstatus = pingTest();
temperatureCheck();
delay(500);
Serial.println("End of sensor check");
//displayTempBastu();
delay(500);
}
void networkSetup()
{
Serial.println("Trying to get an IP address using DHCP");

if (Ethernet.begin(mac) == 0) 
{ 
Serial.println("Failed to configure Ethernet using DHCP");
while (true) 
{
;
}
}
Serial.println();
// start listening for clients
Serial.print("server is at "); 
Serial.println(Ethernet.localIP());
}

boolean pingTest()
{
  ICMPEchoReply echoReply = ping(pingAddr, 4);
  if (echoReply.status == SUCCESS)
  {
   Serial.println("ping worked");
   return true;
  }
  else
  {
    Serial.println("ping error");
    return false;
  }
  Serial.println(buffer);  
}

If I have the code like this with the ledcontrol.h //coment out. Then it compiles as it shuld.

Bit if I includes the ledControl.h I directly get the following errors

In file included from D:\Dropbox\KG\Personligt\Arduino\libraries\icmp_ping/ICMPPing.h:12:0,
                 from Bastucontroller.ino:4:
C:\Program Files (x86)\arduino-1.6.5-r2\libraries\Ethernet\src/utility/w5100.h:15:16: error: expected unqualified-id before numeric constant
 #define SPI_CS 10
                ^
D:\Dropbox\KG\Personligt\Arduino\libraries\LedControl\src/LedControl.h:75:13: note: in expansion of macro 'SPI_CS'
         int SPI_CS;
             ^
Error compiling.

Anyone have any advice? I guess there is a SPI conflict or similar but I cant figure out a solution…

You need to post a link to the LedControl library. Something it is doing is causing the problem.

Shuld be this library

https://github.com/wayoda/LedControl

What a bunch of morons! I'm referring to the dipshits that wrote the Ethernet code. There is just no excuse for using #define to give a constant a name, when const byte is just as effective AND localizes the extent of the name.

You'll need to edit the w5100.h file, to change

#define SPI_CS 10

to

const byte SPI_CS = 10;

Similar changes may be needed to other #define statements with SPI_ in the name.

PaulS: What a bunch of morons! I'm referring to the dipshits that wrote the Ethernet code. There is just no excuse for using #define to give a constant a name, when const byte is just as effective AND localizes the extent of the name.

You'll need to edit the w5100.h file, to change

#define SPI_CS 10

to

const byte SPI_CS = 10;

Similar changes may be needed to other #define statements with SPI_ in the name.

Thank you for your reply.

I changed it and now the error looks like this

In file included from D:\Dropbox\KG\Personligt\Arduino\libraries\icmp_ping/ICMPPing.h:12:0,
                 from Bastucontroller.ino:4:
C:\Program Files (x86)\arduino-1.6.5-r2\libraries\Ethernet\src/utility/w5100.h:15:2: error: invalid preprocessing directive #const
 #const byte SPI_CS = 10;

There is 2 more define SPI_ are they the problem? Have tried a litle bit but this is not my strong suit. What shuld they be?

#if defined(ARDUINO_ARCH_AVR)
#define SPI_ETHERNET_SETTINGS SPISettings(4000000, MSBFIRST, SPI_MODE0)
#else
#define SPI_ETHERNET_SETTINGS SPI_CS,SPISettings(4000000, MSBFIRST, SPI_MODE0)
#endif

eriksson25: C:\Program Files (x86)\arduino-1.6.5-r2\libraries\Ethernet\src/utility/w5100.h:15:2: error: invalid preprocessing directive #const #const byte SPI_CS = 10;

You didn't read carefully enough. PaulS said to change it to:

const byte SPI_CS = 10;

Another option would be to update to Ethernet library version 1.1.2 because they have changed the name of that macro to ETHERNET_SHIELD_SPI_CS so that should solve the conflict. You can do this by: Sketch > Include Library > Manage Libraries... > Filter your search... > type "Ethernet" > click on Ethernet > Update > Close