Go Down

Topic: DHT22 Webserver (Read 8231 times) previous topic - next topic

DancesWithWords

So I think I've discovered why we have been having issue with the webserver. 

from the Arduino Doc's:

Quote
Warning

This example doesn't require an SD card. If an SD card is inserted but not used, it is possbile for the sketch to hang, because pin 4 is used as SS (active low) of the SD and when not used it is configured as INPUT by default. Two possible solutions:
remove the SD card;
add these lines of code in the setup()
pinMode(4, OUTPUT);
digitalWrite(4, HIGH);
Having read this I noticed that I had a MicroSD card in the slot.  So I removed it, rebooted the webserver and ran it for a hour and 1/2 with out a single problem.


To see if it was in fact the above issue I've rolled back to my first working copy of this code, before we started tinkering with the server code.  So far still no issues.  Everything is being render in the browser as per the code

====
DWW.

Peter_n

Yeah, that should be in every example code that uses SPI.

Before using the SD or Ethernet, the default chip select SS should be output (on Uno and Mega) and all chip selects should be set high, so set pin SS and 4 and 10 as output and HIGH.

The first thing I do in setup() is Serial.begin() and write a message what project it is. After that I set those chip selects high. Then I start with the normal initialization of modules, chips and sensors.

DancesWithWords

Yeah, that should be in every example code that uses SPI.

Before using the SD or Ethernet, the default chip select SS should be output (on Uno and Mega) and all chip selects should be set high, so set pin SS and 4 and 10 as output and HIGH.

The first thing I do in setup() is Serial.begin() and write a message what project it is. After that I set those chip selects high. Then I start with the normal initialization of modules, chips and sensors.
If you have a sample/snippet you could post for other to see and/or use please do so.


====
DWW

Peter_n

For the Ethernet Shield with the Uno, Nano, Pro Mini, and Mega 2560
Code: [Select]

void setup()
{
  // Write message to serial terminal that Arduino is running.
  Serial.begin( 9600);
  Serial.println(F("Running"));
 
  // Disable all slave selects on the SPI bus, and set 'SS' to output.
  // The Ethernet Shield uses pin 4 and 10.
  // The 'SS' is pin 10 for Uno and pin 53 for Mega.
  // But disable them all, even if SS is also pin 10.
  // The 'SS' needs to be output, for the internal SPI hardware to work properly.
  // Disable a SPI device means setting the chip select high.
  pinMode ( SS, OUTPUT);    // pin 10 on Uno, pin 53 on Mega
  digitalWrite( SS, HIGH);

  pinMode( 4, OUTPUT);       // SD chip select at pin 4
  digitalWrite( 4, HIGH);

  pinMode( 10, OUTPUT);     // W5100 chip select at pin 10
  digitalWrite( 10, HIGH);

  // SPI bus is now idle and ready to be used.
  delay(1);

  // The Ethernet.begin() and SD.begin() can now be called.
 
}


Paul Stoffregen calls this a "workaround" at step 1 : http://www.dorkbotpdx.org/blog/paul/better_spi_bus_design_in_3_steps
I call it the normal and good way to make the SPI bus idle before starting to use it.

robtillaart

Good to see it has been solved.

09:45:31

Humidity=23%
Temperature=21 C
Dewpoint=-1 C

analog input 0 is 308
analog input 1 is 349
analog input 2 is 324
analog input 3 is 310
analog input 4 is 288
analog input 5 is 300
Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

DancesWithWords

For the Ethernet Shield with the Uno, Nano, Pro Mini, and Mega 2560
Code: [Select]

void setup()
{
  // Write message to serial terminal that Arduino is running.
  Serial.begin( 9600);
  Serial.println(F("Running"));
 
  // Disable all slave selects on the SPI bus, and set 'SS' to output.
  // The Ethernet Shield uses pin 4 and 10.
  // The 'SS' is pin 10 for Uno and pin 53 for Mega.
  // But disable them all, even if SS is also pin 10.
  // The 'SS' needs to be output, for the internal SPI hardware to work properly.
  // Disable a SPI device means setting the chip select high.
  pinMode ( SS, OUTPUT);    // pin 10 on Uno, pin 53 on Mega
  digitalWrite( SS, HIGH);

  pinMode( 4, OUTPUT);       // SD chip select at pin 4
  digitalWrite( 4, HIGH);

  pinMode( 10, OUTPUT);     // W5100 chip select at pin 10
  digitalWrite( 10, HIGH);

  // SPI bus is now idle and ready to be used.
  delay(1);

  // The Ethernet.begin() and SD.begin() can now be called.
 
}


Paul Stoffregen calls this a "workaround" at step 1 : http://www.dorkbotpdx.org/blog/paul/better_spi_bus_design_in_3_steps
I call it the normal and good way to make the SPI bus idle before starting to use it.
I like that, I'll be using it in this and future projects that use my Ethernet shield.

DancesWithWords

Good to see it has been solved.

09:45:31

Humidity=23%
Temperature=21 C
Dewpoint=-1 C

analog input 0 is 308
analog input 1 is 349
analog input 2 is 324
analog input 3 is 310
analog input 4 is 288
analog input 5 is 300

WE got it solved.  Thanks to everyone who lent me hand with this project.

Go Up