Indoor Weather Station using Arduino

Not rated 22,245

Indoor Weather Station using Arduino
Indoor Weather Station using Arduino

The Arduino 2009 functions as an independent weather station without a display. It can operate autonomously for extended periods, sampling data from sensors until the RAM reaches full capacity. The collected data is stored in a designated sector of an SD card, allowing for the potential accumulation of a year's worth of weather samples. When connected to a PC, any unsaved sectors are uploaded to the computer's hard drive for display using the PC's interface. The current sector on the SD card is retained in the EEPROM, enabling reuse after power loss or reset. The Arduino employs a class EEPROM that restricts operations to byte-level read and write. To read a longer data segment (32 bytes in Arduino), additional processing is required. The code snippet provided illustrates how to read the last saved block number from the EEPROM and send this information to the computer. The SD card utilized should be a version 2.00 or later Standard Capacity SD Memory Card, with 1.0 and 2.0 GB cards from 2009 functioning effectively. The operation of the code involves direct reading and writing to SD card sectors without utilizing a FAT file system. If the card is formatted, the FAT in the lower sectors and files in higher sectors can be overwritten without damaging the card, although reformatting may be necessary for compatibility with Windows or Linux. The timing for read and write operations is approximately 44 milliseconds. Improvements could be made to support version 1 SD and HC SD cards by adjusting command usage.

The Arduino 2009 weather station setup involves several key components and processes. The system starts by initializing the SD card and configuring the necessary SPI (Serial Peripheral Interface) settings. The Arduino communicates with the SD card to read and write data blocks. The class `SDCARDclass` encapsulates the functionality for managing the SD card operations, including reading and writing blocks of data.

The `readblock` and `writeblock` functions are crucial for data management. They handle the transfer of 512 bytes of data between the SD card and a buffer in RAM. The buffer is declared as a global variable to ensure accessibility across different functions. The error handling mechanism ensures that any issues during read or write operations are reported, and appropriate actions are taken, such as signaling an error through an LED indicator.

The EEPROM is utilized to store the last block number written to the SD card, allowing the system to resume operations seamlessly after a reset or power interruption. The provided inline function `lastblocksave` showcases the process of writing data to the SD card and updating the EEPROM with the current block number.

The Arduino's ability to function as a standalone weather station relies on its efficient data sampling from various sensors, storage management on the SD card, and communication with the PC for data retrieval. This system is particularly beneficial for long-term environmental monitoring, as it can collect and store extensive datasets over time without the need for constant supervision.The Arduino 2009 acts as a standalone weather station. It does not display the data. It can operate independently for months. It samples the sensors until the RAM is full. The RAM samples are stored on a sector of an SD card. Eventually, a year`s weather samples could be stored on the SD card. Each time the PC is connected, any unstored sectors ar e uploaded to files on the PC`s hard drive. It can then be displayed using all the facilities of the PC`s display. The SD card current sector is held in EEPROM so that during power off or reset, it can be reused. The Arduino has a class EEPROM which only allows read and write of bytes. To read a long (32 bytes in Arduino) requires some work: inline void ready() { unsigned long lastblock = 0; //the last block number saved in the sd card unsigned long tempblock = 0; tempblock = EEPROM. read(0); // remember the LSB of the last saved block lastblock |= tempblock; tempblock = EEPROM. read(1); // remember the next LSB of the last saved block lastblock |= tempblock << 8; tempblock = EEPROM. read(2); // remember the next LSB of the last saved block lastblock |= tempblock << 16; tempblock = EEPROM. read(3); // remember the next MSB of the last saved block lastblock |= tempblock << 24; Serial. println("ready"); //send computer the ready to reset message Serial. println(lastblock); //send computer the last saved block number delay(10000); //every 10 seconds }//end of ready /* Card type: Ver2.

00 or later Standard Capacity SD Memory Card 1. 0 and 2. 0 GB cards purchased in 2009 work well. Usage: Must have global variable. volatile unsigned char buffer[512]; Function calls. unsigned char error = SDCARD. readblock(unsigned long n); unsigned char error = SDCARD. writeblock(unsigned long n); error is 0 for correct operation read copies the 512 bytes from sector n to buffer. write copies the 512 bytes from buffer to the sector n. References: SD Specifications. Part 1. Physical Layer Simplified Specification Version 2. 00 September 25, 2006 SD Group. Code examples: search "sd card" Operation: The code reads/writes direct to the sectors on the sd card.

It does not use a FAT. If the card has been formatted the FAT at the lowest sectors and files at the higher sectors can be written over. The card is not damaged but will need to be reformatted at the lowest level to be used by windows/linux.

Timing: readblock or writeblock takes 44 msec. Improvement: Could initialize so that can use version 1 sd and hc sd. Instead of CMD1 need to use CMD8, CMD58 and CMD41. */ #ifndef SDCARD_h #define SDCARD_h #define setupSPI SPCR = 0x53; //Master mode, MSB first, //SCK phase low, SCK idle low, clock/64 #define deselectSPI SPCR = 0x00; //deselect SPI after read write block #define clearSPI SPSR = 0x00; // clear SPI interrupt bit #define setupDDRB DDRB |= 0x2c; //set SS as output for cs #define selectSDCARD PORTB &= ~0x04; //set the SS to 0 to select the sd card #define deselectSDCARD PORTB |= 0x04; //set the SS to 1 to deselect the sd card #include "WProgram. h" class SDCARDclass { public: unsigned char readblock(unsigned long Rstartblock); unsigned char writeblock(unsigned long Wstartblock); private: unsigned char SD_reset(void); unsigned char SD_sendCommand(unsigned char cmd, unsigned long arg); unsigned char SPI_transmit(unsigned char data); };//end of class SDCARDclass extern SDCARDclass SDCARD; #endif inline void lastblocksave() { unsigned int e = 0; //the error code from the sd card e = SDCARD.

writeblock(currentblock); //save this 256 block of integer data while (e != 0) //cant continue if sd card not working { Serial. println("writesderror"); //send computer sd card error Serial. println(e); //send computer the error number digitalWrite(8, HIGH); //turn led on to show sd card error delay(10000); //every 10 seconds }//end of sd card not working currentblock +=1; //go to the next block in sd card EEPROM.

write(0, currentblock); //write the LSB of saved 🔗 External reference