TinyCamML / Boron-and-OpenMV

This repo is continued progress between Boron and OpenMV as a self contained device that can successfully monitoring flooding on roadways.
MIT License
0 stars 0 forks source link

Monitor external solar panel/battery voltage #9

Open SUPScientist opened 3 months ago

SUPScientist commented 3 months ago

Need

Want to be able to monitor voltage of external solar panel/battery which is plugged into Boron's V_USB via the micro-USB socket.

Challenge

Particle has methods for monitoring VBATT where a LiPo battery would be connected (via the FuelGauge methods: https://docs.particle.io/reference/device-os/firmware/#fuelgauge) but unclear how to monitor V_USB. Assumption may be that V_USB comes from a stable power supply and does not need to be monitored.

Steps to Solve

SUPScientist commented 3 months ago

@efarq, can you check this out?

SUPScientist commented 3 months ago

Here's a reference design for a voltage divider that Particle uses to measure the battery voltage on an Argon: https://docs.particle.io/reference/device-os/api/battery-voltage/battery-voltage-photon-2/#battery-voltage-argon. The voltage on VUSB on the Boron will be higher but the nominal resistances used here are helpful nonetheless. At ≈ 1 MΩ, current wasted will be ≈ 5 µa which isn't too bad.

ebgoldstein commented 3 months ago

fuel gauge does not seem to work with usb input: https://community.particle.io/t/fuel-gauge-reading-on-the-usb/62568/3

efarq commented 3 months ago

Just to confirm - is there anything else you'd like me to look into with this since Evan found that community forum?

SUPScientist commented 3 months ago

Yes, I didn't think the fuelgauge would work but it was worth double-checking. See the voltage divider reference above for a proposed solution. I think it will be critical to have solar panel/battery monitoring ability and a voltage divider is very easy to implement and for @ebgoldstein to include in the PCB.

SUPScientist commented 2 months ago

@efarq to design/test voltage divider to scale 5 V nominal solar panel output down to 3.3 V max acceptable Boron ADC analog input. Using equation Vout = Vin*(R2/(R1+R2)) in standard voltage divider circuit, R2 to be ≈ 2 MΩ and R1 to be rounded up to nearest available resistor that keeps Vout ≤ 3.3 V.

efarq commented 2 months ago

Just following up - I think I got it worked out! With Phil's help, I found that R1 = 1.125 megaohms, so I rounded it up to 1.3 megaohms, and R2 = 2 megaohms. Then I set up the Boron with some resistors (photo and circuit diagram attached) and ran the code on it. The Boron V(out) was consistently reading about ~2.7V while it was receiving usb power from my laptop. I checked with the multimeter, and that matched what the Boron was saying too.

I'm uploading the script folder to the Firmware folder, and the Boron+resistors+breadboard are on the counter in Phil's lab. Let me know if anything looks like it needs to be changed. IMG_0500 IMG_0499

SUPScientist commented 2 months ago

Great, thanks, @efarq. Nice work. I see the test script in your commit here https://github.com/TinyCamML/Boron-and-OpenMV/commit/e2b713a82b8a3a851c1bc34a9584dc5fcb082bdf and in the new subdirectory here https://github.com/TinyCamML/Boron-and-OpenMV/tree/main/Firmware/TestingVoltageSplitter.

To close this issue, I recommend the following:

  1. Create a branch of this repo
  2. Integrate solar panel/battery voltage monitor firmware into main Boron firmware in that branch
  3. Test new firmware
  4. Iterate between 2<—>3 as needed
  5. Once firmware works as desired, merge branch back into main.
  6. Close issue with link to merge

(@ebgoldstein, workflow seem appropriate to you? As we add teammates here, I'm more than open to thinking through desired github workflow together/following your lead.)

efarq commented 2 months ago

Okay I think I correctly created a new branch, got the firmware to work with the boron+openMV so it publishes the solar voltage into google sheets, and merged it back into main?

Before closing, I do have a question - how should we calculate the percent of battery charge left? For testing purposes, I just did (voltage read on pin A1)/3.3V*100. However, the voltage going into A1 should never actually reach 3.3V fully because of all the resistors. So the only other way I was thinking of getting that true "full" number is if I use the power supply in the lab to provide the boron with a perfect 5V and see what it reads with that? Any other ideas?

SUPScientist commented 2 months ago

Great! That looks good at a first glance. Confirming that you tested this on the hardware? If so, please say so and click "close with comment."

I recommend removing the percent charge variable and report. Battery charge is non-linearly related to voltage (google "battery discharge curve" for visuals) and can easily be inaccurate. Voltage will suffice. No branch/pull request needed for that change; just remove relevant parts of .ino file and recommit/push, please.

efarq commented 2 months ago

Yes, I tested it on the Boron and OpenMV that bentley was using, and it seems to work.

efarq commented 1 week ago

I'm reopening this so I remember to look at it this week. I just need to double check the code/voltage with a multimeter for this because it's still reporting about 2.8-2.9 V when plugged into usb power. I thought I scaled it up properly by multiplying by an extra ((R1 + R2) / R1)

https://github.com/TinyCamML/Boron-and-OpenMV/blob/3a03ea4b75fd1438a5236e86fadcb9e209097110/src/boron/src/TinyCamPublish.ino#L72