Skip to content
Raspberry pi solar monitor. Monitoring Battery Voltage

Raspberry pi solar monitor. Monitoring Battery Voltage

    Solar Powered Raspberry Pi 4 Model B

    This is going to be easier than you thought (or at least much easier than I thought)! Today we will create a Raspberry Pi 4 Model B UPS PiJuice System that will be completely powered by a Solar Panel. It’s coming up to winter over here so I thought what better time to try to get this to happen before it completely sets in. We’re going green here at Core! So this guide will teach you exactly how to utilise solar panels on your next Raspberry Pi project to go portable and renewable. With the right solar panel, weather and battery you can create a project that will never stop running. But it is important to manage expectations when using solar panels. A couple of rainy days can throw your remote project into disarray and Raspberry Pis are power-hungry devices. This guide will be using a Raspberry Pi 4 Model B but keep in mind for remote projects where the extra processing power is not required (like a DIY Wildlife Camera project) would work better with a less power-hungry board like a Raspberry Pi Zero. Below is the contents of the guide. What You Will Need- Connecting PiJuice HAT and PiJuice Solar Panels to Raspberry Pi 4 Model B- Best PiJuice Settings for Solar Power and Utilising Different Battery Profiles- What Battery Should I Use- What Size Solar Panel Should I Use

    If you happen to be holding a Raspberry Pi board and not quite sure what it is? Then check out this guide Raspberry Pi Generations to identify it. Every Raspberry Pi Board can be powered by the Sun, you just need to find the right one for your project. Here is a number of potential Solar Panels that can be used with Raspberry Pi Boards. One of the swell aspects of the PiJuice HAT is that it can easily work with different battery types (the PiJuice Solar Panels supports both Li-Ion or Li-Po batteries) and sizes. Linked here is information on how big of a battery you should use depending on your Raspberry Pi, what it is doing and the amount of time you require for it to function. Also here are two fantastic guides, one will get you up to speed on the terminology of Li-Po Batteries and another will teach you how best to conserve battery life when building IoT projects. Here is a more advanced guide on how to save power on your Raspberry Pi by disabling features. As always if you have any questions, queries or things to add please let us know your thoughts!

    What You Will Need

    This has to be the simplest way to get up and running with a solar-powered system and a Raspberry Pi. Below is a list of what you will need Raspberry Pi 4 Model B: Worth noting PiJuice HAT and Solar Panels will work heaps of other Raspberry Boards as well PiJuice UPS HAT With Included Nylon Screws. SD Card with Raspberry Pi OS- PiJuice Solar Panel: I have decided to hook up the largest one available which can provide 40 Watts of energy. Keep in mind a Raspberry Pi 4 Model B pulls 3.4 Watts at Idle, so on a sunny day, this is overkill.- LiPo or Li-Ion Battery: For this, I use the 1820mAh battery that comes attached with the PiJuice HAT, however, you can attach many different batteries, click here or scroll down the page for a list of potential batteries. This means you can incorporate a very large battery into your system for example utilising a 12000mAh battery which will run an idling Raspberry Pi Zero for ~67 Hours.

    Only required for PiJuice settings such as safe shut-down at certain power or if a different battery is used creating a new battery profile Micro-HDMI to HDMI Cord and Monitor– Power Supply Via USB-C. Keyboard and Mouse

    Connecting PiJuice Hat and PiJuice Solar Panels to Raspberry Pi 4 Model B

    The first part of this process will seem very familiar to the UPS Raspberry Pi with PiJuice HAT guide as we will be installing the PiJuice HAT in the same manner. Make sure to line all the GPIO Pins up correctly and press the two boards together. The stand-offs come pre-assembled with the PiJuice the only thing to watch for is to take out the tiny slip of plastic separating the battery from the connectors and to also to use the four nylon screws supplied for the bottom of the board. See below for an image demonstrating this process and pointing out the tiny slip of plastic that you should remove. Now we will connect the Solar Panels to the Raspberry Pi. This is so easy it blows my mind. Literally, we are going to take the Micro-USB side and plug it directly into the power management board (the PiJuice HAT) and the USB side directly into the PiJuice Solar Panel. If you are using a different solar panel there may be different connectors and systems required to hook up the Raspberry Pi to the Solar Panel. A great reference point to check out what connector you have can be found here and a very cool guide on using Solar LiPo Chargers and how Solar Panels work found here. But that all seems too complicated when the Brits have taken the time to make it so easy for us with this PiJuice System. See below for the system all hooked up and ready to go. Once this is done you have succeeded in creating your Solar Powered Raspberry Pi 4 Model B Board. It is that easy! No faffing around with extra componentry. So slide in that micro-SD card with Raspberry Pi OS (link here to a tutorial on how to flash a Micro-SD with Raspberry Pi OS) and then press the button indicated in the picture below. So if you put the solar panel in the sun right now and keep the system on it will go right ahead and function as it should. The sun will literally start charging the battery and the PiJuice will power the Raspberry Pi. Astonishing. Also, this won’t be explored deeply in this tutorial but for those who will and want to know the process of physically connecting a new battery to the PiJuice system the best guide to learning exactly how to do this can be found here. Keep in mind you will also need to adjust the PiJuice Settings by altering the battery profile so the system is aware of this different battery and optimised appropriately. Below you can see a different battery connected to the PiJuice system (note that you must remove the default 1820mAh battery to do this).

    Now that we have connected all the components we will alter some settings of the PiJuice HAT so that we can get the best out of our Solar Powered System. As it stands right now the system will continue until it runs out of electricity. This puts the micro-SD card at risk of being corrupted as the system is not shutting down safely so let us add a safeguard using the inbuilt PiJuice settings. The easiest way to get started is by plugging in a mouse, keyboard and monitor. Then turning the system on you will be welcomed by that familiar Raspberry Pi OS background. Now we can install the PiJuice Settings (if you haven’t already) to Raspberry Pi OS. For a really in-depth step-by-step process of Installing PiJuice Software to Raspberry Pi OS check out this guide. The gist of it is to power up your Raspberry Pi like normal with it connected to a monitor, open up Raspberry Pi OS, connect the system to the internet, click on the Raspberry Terminal button to open the Console and type the following into the terminal. sudo apt-get install pijuice-gui Then once you press enter it will run an installer that will take less than 5 minutes to complete. Then once you safely restart the system you will be able to find the PiJuice settings in two separate locations as you can see below. Clicking on one of these buttons to open up the PiJuice Settings Menu lets now set it up to switch off automatically once it gets to 10% power. This we can do in the System Task Tab, see the image below, by ticking the Minimum charge and then typing in 10 as the Threshold amount. So if your devices ever goes underneath 10% of charge the system will turn itself off automatically. So if there is a day or two without sun or for whatever reason the Raspberry Pi will be able to shut down safely remotely. But say there was a sunny day and we wanted to have the system come back alive (for instance if this was a remotely set up birdwatching camera that we would only check on once a month) then we can incorporate a wakeup on charge. This is done in a similar manner by selecting the tick on the Wakeup on charge setting and then adding a trigger level, lets say for this at 90% it will turn itself back on. Then making sure to click Apply these settings are now locked in. Brilliant. Also if you have installed a different battery take the time to change the battery profile so that you can have optimal functionality. This can be done in the PiJuice HAT Configuration Window and then navigating to the Battery Tab which you can see below. This is a great guide to follow as it goes through the process of connecting the wires correctly and changing the battery profile which can be found in the PiJuice Settings. The following lithium polymer batteries sizes all have profiles already set up for PiJuice however you can easily create custom profiles to suit different battery sizes.

    • 12000mAh
    • 5000mAh
    • 1200mAh
    • 1000mAh (Pi Zero)
    • 600mAh
    • 500mAh

    What Size Battery Should I Use

    Setup Raspberry Pi for a Solar Power Monitoring Kiosk

    Now it can quickly become complicated figuring out what the best battery solution is for you. The best easy and most readily understood resource that I have found is the Official PiJuice Battery Discharge Time Calculator. This will hugely help you decide what battery to use depending on your Raspberry Pi, what it is doing and the amount of time you require for it to function. Also of very high value is this guide which delves into the terminology of these batteries so you absolutely choose the best LiPo Battery for your next project.

    Polling the API

    Pulling data from the gateway API is simple enough.

    raspberry, solar, monitor, monitoring

    In [1]: from tesla_powerwall import Powerwall. import OS pw = Powerwall(powerwall). pw.login(OS.environ.get(PW_PASS)). meters = pw.get_meters.

    This gives me a Powerwall object and a meters object. I can get things like the total system charge percentage:

    In [2]: pw.get_charge Out[2]: 72.48223386691551

    Meters are how you look at power flow through the system. You can get them at four points: solar, load (consumed by the house), site (to and from the grid), and battery. Here’s one:

    Let’s look at how to get this data into New Relic One and what to do with it.

    Pushing data to New Relic One

    New Relic One takes a number of data types: metrics, events, logs, and traces. There are a number of ways to send data into New Relic One, but the one I went with is a simple requests.based submission using the Metric API. For this script, I used the Metric API to report this data as metrics, which have 13-month retention. There’s also a Telemetry SDK with a Python library and maybe I’ll use that next time I write something.

    The data took quite a bit of massaging but in the end here’s the block I send to New Relic One:

    raspberry, solar, monitor, monitoring

    , ‘’: 60000, ‘timestamp’: 1638985517585, ‘metrics’: [. ]

    As you can see, this is a dictionary with two top-level items: common and metrics. common is data that is, well, common to each metric, and the metrics themselves are dictionaries of name/type/value. My metric type is always gauge. but there are others.

    Creating a custom dashboard in New Relic

    Once I could push data to New Relic, I turned my attention to dashboards. I have three kinds of data to work with:

    • Data from the solar API. This is the bulk of what I send and is mostly real-time power generation, consumption data, and the battery charge level as well as some historical data on the total amount of power to and from various points in the system. The data isn’t terribly accurate so the numbers don’t always add up, but they’re pretty decent.
    • Data I get from the free API at OpenWeather: estimated Cloud coverage percentage, sunrise and sunset times, temperature, and a string description of the weather so I can avoid looking out the window that’s literally right behind my monitor and directly in my line of sight.
    • Data I munge on my server before sending it over to New Relic. This is stuff like whether the sun is up, which is useful if I want to make any sort of predictions about how much power I should be drawing on a given day. If it’s before sunrise or after sunset, the answer is none.

    I might also add Solcast to see if I can get daily solar radiation data. One big advantage of New Relic One over the Tesla app is that I can pull in data from other sources. Maybe I’ll get a sense monitor and see how that works.

    Here’s what it all looks like.

    This is cool. Do you have any idea how long it would take me to make something like this out of python, pandas, and matplotlib? A while. And it would look like garbage. New Relic One is much, much better.

    I find myself staring at the dashboard like it’s a new baby, watching it breathe and marveling that it exists. It just works. It’s really nice to have this data and be able to get to it anywhere without having to run a container on a server in my house and port-forward to it or VPN into my home network.

    I’ve also got an alert when the batteries drop down below their reserve percentage, which would indicate that my house has lost power and the batteries are running low. New Relic has a whole lot of things I could fiddle with.

    My custom solar monitoring system (PVS6)

    I’ve been tinkering with monitoring my solar system and have come to a fairly nice useful setup. Time for a post documenting where I am. The details on how I did all this are in previous blog posts but I’m summarizing here. Some code in this gist.

    The daily view is focused on giving me a basic picture of my electricity usage. Green is production for the day, black is the PVS6 measurement of net (ie: production – consumption). Yellow is PGE’s own view of net. I suspect PGE’s data may be more correct; I’m not sure if the PVS6 CT sensors measure reactive loads correctly. Doesn’t much matter anyway; PGE is the authority whether they are right or wrong. Mostly I just care that they are close. (Jan 7 is a data measurement anomaly.)

    This view gives a lot of detail minute by minute. The top panel is a detailed view of production and consumption, what is a single bar in the daily graph. The second graph compares production to a forecast. Below that are details of individual panel production. The individual sparklines towards the bottom are fun; the panel in the upper left goes to 0 in the morning in the shadow of the chimney on my roof. At the bottom is a simple sparkline of lifetime net production, I had a little party when it passed 1MWh.


    The data import code is all in this gist. The Grafana panels are not shared anywhere, sorry.

    Here’s all the places I’m pulling data.

    • PVS6: the Sunpower solar monitoring system
    • PGE: manual downloads via their “Big Green Button”
    • Predictions:

    The whole system is built with Telegraf collecting the data into an Influx database and a Grafana dashboard to visualize it. What a great set of tools those are! A real pleasure to learn and work with.

    The PVS6 stuff is the bulk of it. Turns out Sunpower has a JSON endpoint on a web server in your PVS6 and folks have worked out how to interpret the data. It’s pretty hacky; I’m using a Raspberry Pi to proxy the data onto the rest of the network. I’ve written a ~200 line Python script to collect the JSON data from the PVS6 every minute and emit it in Influx wire format for import. It also does a little analysis within the minute’s dataset to facilitate easier graphing.

    The PGE import is a very simple bit of Python code that converts PGE’s data into Influx. I have to do this download by hand in the website right now. They do have an API but it requires some sort of signup I haven’t tried to do yet. I should add that PGE’s Big Green Button CSV export is really quite good. The CSV data is clean and simple. And they have history! I was able to get 9 years of this house’s electricity usage. Nicely done.

    The import is also very simple. They have a easy-to-use API where you tell them your location and the size and orientation of your solar system. Then they give predictions for power generated, including weather-corrected. The free version of the API is fine for this use; I download a new prediction every six hours.

    Next steps

    I plan to keep tinkering with the data display. I suspect as time goes on I’ll be more interested in the daily summaries than the per minute view, so I’ll probably pay more attention to that.

    It’d be nice to automate the PGE data download.

    I’ve had some thought about packaging this all up as a Raspberry Pi image. I think the whole thing could run on pretty much any flavor of RPi, it’d be like an add-on to the PVS6 with a nice local web dashboard. But that’s a lot of work and I have zero interest in offering a product that uses an unauthorized Sunpower interface. Sunpower has a fairly decent monitoring website with something much like my daily summary view. They also have tools for installers showing per-minute data. Those aren’t available to end consumers, I think on purpose, and I suspect they would not be thrilled by me offering a competing product.

    raspberry, solar, monitor, monitoring

    rd Party Pi Management Boards

    Since we first wrote this guide, several products have come on the market to help manage Raspberry Pi’s power consumption.

    Witty Pi 2 by UUGear: This product adds a real-time clock and power management to the Pi. UUGear has even written a tutorial to create a Pi-based time-lapse camera using our 6 Watt solar panel and V15 Battery Pack with Always On mode. Sleepy Pi 2 by Spell Foundry: We have at least one customer using this board for Smart power management of the Pi, but no solar tutorials just yet.

    Sizing your Solar Panels

    It may be useful to briefly compare the power consumption of different Raspberry Pi boards so you can appropriately size your panels.

    Solar Log: Real-Time Battery Voltage

    Raspberry Pi Model A and Model B

    Note: Every Pi script is different, therefore they all have different power requirements based on the additional accessories and sensors. The numbers presented here are approximations based on power consumption averages with no additional components. The best way to know how much power your Pi board actually uses is to monitor the voltage and current with a USB amp-meter from the battery or some other method.

    Multiply the current by the voltage (USB power supplies are 5V) and by the number of hours you plan on running the Pi and you’ll have your daily power consumption in Watt-hours. This is the benchmark from which you’ll compare the output from the solar panels you are interested in. Multiply the rated wattage of the panel by the number of hours of sunshine you think you’ll receive each day and then discount for power loss along the chain by 40%. For example, if you think you’ll have bright sunshine for 6 hours per day, the 9W panel will produce 32 Watt-hours.

    There are a lot of variables, but we generally recommend choosing a panel size that produces, on a good day, 2-3 times as much power as you think you’ll need on a daily basis. If you so if you are using the Pi model B and your unique project requires 40Wh per day, we recommend using enough solar panels to generate at least 80Wh per day (equivalent to the 18W Charging Kit exposed to 4.5 hours of sun). This is why it’s critically important to reduce power consumption!

    Remember! Don’t only count the number of hours the sun is in the sky, count the number of hours the sun is pointed directly at the solar panels. If there are trees or buildings that cast shade over your project for certain hours of the day, that shortens the amount of time the panels are pointed directly at the sun.

    Solar Power for Raspberry Pi: Conclusion

    With the appropriate software built into the Raspberry Pi to protect itself and some medium-large solar panels your Raspberry Pi project can live on indefinitely. Combining a Raspberry Pi with an Arduino can add many benefits to your project, such as safety and extended battery life during bad weather, though it is certainly not necessary.

    If you can accomplish your project goals without using a Raspberry Pi at all (perhaps by using a BeagleBone or Arduino) it may be in your best interest to do so because of the technical obstacles presented here (high power consumption, risk of corrupting the SD card). Though if you are already very familiar with Raspberry Pi’s or want to use some of the powerful RaspiConnect interfaces to track your data in real time, then it is certainly possible to sustain your project with solar power.

    For more on remote systems, check out our solar powered Arduino guide.

    Leave a Reply

    Your email address will not be published. Required fields are marked *