- 3D Print a Base for Your RPi and Pi-Plate
- LAN/WiFi Speaker Switch
- Solar Powered Remote Environmental Data Logger
- Raspberry Pi HQ Camera Mount
- Using a THERMOplate to Measure Temperatures on the RPi4
- Making Sparks with Pi-Plates
- Dual Syringe Pump
- Cigarbox Pi
- Benchmarking the Pi 3
- Turn Your Raspberry Pi into a Network Monitoring Tool
- Using Pi-Plates with the Raspberry Pi 400
Table of Contents
Introduction
Before construction begins on a new building site, an environmental impact assessment is often performed. This can include a biological survey as well as periodic measurements of physical properties and weather phenomena over a predetermined duration. Some of the data collected can include temperature, wind speed and direction, humidity, soil characteristics, barometric pressure, and solar energy just to name a few. Once collected, these measurements can be transmitted to a remote computer or a cloud service via a cellular modem, point to point radio, or even a satellite link for real time assessment. Or the data can be stored locally and evaluated at a later time.
Often these can be new sites in remote locations where it is highly unlikely that a source of power will be available. For those situations, a low power solution combined with a solar energy source can be an ideal solution. To address this scenario, we built a simple environmental data logger based on a Raspberry Pi 4. If you're familiar with the 4 then you know that it can consume quite a bit of current which might seem contradictory to our requirements. But, by using the power scheduling feature on the Pi-Plate POWERplate, we dramatically reduce the average energy consumption by periodically turning on the RPi, collecting and saving the required data, and then shutting off again.
Another problem with a remote "off the grid" environmental logger is that there is likely no internet. Without an internet connection at power up, the Raspberry Pi has no way of setting the clock. And without a clock, the data logger cannot assign an accurate time stamp to the measurements. Fortunately, the POWERplate has a Raspberry Pi compatible battery backed real time clock (RTC) on board to address this problem.
In the project that follows, we describe a simple solar powered remote environmental data logger based on an RPi4, a POWERplate, and a THERMOplate.
Parts Used
- Solar power system panel and energy controller from Amazon.
- 12V sealed lead-acid battery for night time operations from Amazon.
- A waterproof enclosure.
- A POWERplate
- A THERMOplate
- A DINplate
- Four type K Thermocouples
- A USB cable that terminates with a microB connector
- A piece of DIN rail to hold the Pi-Plate stack inside the enclosure.
- A Raspberry Pi 4 with the RPi OS installed on the microSD card.
Assembly
A block diagram of our assembly is shown below. As can be seen, there are 5 major components:
- the Pi-Plate stack sandwiched inside of a DINplate
- the sensors
- The battery
- the power controller
- and the solar panel
And these are the build steps we followed:
- Connect the solar panel and the battery to the energy controller. The controller comes with a set of clamps for the battery which we thought were overkill so instead we made some simple cables that had crimped-on FastOn connectors for the battery and were stripped on the other end for the controller.
- Assemble your Pi-Plate stack in the DINplate making sure to place the POWERplate directly over the Raspberry Pi.
- Attach thermocouples to the inputs on the THERMOplate
- Prepare the enclosure by screwing the DIN rail to the back and drilling out a hole on the side for the sensors. To be truly waterproof, you may want to use a liquid tight cord grip for your wires like these sold by Heyco.
- Snap the DINplate tabs onto the DIN rail next to the hole and position the battery and controller on the other side of the Pi-Plate stack.
- Route the thermocouples through the hole on the side of the enclosure.
- Route a cable between one of the USB connectors on the front of the power controller and the microB connector on the side of the POWERplate.
- Tuck excess wires between the wall of the enclosure and the battery.
Code
It might be easier to set up the code on your desktop before mounting the RPi inside of the case.
- Follow the directions in the POWERplate documentation to:
- setup the Real Time Clock
- setup the power switch
- modify the /etc/rc.local file to ensure that our program runs at powerup (our program is called "envLogger.py" and it is located in the /home/pi directory)
- Place the script shown below into your home directory (/home/pi)
- Make any changes you need for your particular sensor and/or sample rate requirements
- Once your code is final, delete all old log files
- Hold the power switch for a few seconds to power down the RPi and any attached Pi-Plates. When the shut down is complete, the LED on the POWERplate will be red.
- Once the HW is set up and ready, press the power button for a few seconds to start the logger. The POWERplate will now periodically wake the RPi, run the logging script, and shut down when completed.
- To stop the logger at any time, press the power button for a few seconds.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
#!/usr/bin/env python # Before running this the first time: # 1) Make sure that the line "dtoverlay=gpio-shutdown,gpio_pin=24" # has been added to the end of the /boot/config.txt file. # Otherwise the power button won't work. # # 2) Follow the documentation to set up the Real Time Clock # # 3) Run "sudo nano /etc/rc.local" from the command line and # add the line "(python3 /home/pi/envLogger.py) &" at the end # of the file before the "end" statement and save. import os import time import datetime import piplates.THERMOplate as THERMO import piplates.POWERplate as POW minDelta=10 #use a 10 minute delta between measurements header='Date,Time,Air,Water,Soil,Cabinet\n' #Create header for CSV log file logfile='/home/pi/envData.csv' #This will be the file name of our data log - note that we use the full path name ###################################################################################### # nextWake(minutes) - this routine takes an argument with units of minutes and # adds it to the current time. This value is then sent to # the POWERplate for the next wake up time. ###################################################################################### def nextWake(dT): cTime=time.localtime() #get the current time hr=cTime.tm_hour #and extract hours, minutes, and seconds min=cTime.tm_min # sec=cTime.tm_sec # min=(min+dT) #add the incremental time if (min>=60): #if greater than 60 then fix min=min-60 # hr=hr+1 #increment hour and fix if it turns out to be 24 if (hr>=24): hr=hr-24 POW.setWAKE(0,hr,min,sec) #set next wakeup time on the POWERplate # Check source of powerup. If not caused by wakeup function AND a logfile exists then exit the program. # This will prevent corrupted log data and prevent the POWERplate from shutting the RPi off. if (POW.getWAKESOURCE(0)!=2): #If the powerup cause is not a scheduled wakeup if (os.path.exists(logfile)): #AND if the logfile exists exit() #then exit. f=open(logfile,"a") #open our log file if (os.stat(logfile).st_size==0): #if this is the first time running this script f.write(header) # then write the header to the log file, POW.ledMODE(0,1) # set the LED mode to blink to reduce power consumption, POW.fanOFF(0) # turn off the fan to reduce power consumption, POW.enablePOWERSW(0) # and enable the power switch if it isn't already set. #Collect and save time and temperature readings from the THERMOplate currentDT = datetime.datetime.now() # get current time structure #collect temperature values, convert to strings and append commas where applicable. air=str(THERMO.getTEMP(0,2))+',' h20=str(THERMO.getTEMP(0,1))+',' soil=str(THERMO.getTEMP(0,3))+',' cab=str(THERMO.getTEMP(0,4)) #Create data string data=currentDT.strftime("%m/%d/%Y,%H:%M:%S,")+air+h20+soil+cab+'\n' f.write(data) #save data to log file f.close() #close the log file nextWake(minDelta) #schedule the next wakeup time POW.enableWAKE(0) #renable the wakeup mode POW.powerOFF(0) #tell the POWERplate to shutdown |
Results
We placed our Solar Powered Remote Environmental Data Logger next to a lake and positioned thermocouples in the water, ground, air, and inside the cabinet. We pushed the power button, closed the door and left it for a couple of days. We then retrieved it, imported the CSV-formatted data file into LibreOffice Calc on the RPi, and plotted the data: