I fixed a part of it. You were right. That was one part of the problem. The other part was resetting the SPI settings of the ethernetshield. (SPI.setDataMode from SPI_MODE3 to SPI_MODE0 etc.).
Now I got it to work, but it's still losing bits and thus the data will not be very consistent and accurate. But I don't know why and what other settings I could be forgetting.
I changed the webclientcode to sent and receive data from a server. There's nothing wrong with the ethernet output. Just the SPI sensordata. (which is oke when I don't use a ethernetshield).
/*
Web client
This sketch connects to a website (http://www.google.com)
using an Arduino Wiznet Ethernet shield.
Circuit:
* Ethernet shield attached to pins 10, 11, 12, 13
created 18 Dec 2009
by David A. Mellis
modified 9 Apr 2012
by Tom Igoe, based on work by Adrian McEwen
*/
#include <SPI.h>
#include <Ethernet.h>
#include <ADT7310.h>
#define SELPIN 9
ADT7310 adt7310(SELPIN);
unsigned int ADTcheck = 0;
// Enter a MAC address for your controller below.
// Newer Ethernet shields have a MAC address printed on a sticker on the shield
byte mac[] = { 0x90, 0xA2, 0xDA, 0x0D, 0x80, 0x23 }; //physical mac address
byte ip[] = { 192,168,1,101 }; // ip in lan assigned to arduino
byte myserver[] = { 192,168,1,102 };
EthernetClient client;
void setup() {
digitalWrite(9,HIGH);
// Open serial communications and wait for port to open:
Serial.begin(9600);
while (!Serial) {
; // wait for serial port to connect. Needed for Leonardo only
}
// start the Ethernet connection:
Ethernet.begin(mac, ip);
// give the Ethernet shield a second to initialize:
pinMode(SELPIN, OUTPUT);
digitalWrite(10,HIGH);
digitalWrite(3,HIGH);
digitalWrite(4,HIGH);
adt7310.init();
adt7310.reset();
Serial.print("Writing config: ");
adt7310.setmode(ADT7310_1FAULT | ADT7310_CT_POLARITY_LOW | ADT7310_INT_POLARITY_LOW | ADT7310_INTCT_INTERRUPT | ADT7310_CONTINUOUS | ADT7310_16BIT);
Serial.println(" done");
//On powerup, register 0x04 Tcrit should be value 0x4980
Serial.print("reading Tcrit: ");
unsigned int value = adt7310.read(0x04, 16);
Serial.print(" Read complete [0x");
Serial.print(value,HEX);
Serial.println("]");
// Save this value for later to compare against to make sure communications still synchronized.
ADTcheck=value;
delay(240); // First conversion takes ~ 240 ms
SPI.setDataMode(SPI_MODE3);
SPI.setClockDivider(SPI_CLOCK_DIV4);
SPI.setBitOrder(MSBFIRST);
unsigned long ok = 0;
float t = 0;
value=0;
//Read the 16-bit temperature value from register 0x02
value = adt7310.read(0x02, 16);
// Convert to a floating point temperature in C
t=adt7310.temperature(value,16);
value = adt7310.read(0x04, 16);
ok=0;
//} else {
ok=ok+1;
Serial.print("Temperature: ");
Serial.print(t,3);
delay(10);
SPI.setDataMode(SPI_MODE0);
SPI.setBitOrder(MSBFIRST);
SPI.setClockDivider(SPI_CLOCK_DIV2);
digitalWrite(9,HIGH);
delay(10);
}
//-------------------------------------------------------------------------------------------------------------------------------------------------------
//-------------------------------------------------------------------------------------------------------------------------------------------------------
//-------------------------------------------------------------------------------------------------------------------------------------------------------
void loop()
{
unsigned int value = 0;
delay(5);
sendGET();
delay(5);
sendTemp();
delay(5);
SPI.setDataMode(SPI_MODE3);
SPI.setClockDivider(SPI_CLOCK_DIV4);
SPI.setBitOrder(MSBFIRST);
digitalWrite(10,HIGH);
digitalWrite(3,HIGH);
digitalWrite(4,HIGH);
delay(50);
unsigned long ok = 0;
float t = 0;
value=0;
// Read the 16-bit temperature value from register 0x02
value = adt7310.read(0x02, 16);
// Convert to a floating point temperature in C
t=adt7310.temperature(value,16);
value = adt7310.read(0x04, 16);
ok=0;
ok=ok+1;
Serial.print("Temperature: ");
Serial.println(t,3);
SPI.setDataMode(SPI_MODE0);
SPI.setBitOrder(MSBFIRST);
SPI.setClockDivider(SPI_CLOCK_DIV2);
delay(2);
// if the server's disconnected, stop the client:
}