GrumpyOldPizza / arduino-STM32L4

69 stars 60 forks source link

getVBUS function output #40

Open rmeldo opened 5 years ago

rmeldo commented 5 years ago

Hi, A question about the function getVBUS.

I am using a Grasshopper board (LoRa), powered with two 1.5 batteries which give 3.2V. I am powering it through the LDO voltage regulator.

I would like to include the voltage level into the periodic upload message to be aware of the state of charge of the batteries.

When I call the function "Serial.print(STM32L0.getVBUS());" I get a "1" on the Arduino serial monitor. Is this what I am supposed to get? How would the message change as the voltage drops?

Thanks Riccardo

kriswiner commented 5 years ago

getVBUS is simple a TTL indicator whether there is 3V present on the USB detect pin. You cannot get a voltage measure from this function. You can simply connect the battery anode by wire to an analog pin and use the ADC (i.e., analogRead) to measure voltage.

On Sat, Oct 27, 2018 at 9:11 AM rmeldo notifications@github.com wrote:

Hi, A question about the function getVBUS.

I am using a Grasshopper board (LoRa), powered with two 1.5 batteries which give 3.2V. I am powering it through the LDO voltage regulator.

I would like to include the voltage level into the periodic upload message to be aware of the state of charge of the batteries.

When I call the function "Serial.print(STM32L0.getVBUS());" I get a "1" on the Arduino serial monitor. Is this what I am supposed to get? How would the message change as the voltage drops?

Thanks Riccardo

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/GrumpyOldPizza/arduino-STM32L4/issues/40, or mute the thread https://github.com/notifications/unsubscribe-auth/AGY1qmsbDrLVMVabNNw2W5yRGtxYii5Vks5upIWfgaJpZM4X9go4 .

kriswiner commented 5 years ago

This works because you maximum battery voltage is < 3.3 V, the analog reference voltage. If you were to use a LiPo battery then you would need a violtage divider to bring the max voltage back to 3.3 V or less. Be careful on your choice of analog pins since some are not 5 V tolerant. As long as the battery voltage or input voltage is 3.3 V or less this is not an issue.

On Sat, Oct 27, 2018 at 9:21 AM Tlera Corporation tleracorp@gmail.com wrote:

getVBUS is simple a TTL indicator whether there is 3V present on the USB detect pin. You cannot get a voltage measure from this function. You can simply connect the battery anode by wire to an analog pin and use the ADC (i.e., analogRead) to measure voltage.

On Sat, Oct 27, 2018 at 9:11 AM rmeldo notifications@github.com wrote:

Hi, A question about the function getVBUS.

I am using a Grasshopper board (LoRa), powered with two 1.5 batteries which give 3.2V. I am powering it through the LDO voltage regulator.

I would like to include the voltage level into the periodic upload message to be aware of the state of charge of the batteries.

When I call the function "Serial.print(STM32L0.getVBUS());" I get a "1" on the Arduino serial monitor. Is this what I am supposed to get? How would the message change as the voltage drops?

Thanks Riccardo

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/GrumpyOldPizza/arduino-STM32L4/issues/40, or mute the thread https://github.com/notifications/unsubscribe-auth/AGY1qmsbDrLVMVabNNw2W5yRGtxYii5Vks5upIWfgaJpZM4X9go4 .

rmeldo commented 5 years ago

OK, but where does the 3v3 reference voltage comes from, when the battery voltage is 3.2V?

It maybe that I do not understand how analogRead works. Riccardo

kriswiner commented 5 years ago

Well, quite right, if you supply the board with 3.2 V the board voltage will be ~3.1 V or so, so this will be the analog voltage too. This can be read by STM32L0.getVDDA() IIRC. So you could just read the VDDA and maybe get a measure of your input voltage, but it won't be exact since for some reason you are going through the LDO. I wouldn't. Just connect 3.2 V to the 3V3 on the board edge, then the board voltage will be a good measure of your battery voltage and you can read this via VDDA.

On Sat, Oct 27, 2018 at 9:45 AM rmeldo notifications@github.com wrote:

OK, but where does the 3v3 reference voltage comes from, when the battery voltage is 3.2V?

It maybe that I do not understand how analogRead works. Riccardo

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/GrumpyOldPizza/arduino-STM32L4/issues/40#issuecomment-433636250, or mute the thread https://github.com/notifications/unsubscribe-auth/AGY1qmEOgrqX1eQy4HMdQ_QZH0t9wKSSks5upI26gaJpZM4X9go4 .

rmeldo commented 5 years ago

OK so for a test I am powering through the USB connector and the STM32L0.getVDDA() returns 3.93. Is it Volts? is seems high. I thought the board ran on 3.3V. Riccardo

rmeldo commented 5 years ago

By the way, the intention is to use supply through the 3.3V pin, for the but since I am using a couple of different battery packs I thought it would be safer to go through the LDO

kriswiner commented 5 years ago

" STM32L0.getVDDA() returns 3.93."

Then something is very wrong with your board...What does 3V3 show?

On Sat, Oct 27, 2018 at 1:36 PM rmeldo notifications@github.com wrote:

By the way, the intention is to use supply through the 3.3V pin, for the but since I am using a couple of different battery packs I thought it would be safer to go through the LDO

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/GrumpyOldPizza/arduino-STM32L4/issues/40#issuecomment-433653287, or mute the thread https://github.com/notifications/unsubscribe-auth/AGY1quunAAkwRUV1q5rtGdwdpsYBLnMsks5upMO4gaJpZM4X9go4 .

rmeldo commented 5 years ago

the 3V3 shows 3.9 as well. I tried another board and it shows 3.3V.

could I have damaged the voltage regulator?

kriswiner commented 5 years ago

Hard to imagine 3.2 V damaging anything, 6 V or 9 V, likely...

On Sat, Oct 27, 2018 at 2:01 PM rmeldo notifications@github.com wrote:

the 3V3 shows 3.9 as well. I tried another board and it shows 3.3V.

could I have damaged the voltage regulator?

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/GrumpyOldPizza/arduino-STM32L4/issues/40#issuecomment-433654965, or mute the thread https://github.com/notifications/unsubscribe-auth/AGY1qvsdOe_-n1KBtdZiBsSdzinlu8Zaks5upMnGgaJpZM4X9go4 .

rmeldo commented 5 years ago

Thanks for the advice. STM32L0.getVDDA() is what I was looking for. Still chasing this voltage problem on my board, but that's on me.

Riccardo