Pages: 1 [2] 3 4 ... 6   Go Down
Author Topic: max6675+ethernet+sd card  (Read 5307 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Jr. Member
**
Karma: 0
Posts: 66
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hello
thanks for your time.
I do not have the board here with me, I shell try this tonight. I will post the results as soon as possible.

Thanks for your time.

José
Logged

Miramar Beach, Florida
Offline Offline
Faraday Member
**
Karma: 116
Posts: 5393
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

No problem. I know it is a little confusing at first.  smiley

I made a change to the w5100 setup code in the post above. The ethernet library has a bug that leaves the w5100 SPI enabled after the Ethernet.begin() call.

If that works, we will start reading the max6675 in the loop() section every second to test it.
Logged

Offline Offline
Jr. Member
**
Karma: 0
Posts: 66
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

This is a quite big domotica project. At least big for me.
I plan to monitor the temperature all the rooms from my house.
Now I have temp sensors in: Outside (using a dth22)
Kitchen with DS18S20
living room with DS18S20
corridor with DS18S20
Garage with DS18S20

I have a humidity sensor outside (DTH22) and a Light sensor using an LDR.

All this is already running and writing data to an mysql server using PhP.

I plan now to monitor our eating system.
I have an thermocouple inside the burning chamber connected to the Max6675 and two DS18S20 one in  the water input and the other in the water output of the burning chamber.
I also have a rele controlling the pump, so it will turn on the pump when the temp in the burning chamber reaches 60º.

I plan to change the program so when it starts it reads a configuration file from the sd card, later I plan to implement an webpage where I can change the config file in the card.
I also plan to control the air intake in the burning chamber as function of the chamber temperature and the rooms temperatures.

On a later stage I plan to install electro-valves in the eating block in each room to control the water flux according to the comfort temperature set in the config file.

Was this clear enough to show you the motivation of my project ?

José

Logged

Miramar Beach, Florida
Offline Offline
Faraday Member
**
Karma: 116
Posts: 5393
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I don't see a problem. That is a good reason to get this on the standard SPI bus. I have the max6675 code ready for you when you verify the test code above works. I'm still running tests on it. I don't have a max6675, so I am injecting values into the SPI transfer function to verify the conversion to Celsius.

edit: OK, enough testing. If the test above works, this should also.
Code:
#include <SPI.h>
#include <Ethernet.h>
#include <SD.h>

byte mac[] = { 0x00, 0xAA, 0xBB, 0xCC, 0xDE, 0x02 };

void setup() {
  Serial.begin(9600);
  
  // disable w5100 SPI
  pinMode(10,OUTPUT);
  digitalWrite(10,HIGH);
  
  // disable max6675 SPI
  pinMode(49,OUTPUT);
  digitalWrite(49,HIGH);
  
  Serial.print("Starting SD..");
  if(!SD.begin(4)) Serial.println("fail");
  else Serial.println("ok");

  Serial.print("Starting w5100..");
  if(!Ethernet.begin(mac)) Serial.println("failed");
  else Serial.println(Ethernet.localIP());
  digitalWrite(10,HIGH);

  Serial.println("Setup complete");
}

void loop() {
  delay(1000);

  // thisTemp gets temp in 1/4 degrees C
  int thisTemp = readMax();
  
  Serial.print(thisTemp/4,DEC);
  Serial.print(".");
  Serial.println((thisTemp%4) * 25,DEC);
}

int  readMax() {
  int maxLow;
  int maxData;
  
  //  enable max SPI
  digitalWrite(49,LOW);

  // do the 16 bit read  
  maxData = SPI.transfer(0x00);
  maxLow = SPI.transfer(0x00);
  
  // disable max SPI
  digitalWrite(49,HIGH);

  // convert to an integer from the two bytes
  maxData = maxData << 8;
  maxData = maxData | (maxLow & 0xff);

  // shift temp reading into position
  maxData = maxData >> 3;
  
  // return 1/4 degrees Celsius
  return maxData;
}
« Last Edit: November 05, 2012, 02:12:57 pm by SurferTim » Logged

0
Offline Offline
Faraday Member
**
Karma: 7
Posts: 2526
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
The ethernet library has a bug that leaves the w5100 SPI enabled after the Ethernet.begin() call.

There could be hardware issues as well.  Which version of the ethernet shield do you have?  An early version may have a bug.

The W5100 is not a well behaved SPI device in that MISO does not go into a high impedance state when CS is deselected.  There is a separate enable input that is required to cause MISO to go hi-Z.  In a stroke of anti-genius, Wiznet made the two pins opposite logic (one active high, the other active low) so you can't just tie them together to get correct output.

IIRC very early versions of the ethernet shield tied the enable input active, so that effectively you could never send the W5100 MISO into hi-Z, so you could never connect a second peripheral to the SPI bus.  Later versions added a transistor to act as an inverter and activate CS and enable pins with a single input line, making the shield compatible with other SPI devices.

-j
Logged

Miramar Beach, Florida
Offline Offline
Faraday Member
**
Karma: 116
Posts: 5393
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

The bug is in the ethernet library code. I have researched this already. All SPI devices should end up in a disabled state after the setup. I know the Ethernet.begin() function returns with the SPI enabled, both in the code and by experience.

edit: It is not a matter of the MISO line. It is the slave select pin (digital pin 10). Ethernet.begin(mac) returns with digital pin 10 LOW (SPI active).
« Last Edit: November 05, 2012, 02:44:40 pm by SurferTim » Logged

Offline Offline
Jr. Member
**
Karma: 0
Posts: 66
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hello Paul
Sorry for the late post but my litle girl (2 years old) required my attentionuntil now.
I did the connections as you sugested and run the inicial program and I get the following in the serial monitor

Starting SD..fail
Starting w5100..

Could it be a problem with the libraries ?

José
Logged

Offline Offline
Jr. Member
**
Karma: 0
Posts: 66
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Just another thing
If I use the example of the max6675 library with this pin configuration it runs ok
So its not a wiring problem.

José
Logged

Miramar Beach, Florida
Offline Offline
Faraday Member
**
Karma: 116
Posts: 5393
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
If I use the example of the max6675 library with this pin configuration it runs ok
So its not a wiring problem.
OK, then you should be good to go!
Logged

Offline Offline
Jr. Member
**
Karma: 0
Posts: 66
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

No surfer tim
Acording to paul with is first program sugestion I should get ok for both the sd card and the ethernet shield begin.

José
Logged

Miramar Beach, Florida
Offline Offline
Faraday Member
**
Karma: 116
Posts: 5393
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

No surfer tim
Acording to paul with is first program sugestion I should get ok for both the sd card and the ethernet shield begin.

José

But you don't, do you?
Logged

Offline Offline
Jr. Member
**
Karma: 0
Posts: 66
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

No
So I am still in trouble.

José
Logged

Miramar Beach, Florida
Offline Offline
Faraday Member
**
Karma: 116
Posts: 5393
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

No
So I am still in trouble.
Not yet. If you use my last code and disconnect the max6675, does all do ok except the output show:
Quote
Setup complete
0
0
0
0
...and on
Logged

Offline Offline
Jr. Member
**
Karma: 0
Posts: 66
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Yes, making some progress
With your latest code and the wiring of the max6675 disconnected I get

Starting SD..ok
Starting w5100..192.168.1.96
Setup complete


José
Logged

Miramar Beach, Florida
Offline Offline
Faraday Member
**
Karma: 116
Posts: 5393
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

OK! Now we are good. We must figure out how to connect the max6675. If you connect the max6675 to the sck (pin 52), miso (pin 50), and CS (digital pin 49), does it still fail?


Logged

Pages: 1 [2] 3 4 ... 6   Go Up
Jump to: