<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[Aaron Torchn]]></title><description><![CDATA[Aaron Torchn]]></description><link>https://torchnaaron.hashnode.dev</link><generator>RSS for Node</generator><lastBuildDate>Sat, 21 Nov 2026 18:29:54 GMT</lastBuildDate><atom:link href="https://torchnaaron.hashnode.dev/rss.xml" rel="self" type="application/rss+xml"/><language><![CDATA[en]]></language><ttl>60</ttl><item><title><![CDATA[How I check whether a PV string will over-voltage the charge controller on a cold morning]]></title><description><![CDATA[A charge controller that runs happily in August can refuse to start, or worse, take damage, on a clear January morning. The reason is usually not a mystery…]]></description><link>https://torchnaaron.hashnode.dev/pv-string-cold-voltage-mppt-check</link><guid isPermaLink="true">https://torchnaaron.hashnode.dev/pv-string-cold-voltage-mppt-check</guid><category><![CDATA[Python]]></category><category><![CDATA[solar]]></category><category><![CDATA[Electronics]]></category><dc:creator><![CDATA[Aaron Torchn]]></dc:creator><pubDate>Sat, 21 Nov 2026 01:07:43 GMT</pubDate><content:encoded><![CDATA[<p>A charge controller that runs happily in August can refuse to start, or worse, take damage, on a clear January morning. The reason is usually not a mystery load. It is string voltage. Cold solar cells produce a higher open-circuit voltage than the number on the datasheet, and that number was measured at 25 °C. I check this before the array is landed on the roof, not after the first frost.</p>
<h2>What actually rises in the cold</h2>
<p>The figure that matters is the module's open-circuit voltage, Voc, and its temperature coefficient, usually listed as a negative percentage or in mV per °C. As the cells get colder, Voc climbs. The current drops a little, but the voltage is the one that can cross a limit.</p>
<p>The controller, or the MPPT input on an all-in-one unit, has a hard maximum voltage. Above that, protection may trip, or the input can be damaged. The check is simple in principle: estimate the highest string Voc you will ever see, and keep it below that limit with a margin.</p>
<h2>A worked example (numbers are examples only)</h2>
<p>Suppose each module is rated Voc 49.6 V at 25 °C, with a coefficient of −0.27%/°C. You plan four modules in series. The coldest morning you design for is −10 °C, which is 35 °C below the rating temperature.</p>
<p>The fractional rise is 35 × 0.27% = 9.45%. Each module's cold Voc is about 49.6 × 1.0945 ≈ 54.3 V. The string is 4 × 54.3 ≈ 217 V.</p>
<p>If the controller's maximum input is 200 V, this string is already over. If the maximum is 250 V, you have some room, but I still like a margin of at least 5–10%, because datasheet coefficients are typical values, and a very clear, still morning can be colder than the air temperature you planned for. Cells can sit below ambient just before sunrise.</p>
<p>A short way to repeat the arithmetic, if you like to check it in Python:</p>
<pre><code class="language-python">voc_stc = 49.6          # V, example only
coeff = -0.0027         # per °C, example only
t_min = -10             # °C, example only
n_series = 4
voc_cold = voc_stc * (1 + coeff * (t_min - 25))
print(round(voc_cold * n_series, 1))
</code></pre>
<p>That prints 217.1, the same estimate as above. Change the inputs to the figures on your own datasheets.</p>
<h2>How I use the result</h2>
<p>If the cold string voltage is too close to the limit, I do not hope the mornings are milder. I change the wiring: fewer modules in each series string, and more strings in parallel, so the voltage comes down and the current goes up. Then I check that the controller's maximum input current still covers the parallel combination, and that the cable and fuse sizes still fit.</p>
<p>I also check the other end of the window. In hot weather the voltage falls. A string that is only just above the MPPT start voltage in a datasheet at 25 °C can drop out of the window on a hot roof. The cold-morning check and the hot-afternoon check are two halves of the same job.</p>
<h2>Where I look the numbers up</h2>
<p>The module Voc and coefficient come from the module datasheet, not from a sales sheet that only lists wattage. The limit comes from the controller or inverter manual, the "maximum PV open-circuit voltage" line, which is not the same as the MPPT operating range. If you want a longer <a href="https://solarenergystoragesystem.com/en/blog/mppt-input-voltage-too-high-off-grid-solar">walkthrough of string voltage and MPPT input limits</a>, that page works through the same cold-weather arithmetic. Wiring diagrams and string examples are also collected at <a href="https://solarenergystoragesystem.com/en/design-library">https://solarenergystoragesystem.com/en/design-library</a>.</p>
<p>Do the sum on paper or in a script, and write the assumed temperature next to it. Keep that sheet with the as-built notes.</p>
<hr />
<p><em>Disclosure: I work with TORCHN. Yangzhou Weikechuang handles export trade and projects, and Yangzhou Dongtai handles production; both share the TORCHN brand.</em></p>
]]></content:encoded></item><item><title><![CDATA[Logging battery SOC from an RS485 BMS with Python, then finding out what the data says]]></title><description><![CDATA[A small Python logger that polls a battery BMS over Modbus RTU, writes CSV, plus a pandas script for daily SOC, cycles and imbalance alerts.]]></description><link>https://torchnaaron.hashnode.dev/log-bms-soc-modbus-python</link><guid isPermaLink="true">https://torchnaaron.hashnode.dev/log-bms-soc-modbus-python</guid><category><![CDATA[Python]]></category><category><![CDATA[modbus]]></category><category><![CDATA[data analysis]]></category><dc:creator><![CDATA[Aaron Torchn]]></dc:creator><pubDate>Fri, 20 Nov 2026 01:42:11 GMT</pubDate><content:encoded><![CDATA[<p>Most solar batteries know far more about themselves than their owners ever see. The BMS tracks state of charge, pack voltage, current, temperatures and individual cell voltages, and it will usually hand them over on an RS485 or CAN port. The inverter reads a few of those values and shows a percentage on its screen. Everything else disappears.</p>
<p>I wanted a simple way to log battery SOC with Python on remote sites, keep the raw data as CSV, and answer three questions later: how deep does the battery go each night, how many cycles is it really doing, and are the cells drifting apart? This post is the minimal version of that setup. It runs on a Raspberry Pi or any old laptop.</p>
<h2>A warning before the code</h2>
<p>There is no universal BMS register map. Some batteries speak Modbus RTU over RS485, many use a vendor protocol on the same wires, and others only expose CAN for the inverter. Register addresses, scaling and even byte order vary by manufacturer and firmware.</p>
<p><strong>The register map below is an example only.</strong> It is not the map of any particular product. Get the real protocol document from your battery supplier and change the table at the top of the script. If the battery uses a non-Modbus protocol, the logging and analysis parts still apply; only the read function changes.</p>
<p>Also: if the inverter is already talking to the BMS on that port, don't add a second master on the same bus. Use a separate monitoring port if the battery has one, or read the values from the inverter instead.</p>
<h2>What you need</h2>
<ul>
<li>A USB-to-RS485 adapter (two wires, A and B, plus ground if the port provides it)</li>
<li>Python 3.9 or newer</li>
<li><code>pip install minimalmodbus pandas</code></li>
<li>The battery's protocol document: slave address, baud rate, register addresses and scaling</li>
</ul>
<h2>Part 1: the logger</h2>
<p><code>minimalmodbus</code> is small and its API has been stable for years, which matters on a box nobody will touch for months.</p>
<pre><code class="language-python"># bms_logger.py  — poll a BMS over Modbus RTU and append rows to a CSV.
# REGISTER MAP IS AN EXAMPLE ONLY. Replace with your battery's protocol document.
import csv, time, datetime as dt
import minimalmodbus

PORT, SLAVE_ID, BAUD = "/dev/ttyUSB0", 1, 9600
INTERVAL_S = 60

# name: (register address, scale, signed)
REGS = {
    "pack_v":   (0x0000, 0.01, False),   # volts
    "current_a":(0x0001, 0.01, True),    # + charge / - discharge
    "soc_pct":  (0x0002, 1,    False),
    "temp_c":   (0x0003, 0.1,  True),
    "cell_max_mv": (0x0004, 1, False),
    "cell_min_mv": (0x0005, 1, False),
}

bms = minimalmodbus.Instrument(PORT, SLAVE_ID)
bms.serial.baudrate = BAUD
bms.serial.timeout = 1.0

def read_all():
    row = {"ts": dt.datetime.now().isoformat(timespec="seconds")}
    for name, (addr, scale, signed) in REGS.items():
        raw = bms.read_register(addr, 0, functioncode=3, signed=signed)
        row[name] = round(raw * scale, 3)
    return row

with open("bms_log.csv", "a", newline="") as f:
    w = csv.DictWriter(f, fieldnames=["ts", *REGS])
    if f.tell() == 0:
        w.writeheader()
    while True:
        try:
            w.writerow(read_all()); f.flush()
        except (IOError, ValueError) as e:      # timeouts, CRC errors
            print("read failed:", e)
        time.sleep(INTERVAL_S)
</code></pre>
<p>A few practical notes from running this kind of script in the field:</p>
<ul>
<li><strong>One-minute polling is plenty.</strong> SOC moves slowly. Faster polling just makes larger files and more bus traffic.</li>
<li><strong>Log raw readings, analyse later.</strong> Don't compute anything clever in the logger. If the scaling turns out to be wrong, you can fix it in the analysis and keep the data.</li>
<li><strong>Expect gaps.</strong> Serial reads fail occasionally. The <code>try</code> block keeps the logger alive, and the analysis below copes with missing rows.</li>
<li><strong>Run it as a service.</strong> A systemd unit with <code>Restart=always</code> brings it back after a power cut.</li>
</ul>
<h2>Part 2: what the data says</h2>
<p>After a few weeks you have tens of thousands of rows. Here is the analysis script I use, built around pandas.</p>
<pre><code class="language-python"># analyse.py — daily summary from bms_log.csv
import pandas as pd

NOMINAL_AH = 100          # example only: your battery's rated capacity
IMBALANCE_MV = 50         # example alert threshold, check the BMS manual

df = pd.read_csv("bms_log.csv", parse_dates=["ts"]).set_index("ts").sort_index()

# Integrate current over time (Ah). Gaps longer than 5 min are not integrated.
dt_h = df.index.to_series().diff().dt.total_seconds().div(3600)
dt_h = dt_h.where(dt_h &lt; 5/60, 0)
df["ah"] = df["current_a"] * dt_h
df["delta_mv"] = df["cell_max_mv"] - df["cell_min_mv"]

daily = pd.DataFrame({
    "soc_min":    df["soc_pct"].resample("D").min(),
    "soc_max":    df["soc_pct"].resample("D").max(),
    "ah_out":     -df["ah"].clip(upper=0).resample("D").sum(),
    "ah_in":      df["ah"].clip(lower=0).resample("D").sum(),
    "temp_max":   df["temp_c"].resample("D").max(),
    "delta_max":  df["delta_mv"].resample("D").max(),
})
daily["equiv_cycles"] = daily["ah_out"] / NOMINAL_AH
daily["imbalance_flag"] = daily["delta_max"] &gt; IMBALANCE_MV

print(daily.round(2).tail(14))
print("total equivalent cycles:", round(daily["equiv_cycles"].sum(), 1))
print("days below 20% SOC:", int((daily["soc_min"] &lt; 20).sum()))
</code></pre>
<h3>Reading the summary</h3>
<p><strong><code>soc_min</code> per day</strong> is the number I look at first. If the battery bottoms out near its lower limit most nights, the system is undersized for the load or the PV is not refilling it. If it never drops below 70%, the battery may be oversized for this site, which is useful to know before building the next one.</p>
<p><strong><code>equiv_cycles</code></strong> converts discharged amp-hours into full-cycle equivalents. A battery that goes from 100% to 70% every night is doing about 0.3 equivalent cycles a day, roughly 110 a year. That is the figure to compare against the cycle-life claim on the datasheet, together with the depth of discharge and temperature the claim was tested at.</p>
<p><strong><code>ah_in</code> versus <code>ah_out</code></strong> over a week gives a rough idea of round-trip losses and whether the battery is being fully recharged. If <code>ah_in</code> is consistently lower than <code>ah_out</code> and SOC drifts down day after day, the PV can't keep up.</p>
<p><strong><code>delta_max</code></strong> is the largest gap between the highest and lowest cell voltage each day. A small, stable gap is normal. A gap that grows week by week, especially near full charge, is an early sign of imbalance worth raising with the supplier while the battery is still under warranty. The 50 mV threshold here is a placeholder; use the value your BMS documentation gives.</p>
<p><strong><code>temp_max</code></strong> catches cabinets that cook in the afternoon, which shortens battery life quietly.</p>
<h2>Where this fits</h2>
<p>When you log battery SOC with Python on unattended sites like weather stations, water-level monitors and cameras, the log is often the only evidence of how the power system behaves in the worst month. It tells you whether the battery and PV were sized correctly in the first place. If you are at that sizing stage, I found these <a href="https://solarenergystoragesystem.com/en/blog/solar-monitoring-system-selection">notes on choosing a power setup for monitoring sites</a> a useful checklist of the inputs to collect. For the general sizing order — loads, daily energy, autonomy, PV, battery, then inverter — there is a reference at <a href="https://solarenergystoragesystem.com/en/knowledge">https://solarenergystoragesystem.com/en/knowledge</a>.</p>
<p>The code above is deliberately short. Add a chart, push the CSV to a server, send yourself an alert when <code>soc_min</code> drops below a threshold. Start with the boring version that logs reliably, though. Data you didn't collect can't be analysed.</p>
<hr />
<p><em>Disclosure: I work with TORCHN. Yangzhou Weikechuang handles export trade and projects, and Yangzhou Dongtai handles production; both share the TORCHN brand.</em></p>
]]></content:encoded></item><item><title><![CDATA[Sizing solar for a remote sensor station, with a 30-line Python script]]></title><description><![CDATA[A step-by-step remote sensor station solar sizing walkthrough: load budget, autonomy days, cold derating and PV recovery, with a small Python script.]]></description><link>https://torchnaaron.hashnode.dev/remote-sensor-station-solar-sizing-python</link><guid isPermaLink="true">https://torchnaaron.hashnode.dev/remote-sensor-station-solar-sizing-python</guid><category><![CDATA[Python]]></category><category><![CDATA[iot]]></category><category><![CDATA[solar]]></category><category><![CDATA[embedded]]></category><dc:creator><![CDATA[Aaron Torchn]]></dc:creator><pubDate>Wed, 18 Nov 2026 02:02:33 GMT</pubDate><content:encoded><![CDATA[<p>Remote sensor station solar sizing looks simple on a whiteboard: add up the watts, buy a panel, buy a battery. Then the first grey week of winter arrives and the logger goes silent on day four. This walkthrough is the process I use for small 12 V or 24 V DC sites, such as a camera, a cellular router and a few sensors, with a script at the end so you can rerun the numbers when the load list changes.</p>
<p>All numbers below are an example, not a recommendation for your site.</p>
<h2>Step 1: Write the load budget in watt-hours, not watts</h2>
<p>Everything here runs on DC, so there is no inverter in the chain. That matters: an inverter's idle draw alone could exceed the entire load on a site like this.</p>
<table>
<thead>
<tr>
<th>Load</th>
<th>Average power</th>
<th>Hours/day</th>
<th>Wh/day</th>
</tr>
</thead>
<tbody><tr>
<td>IP camera (night IR on)</td>
<td>6 W</td>
<td>24</td>
<td>144</td>
</tr>
<tr>
<td>LTE router</td>
<td>5 W</td>
<td>24</td>
<td>120</td>
</tr>
<tr>
<td>Data logger + sensors</td>
<td>1.5 W</td>
<td>24</td>
<td>36</td>
</tr>
<tr>
<td>Charge controller self-use</td>
<td>0.5 W</td>
<td>24</td>
<td>12</td>
</tr>
<tr>
<td><strong>Total</strong></td>
<td><strong>13 W</strong></td>
<td></td>
<td><strong>312 Wh</strong></td>
</tr>
</tbody></table>
<p>Two traps. First, use measured average power, not the nameplate maximum, but measure it over a full day including night mode. Second, include the controller's own consumption. It looks tiny until you multiply by 24.</p>
<h2>Step 2: Pick days of autonomy from the weather, not from habit</h2>
<p>Autonomy is how many days the battery must carry the load with almost no solar input. For a station that sends alarms, I start at five days in temperate climates with long grey spells, and three in sunny regions. Look at the worst stretch of consecutive overcast days in local records for the month you care about.</p>
<p>Five days × 312 Wh = 1,560 Wh that must be usable.</p>
<h2>Step 3: Turn usable energy into battery capacity</h2>
<p>Usable is not the same as rated. Divide by the depth of discharge you are willing to use:</p>
<ul>
<li>LiFePO4 planned at 80% DoD: 1,560 / 0.8 = 1,950 Wh</li>
<li>Gel planned at 50% DoD: 1,560 / 0.5 = 3,120 Wh</li>
</ul>
<p>Then account for cold. Batteries deliver less capacity at low temperature. Using 85% as a conservative winter factor for LiFePO4 gives about 2,290 Wh, which is roughly 180 Ah at 12.8 V. I would round up to a 200 Ah pack.</p>
<p>One more cold-weather point: most LiFePO4 packs must not be charged below 0 °C. If the enclosure freezes, either pick a pack with low-temperature charge protection or self-heating, or consider gel, which charges in the cold at the cost of more weight and a lower usable fraction.</p>
<h2>Step 4: Size the array for the worst month, plus recovery</h2>
<p>Peak sun hours (PSH) vary a lot by season. Use the worst month the station must survive. Say that is 2.5 PSH.</p>
<p>I apply two factors:</p>
<ul>
<li><strong>System efficiency (0.85):</strong> battery round trip and wiring losses, so the array must deliver 312 / 0.85 ≈ 367 Wh/day.</li>
<li><strong>PV derate (0.8):</strong> temperature, soiling, mismatch and controller losses.</li>
</ul>
<p>Minimum array to break even on an average winter day: 367 / (2.5 × 0.8) ≈ 184 W.</p>
<p>Break-even is not enough. After a grey spell the battery is empty and the array must refill it while still running the load. If I want to recover one day's deficit per sunny day, the array has to cover two days of energy: (367 + 312) / (2.5 × 0.8) ≈ 340 W. In practice that means two modules in the 180–200 W class.</p>
<h2>Step 5: Check the controller and wiring</h2>
<p>At 12.8 V, 400 W of array produces up to about 31 A of charge current, so a 40 A MPPT controller fits with margin. If the cable run from panel to enclosure is long, consider a 24 V battery instead; halving the current quarters the resistive loss.</p>
<p>Also check the string's open-circuit voltage at the coldest expected temperature against the controller's absolute maximum PV input. Voc rises as cells get colder.</p>
<h2>The script</h2>
<pre><code class="language-python"># Remote DC site sizing. Example values only; edit for your site.
loads_w = {"camera": 6, "lte_router": 5, "logger": 1.5, "controller": 0.5}

autonomy_days = 5
dod = 0.8            # LiFePO4 planning DoD (use ~0.5 for gel)
cold_factor = 0.85   # usable capacity fraction at winter temperature
battery_v = 12.8
worst_psh = 2.5      # peak sun hours in the design month
system_eff = 0.85    # battery round trip + wiring
pv_derate = 0.8      # temperature, soiling, mismatch, controller

daily_wh = sum(loads_w.values()) * 24
need_from_pv = daily_wh / system_eff

battery_wh = daily_wh * autonomy_days / dod / cold_factor
battery_ah = battery_wh / battery_v

pv_min_w = need_from_pv / (worst_psh * pv_derate)
pv_recovery_w = (need_from_pv + daily_wh) / (worst_psh * pv_derate)
ctrl_a = pv_recovery_w / battery_v

print(f"Daily load:        {daily_wh:.0f} Wh")
print(f"Battery:           {battery_wh:.0f} Wh  (~{battery_ah:.0f} Ah @ {battery_v} V)")
print(f"PV break-even:     {pv_min_w:.0f} W")
print(f"PV with recovery:  {pv_recovery_w:.0f} W")
print(f"Controller current: {ctrl_a:.0f} A (choose next size up)")
</code></pre>
<p>Run it and you get roughly 312 Wh/day, 2,290 Wh of battery, 184 W break-even and 340 W with recovery.</p>
<h2>Cross-checking with a second tool</h2>
<p>I like to compare my numbers against a different method, because the assumptions differ. The <a href="https://solarenergystoragesystem.com/en/calculator">off-grid solar system calculator</a> on the TORCHN site uses a 4 peak-sun-hour baseline with a sunlight factor for good, normal or weak regions, and sizes the battery as daily kWh × backup days ÷ usable DoD. Its daily-energy slider starts at 1 kWh, so for a 312 Wh DC site treat it as a sanity check on the battery side rather than a design. If two methods disagree by a lot, the gap usually points to an assumption worth checking, often the sun hours.</p>
<h2>What usually goes wrong</h2>
<ul>
<li>The load was measured in daytime only, and night IR doubled the camera draw.</li>
<li>The panel was tilted for summer and sits in shadow from a ridge in winter.</li>
<li>The battery froze at night and the BMS refused to charge in the morning.</li>
<li>Nobody checked the logs until the station went dark.</li>
</ul>
<p>Log battery voltage and state of charge through the same modem that sends the sensor data. It costs nothing and tells you about a failing array weeks before an outage.</p>
<hr />
<p><em>Disclosure: I work with TORCHN. Yangzhou Weikechuang handles export trade and projects, and Yangzhou Dongtai handles production; both share the TORCHN brand.</em></p>
]]></content:encoded></item></channel></rss>