I am attempting to build a small sensor network for my greenhouse as a first Arduino project. I have several sensors attached and working though there is still some calibration work to be done. One of the things that I would like to do with this is to write the sensor outputs to a file on an SD card.
My setup includes:
Arduino UNO R3
Seeed Studio Grove Base Shield (stacked on top of Arduino)
Arduino Ethernet Shield R3 with Wiznet5100 (Ethernet and microSD output) - jumpered to Base Shield as follows:
Digital Pin 4
Digital Pin 10
Powered as normally
Freetronics TEMT6000 light sensor attached to A1-Reset-Grd as in data sheet
DHT22 Temperature and Humidity Pro sensor attached to A2 using supplied sensor cable
HP20X Barometric Pressure sensor attached to I2C using supplied sensor cable
Homebrew galvanic moisture sensor attached to A0 using schematic found online
All of this works. I can upload a sketch and run all day long dumping sensor values.
I want to log them to the SD card though and eventually to send them via XBee to my PC.
Right now the sketch and the hardware only includes the SD card output.
When I run Serial Monitor I see that the SD card initially writes the first set of values that it sees.
On the next write the SD card initialization fails.
I have been through a lot of posts looking for a solution that works for me but without success. I do have the digitalWrite setting 10 HIGH.
I have also swapped in a Seeed Studio W5200 Ethernet Shield with SD output and grabbed those libraries but for that setup it won’t even write the first time. I did swap the chipSelect to 8 (instead of 4 for the Arduino borad) as noted in something I saw on Adafruit I think.
One thing that may be problematic is the memory usage by variables in the sketch reportedly leaves only 652 bytes after compile. I understand from somewhere else that the SD write needs at least 512 to function so I tweaked things to get to this point.
I am posting the code here in case anyone has a chance to give me a hint at what is wrong.
You don’t have to go easy on me. If something in the code stinks I’d like to know about it. It’s been 30 years since I messed with C coding so it may take me a while to get my C legs back.
Greenhouse_Sensors5.ino (4.55 KB)