Shop OBEX P1 Docs P2 Docs Learn Events
P2 ADC project — Parallax Forums

P2 ADC project

Brief description:
I have three 12V 300Ah batteries that I want to keep track of. And I will be capturing the data and moving it over to my rpi device, for further data manipulation.

Since the Activity Board is now eol, I am going to start using the P2. On the Activity board it was a simple matter of how to hook the wires to the ADC. For the P2 it is not as obvious as it should be. Their is no add-on board for doing this, that I have seen. So, I guess I need a simple diagram, showing what goes between the battery and the P2 pins.

At this point I am not sure what I will use, Spin2, C, BASIC, or whatever will be the easiest to deal with.

Thanks in advance.
Ray

Comments

  • JonnyMacJonnyMac Posts: 9,555

    Remember that the P2 IOs are 3.3v so you need to keep your ADC input to that. In a recent project I needed to monitor the state of a 12V battery that feeds an offboard 5v regulator. I added a 12v battery input to the PCB and with a voltage divider that will allow me to safely monitor up to 15v.

    No matter what language you use, you'll need to activate the smart pin ADC mode to read an analog voltage. I've attached my Spin2 object for simple ADC measurements. It includes scaling factors to convert the ADC reading to match your situation. In my case, I can do this (for my circuit designed for 0-15v).

      adc.startx(BATT_MON, 0, 15_000)
    

    After this I can use adc.read() to get the battery voltage in millivolts.

  • RsadeikaRsadeika Posts: 3,875

    Thanks Jon, excellent diagram.
    I have created a power station, in the basement, which consists of the three batteries, three inverters, and a solar charge controller. Two of the inverters are ac powered, and one inverter is a plain one. Outside I have six 200 W solar panels, connected to the charge controller. The ac powered inverter has a built in 20 amp battery charger, a circuit that automatically switches to the battery source when it loses ac power.

    One ac inverter handles my sump pump, the other ac inverter handles my freezer, and the plain inverter takes care of my cable modem, router, 10 TB NAS unit, Dell computer, the lan distribution unit and some other stuff.

    The batteries are connected to a power bar which also has the charge controller connection, and every thing is parallel. Not sure but this might complicate things in terms of the resistors that are shown in the diagram. When the sun is out, I have seen the charge controller getting up to 25 amps, and that is on a partly cloudy day, plus I am not sure what is being provided to the batteries when the ac inverter battery charger kicks in. So, I am not sure how the battery voltage gets when the chargers kick in.

    It would also be nice to have some kind of circuit that provides battery power usage, that the P2 could capture. At the moment I have no idea as too what the battery power activity looks like. Can I add more power hungry devices to this setup, and can I distribute the devices I have now between the inverters. This starting to sound pretty complicated to me.

    Ray

  • evanhevanh Posts: 17,017

    Lead-acid battery chemistry I presume?

  • RsadeikaRsadeika Posts: 3,875

    No, these are lithium batteries. I think China was dumping these batteries in the USA, the price was very low, also the solar panels were probably dumped, those prices were very low. I have not checked to see if the prices are now back to being very high.

    Ray

  • evanhevanh Posts: 17,017
    edited 2025-12-19 21:59

    Lithium-phosphates are cool tech. Requires manual balancing though ... unless there is maybe bleed resistors under the battery lid. I've never opened up a 12V pack.

    Surprisingly rugged, I've accidentally way overcharged individual cells without ill effects - The cells just went high volts no current. So I've worked out that's the easy way to balance them.

  • evanhevanh Posts: 17,017
    edited 2025-12-20 00:10

    @evanh said:
    Surprisingly rugged, I've accidentally way overcharged individual cells without ill effects - The cells just went high volts no current. So I've worked out that's the easy way to balance them.

    On that note, what should be better than bleed/balance resistors across every cell is using heavy zenors instead. As long as the zenor voltage is higher than the cell high impedance voltage then it can never be a short to that cell. Worst case is the charging current flows through the zenor. Which is still lots of heating ... say a 3.6 Volt zenor ... 4.0 Volts x 50 Amps = 200 Watts heating per diode. Hmm, tricky.

    Okay, maybe still have cell monitoring, so then the charger backs off to trickle when first cell goes fully charged. Then the zenors should never have to deal with high currents.

  • RsadeikaRsadeika Posts: 3,875

    The ac inverter built in battery charger has some kind of smarts to charge the lithium battery. Also the solar charge controller is set to charge lithium batteries. Both of these devices go through some kind of cycling process.

    So far I have had this setup running for a couple of months, no smoke from any part of the system. I do have a tp-link wifi smart plug that I use to turn the ac on and off for the ac inverters. I have it set to to turn off at 11:00 AM and to turn it back on at 3:00 PM. That is a four hour window where the system is working from battery power. So far none of the devices have complained about lack of power. The tp-link wifi plug comes in a power info model. I think I will change over to that, too get a sense of how much power the ac inverters are using when the ac power gets turned back on.

    Now I have to give it some thought as to how I will proceed with the ADC thing, I hate dealing with resister combinations. I might have to invest in the JonnyMac breadboard. The only problem I see with this setup is, the breadboard will be a long distance from the batteries, so how do I deal with the long wires coming from the batteries and not being loosened, contact wise, on the breadboard.

    Ray

  • evanhevanh Posts: 17,017
    edited 2025-12-20 12:22

    @Rsadeika said:
    The ac inverter built in battery charger has some kind of smarts to charge the lithium battery. Also the solar charge controller is set to charge lithium batteries. Both of these devices go through some kind of cycling process.

    None of that can correct an imbalance in the cells. If it is sealed then the battery presumably has something internal to manage it. And that will also presumably slowly discharge the battery.

    When building a battery with individual cells a separate Battery Management System (BMS) is used to monitor every cell individually. These BMSs may or may not also actively perform balancing during charging. You have a loom of sense wires that fan out across the whole battery.

  • evanhevanh Posts: 17,017

    Lead-acid batteries also need balancing. All batteries do. But with lead-acids they can cheat. When a cell is fully charged it transitions to boiling off hydrogen - Using current to do so. The fully charged cells are therefore still acting like they're taking charge - Which allows the remaining cells to keep charging from a regular charger. No fancy electronic monitoring of individual cells is required.

    NiCds and NiMH I suspect take damage when overcharged. They heat up is about all I know. I don't know if they convert chemically. At any rate they continue to conduct when fully charged so balancing is achieved by slightly overcharging. It's likely the reason why they have a short lifespan.

  • RsadeikaRsadeika Posts: 3,875

    I need some serious help with this one. Parallax sells the mikroBus boards, so I went to the mikrobus site, and found a board, BATT-MON Click. Not sure what thing does exactly, but it deals with 3.3v and 5v inputs. I have never worked with any mikrobus products. I do not know if this would do what I want, or how I would go about working with this thing. If this thing plugs into a P2, is there spin2 programs that can deal with this. As for the input voltage, I have some little boards that takes in as much as 25V and knocks it down to 5V. I wonder if that would work with the P2 board, using the BAT-MON Click board. Thanks in advance if anybody decides to give a hand.

    This board would reduce the complication some what, I think, and make a less messy situation with the connections to the P2.

    Ray

  • evanhevanh Posts: 17,017
    edited 2025-12-20 13:50

    Is there a lid on the batteries that can be removed? If so, I'd very much like to know what's under the lid.

  • RsadeikaRsadeika Posts: 3,875

    PUPVWMHB 12V 300Ah MINI LiFePO4 Lithium Battery. These are sealed batteries, it shows another $50 price drop. That works out to be a $100 for a 100Ah. The sealed lead acid batteries are about $190 for a 100Ah. On this particular battery type the BT could use a longer range. You have to be fairly close to pick up a signal. I bought these on Amazon.

    Ray

  • RsadeikaRsadeika Posts: 3,875

    So I asked AI:
    "
    There is no MikroE BATT-MON Click specifically designed for 12V batteries. The BATT-MON Click is intended for single-cell battery applications, such as LiPo/Li-Ion batteries commonly found in devices like smartphones, laptops, and power tools, and it supports battery voltages up to 4.5V.
    The device features a high-precision battery gas gauge IC (STC3115) that monitors voltage, current, and temperature, and it can provide additional current to the load using the connected battery through intelligent power routing.
    While the BATT-MON Click can be used in systems that include 12V batteries as part of a larger power management setup, it is not designed to directly monitor or manage a 12V battery pack. For 12V battery monitoring, other solutions such as the BATT-MON 3 Click, which features the BQ35100 IC for battery pack safety and parameter monitoring, may be more suitable.
    "
    Now I am getting a little more familiar, but having no electrical knowledge, not sure if this kind of device will work for my needs. Plus, I cannot tell what kind of programming would be involved in getting the information captured.

    Ray

  • evanhevanh Posts: 17,017

    Posting links would be helpful. I found something but there's no pricing for me since I'm not in shipping zone - https://www.amazon.com/PUPVWMHB-LiFePO4-Bluetooth-Max-3840Wh-Trolling/dp/B0DL9MNRDN

    Okay, they're fancy batteries with Bluetooth! I guess that puts it firmly in the category of "It has its own cell balancing".

  • evanhevanh Posts: 17,017
    edited 2025-12-20 22:52

    @Rsadeika said:
    Now I am getting a little more familiar, but having no electrical knowledge, not sure if this kind of device will work for my needs. Plus, I cannot tell what kind of programming would be involved in getting the information captured.

    Forget the Click board. Jon posted both the wiring and ADC control software.

    Bite the bullet on using a soldering iron. Get one that has temperature control. You'll also want a fine toothless needlenose pliers, and fine flush-cut side-cutters. A solder sucker or wicking braid also important for desoldering and cleaning off old solder.

    Parts for the circuit include:

  • It looks like you are suggesting I make my own prototype board. Actually I am trying stay away from that, I am dealing with wet amd. I do not want to screw up too many boards and still not get the thing to work. It is hard for me to make a public admission like that, but I have to except reality.

    Ray

  • evanhevanh Posts: 17,017
    edited 2025-12-21 14:13

    As per Jon's diagram, yes, add two resistors, a capacitor, and terminals to the mini prototype.

    Desoldering and resoldering the same components can be done in the process of getting it right. The mini prototype board is perfect for messing up with. It starts with no electronics and only gains what you add to it. It's easy to plug and unplug to try again. You'd be hard pressed to break anything.

    PS: You only want the two X1 Batt terminals. The other four terminals aren't needed for a simple voltage monitor. And the Prop2 will have its own power pack.

  • I have a question about Jon's diagram, what the heck is 'C2 0.1', does that have some thing to do with the battery monitor hook up. My interpretation is, the diagram is showing the battery side connections. What ends connect to the P2. Does the 'R11 and R12' connect to the ground on the P2 and the does other wire joined with the ground off the battery connect to, lets say, P0 pin.

    Ray

  • evanhevanh Posts: 17,017

    @Rsadeika said:
    evanh, that is a long link address. It seems that the price went up, maybe because of the holidays.

    Because that's a tracking link. It basically contains a cookie that personalises to you. It can do things like adjust pricing according to what the algorithm thinks you will pay.

    Everything from the "ref=" onwards is not needed - https://www.amazon.com/PUPVWMHB-Bluetooth-Self-Heating-Max-4224Wh-Trolling/dp/B0FY5BZCRX/

  • JonnyMacJonnyMac Posts: 9,555
    edited 2025-12-21 21:41

    Jumpin' Jiminy on a cracker... I was hoping not to have to redraw this simple schematic, but that time spent is better than getting blamed for a problem I didn't create.

    As you can see, the resistors form a simple voltage divider. The middle of the divider connects to the BATT_MON pin on the P2 (with smart pins, any pin can be an ADC). The capacitor is to help keep the ADC input quiet as the battery also feeds a switching power supply that provides 5V to my board (connected via terminal block in the schematic I first posted).

    By convention we typically specify resistor values in ohms and capacitor values in microfarads. So that is 39K ohms, 11K ohms, and 0.1 microfarads (uF).

    This circuit is really simple, and exists in the real world, that is, I'm not posting theory that haven't actually worked with. Here's that circuit on my board. The battery is connected using a 2-pin JST plug.

    I selected the resistor values to allow the battery input to go up to 15 volts, and I can get those values in 1%. It's just simple math (11 / 50 = 0.22; 0.22 * 15 = 3.3).

  • evanhevanh Posts: 17,017
    edited 2025-12-21 21:32

    @Rsadeika said:
    I have a question about Jon's diagram, what the heck is 'C2 0.1', does that have some thing to do with the battery monitor hook up.

    It's a minor noise suppression. Helps remove possible high frequency fuzz. The value is 0.1 uF (100 nF) ceramic capacitor.

    My interpretation is, the diagram is showing the battery side connections. What ends connect to the P2. Does the 'R11 and R12' connect to the ground on the P2 and the does other wire joined with the ground off the battery connect to, lets say, P0 pin.

    The yellow BATT_MON goes to a Prop2 I/O pin. And yep, all grounds connect to Prop2 ground. No, Prop2 I/O pin P0 is not a ground.

    PS: Don't feel bad about having to learn reading schematics. It'll get easier quite quickly. You'll be designing your own circuit boards before you know it.

  • @Rsadeika said:
    It looks like you are suggesting I make my own prototype board. Actually I am trying stay away from that, I am dealing with wet amd. I do not want to screw up too many boards and still not get the thing to work. It is hard for me to make a public admission like that, but I have to except reality.

    Ray

    I respect the strength you’ve shown in making this admission.

    Perhaps this is a situation where the assistance of someone in designing a small custom board, if you need that, and then a small production batch might be the best way to achieve your aim.
    I recognize that mass-produced off-the-shelf parts have the dual appeal of previous testing and low cost, but it’s possible that what you can assemble that way may be less reliable than you desire, while also being more convoluted.

    Given the simplicity of this particular circuit you might also find it simpler to construct from through-hole components without a board. The 11k resistor and 0.1uF capacitor (in an axial-leaded package) can be soldered together in parallel, the 39k resistor joined to one end of the bundle and the whole assembly wrapped in heat-shrink sleeving. This could then be added to the P2 end of the cable and secured in place using hot glue or a cable-tie. Each end of the cable would have two terminals one of which is the common ground.

    This approach may not work for your situation, but I thought it would be worth considering.

  • RaymanRayman Posts: 15,900

    Here's a similar board for the P2 PLC project.
    Not really a help here...

    Am thinking about making a version that plugs into a standard P2 header and will have 8 analog inputs...

    The CDSOD thing is a TVS diode meant to protect P2 pins for overvoltage.
    The actual values here are subject to change, depending on needs.

    Note this is meant for very slow changing inputs.

    2354 x 1304 - 35K
    769 x 1036 - 152K
Sign In or Register to comment.