Electronic Time Capsule: Difference between revisions
No edit summary |
No edit summary |
||
Line 30: | Line 30: | ||
* https://github.com/Marzogh/SPIMemory - for using the external flash memory chip that stores the measurements | * https://github.com/Marzogh/SPIMemory - for using the external flash memory chip that stores the measurements | ||
* The SparkFun BME280 library - For configuring the BME280 sensor | * The SparkFun BME280 library - For configuring the BME280 sensor | ||
==Build Instructions== | |||
* Make the board and assemble the components onto it. Everything is surface mount except the sensor board, which is an Aliexpress special. | |||
* Flash the 328 on the board with the Arduino MiniCore bootloader. Make sure that the BOD is disabled, and the 8 mhz clock speed is selected. I tried 1 mhz as well, but found that the flash chip did not work well at this speed. The 328 can be programmed with ICSP, just like flashing a normal Arduino. The reset line, VCC and ground pins are brought out on the outside 5 pin header. The remaining SPI pins needed for ICP can be connected to either some test points on the board, or by clipping onto the legs of the flash chip. | |||
* The board can now be programmed with a usb-serial adapter like any other arduino board. The tx and rx pins on the board connect to the rx and tx pins on the usb-serial device. The reset pin on the board connects through a 0.1uf cap to the DTR pin on the usb-serial, because I didn't include one on the board. Upload the main program. | |||
* Push switches 1 (clock set) , 2 (flash erase) and 4 (status) on, and connect the board to a serial monitor and power (between 4 and 15 volts). | |||
* Use the single button to set the clock following the serial terminal instructions. For example, to set the first parameter, the year, to 2018, press the button repeatedly until 18 is shown, then wait 2 seconds to continue. | |||
* Erase the flash by pressing the button once when prompted. | |||
* Return all dip switches to off position. Switch 4 can be left on, which will blink the green led whenever the 328 is powered up, but can be turned off to save power. | |||
* After data is collected, turn switch 3 on and press the button. The data will be output over serial in the form of a table. | |||
==Example Output== | ==Example Output== |
Revision as of 21:52, 5 September 2018
This is a board with a bme280 pressure, humidity and temperature sensor, a ds3232m realtime clock, and 4MB of flash memory. The clock wakes up an atmega328p, it takes readings and stores them, and then goes back to sleep. A low dropout, low quiescent current voltage regulator provides 3.3v power to the board from an external battery.
I built this to be buried inside a time capsule (though it has plenty of other uses), so it has to be able to survive freezing temperatures, and should last at least 5 years without maintenance. A quick calculation of current draw on my prototype says that it should be able to run for about 15 years (!) on AA batteries, and there is plenty of room in the flash memory for hourly measurements (15ish years worth).
Sensor List
- BME280 board measuring temperature, humidity and pressure.
- DS3231M measuring time, and temperature
- Optional voltage divider to measure battery voltage
Interface Description
The board contains 4 dip switches, which pretty much work independently, and one button. The switches should be labeled 1-4, with 1 being closest to the center of the board. The off position of the switch has the handle toward the 3 indicator LEDs, and the on position is towards the button.
The functions of the switches are:
- Switch 1 (on) - Enters the clock setting procedure. The clock is set using only the single button, pressed a number of times to set the date and time. You can only set the clock when the board is first connected to power or reset.
- Switch 2 (on) - Erases the flash chip. The flash must be empty to write new data from the beginning. An extra button press is needed to confirm you really want to do this. If the clock set switch is also on, then you will set the clock first, then erase the flash. You can only erase the flash when the board is first connected to power or reset. This helps avoid doing it accidentally.
- Switch 3 (on) - Dumps the flash. Over serial, the board will output a tab-formatted table of the measurements that have been recorded. The dump will continue until either the entire chip has been read (including blank areas), or Switch 3 has been turned off. To start a dump, turn switch 3 on and then either wait for the RTC to wake up the system, or wake it up yourself with a single press of the button.
- Switch 4 (on) - Blinks a green light every time the 328 powers up. Turn off to save power
The LED functions are, in general:
- Green - Status - Blinks when something happens / has happened
- Red - Working - Turns on when user input is acknowledged
- Yellow - Waiting for user input
Software Libraries used
The following software was used in the program for this device:
- Arduino MiniCore hardware package. The board is programmed like a normal arduino board with the arduino bootloader, but this package makes it easier to get a bare 328 chip working with many of the power-heavy features disabled.
- avr/power, avr/sleep, Wire, SPI arduino libraries, included with the arduino IDE.
- https://github.com/Marzogh/SPIMemory - for using the external flash memory chip that stores the measurements
- The SparkFun BME280 library - For configuring the BME280 sensor
Build Instructions
- Make the board and assemble the components onto it. Everything is surface mount except the sensor board, which is an Aliexpress special.
- Flash the 328 on the board with the Arduino MiniCore bootloader. Make sure that the BOD is disabled, and the 8 mhz clock speed is selected. I tried 1 mhz as well, but found that the flash chip did not work well at this speed. The 328 can be programmed with ICSP, just like flashing a normal Arduino. The reset line, VCC and ground pins are brought out on the outside 5 pin header. The remaining SPI pins needed for ICP can be connected to either some test points on the board, or by clipping onto the legs of the flash chip.
- The board can now be programmed with a usb-serial adapter like any other arduino board. The tx and rx pins on the board connect to the rx and tx pins on the usb-serial device. The reset pin on the board connects through a 0.1uf cap to the DTR pin on the usb-serial, because I didn't include one on the board. Upload the main program.
- Push switches 1 (clock set) , 2 (flash erase) and 4 (status) on, and connect the board to a serial monitor and power (between 4 and 15 volts).
- Use the single button to set the clock following the serial terminal instructions. For example, to set the first parameter, the year, to 2018, press the button repeatedly until 18 is shown, then wait 2 seconds to continue.
- Erase the flash by pressing the button once when prompted.
- Return all dip switches to off position. Switch 4 can be left on, which will blink the green led whenever the 328 is powered up, but can be turned off to save power.
- After data is collected, turn switch 3 on and press the button. The data will be output over serial in the form of a table.
Example Output
This is what it looks like when running / dumping measurements in the serial terminal.
TIME CAPSULE LONG DURATION ENVIROMENTAL LOGGER - Alan J. WIlson 2018 Current time: 00/01/01 00:51:57 Flash capacity: 4194304 bytes, 131072 frames Frame size: 32 Next ram index: 13159 Current time: 00/01/01 00:52:02 Cycle: 0 Index: 13159 Battery ADC: 0 DS3231 Temperature (C): 25.25 BME280 Temperature (C): 25.29 BME280 Pressure (Pa): 99076.30 BME280 Humidity (%): 69.27 Write OK FLASH MEMORY DATA DUMP FOLLOWS Index Cycle Year Month Day Hour Minute Second DS3231 Temperature (C) Temperature (C) Pressure (Pa) Humidity (%) Battery (10-bit ADC) 0 0 18 8 26 18 13 12 28.00 25.93 98721.45 56.25 0 1 1 18 8 26 18 14 10 27.25 26.69 98700.82 51.92 0 2 2 18 8 26 18 15 10 26.25 26.62 98697.11 51.89 0 3 3 18 8 26 18 16 10 26.00 26.08 98680.39 51.73 0 4 4 18 8 26 18 17 10 25.50 25.72 98682.92 52.41 0 5 5 18 8 26 18 18 10 25.25 25.43 98677.75 52.36 0 6 6 18 8 26 18 19 10 25.00 25.13 98676.18 52.90 0