Reading LiPo sensor FLVSS with Arduino Uno

General Help and support for the Taranis Radio.
User avatar
MikeB
9x Developer
Posts: 17993
Joined: Tue Dec 27, 2011 1:24 pm
Country: -
Location: Poole, Dorset, UK

Re: Reading LiPo sensor FLVSS with Arduino Uno

Post by MikeB »

The FlvssCells array is updated when data is received from the sensor, so always holds the last values received.
If you need these to go to zero when the sensor is disconnected, you need to note the time (millis()) when data is put in the array, then, in loop(), timeout data is received and set the array to zero.

Mike
erskyTx/er9x developer
The difficult we do immediately,
The impossible takes a little longer!

Raythegreat
Posts: 284
Joined: Sat Apr 16, 2016 11:33 pm
Country: -

Re: Reading LiPo sensor FLVSS with Arduino Uno

Post by Raythegreat »

Got it Mike.
It seems to work very well and in real time when the balance cable is connected.
But if there is zero volts coming in, the mechanism you described occurs. The arrays are not refreshed.

So I will carry on with my code. I don't need to read 0 when not connected.
Also it does not look like I will need to put TX_HUB_PIN to 5. It works not in real time. Sport bus does not seems to be upset...yet.

I might have more questions but I hope not. You've been a great help.
This project by using the FLVSS prevents me to make an analog circuit and read analog voltages even if it would be much more simple for the C code.

I will need to automate the whole process with a relay switching loads.

Thanks,
Ray
User avatar
Kilrah
Posts: 11109
Joined: Sat Feb 18, 2012 6:56 pm
Country: Switzerland

Re: Reading LiPo sensor FLVSS with Arduino Uno

Post by Kilrah »

My charger provides IR measurements so I don't need this, but could do a comparison out of interest.
Raythegreat
Posts: 284
Joined: Sat Apr 16, 2016 11:33 pm
Country: -

Re: Reading LiPo sensor FLVSS with Arduino Uno

Post by Raythegreat »

Hi Kilrah,

Yes, my charger does it also but most chargers give notoriously bad values. Some chargers are good but I have never seen or owned one that gives real good values.
Try the manual way and compare with your charger. You'll need a good multimeter and a know load.

1- Get a know resistor load. Mine is 8.3 ohms measured with a good multimeter.
2- Measure the lipo pack voltage with the load. This gives you VL (voltage under load) and IL (current with load).
3- Wait at least 5 seconds to get the stabilized open loop voltage and measure the pack voltage. This is VO.
4- Rin = VO - VL / IL. This gives you the total Rin of the entire pack. Divide by the number of cells to get the average Rin of each cell.
You can do the same process on each cell individually.

Compare with your charger. If you have good results, then you have a good charger.
Make sure to compare at the same temperature and % of voltage charge.

Ray
Raythegreat
Posts: 284
Joined: Sat Apr 16, 2016 11:33 pm
Country: -

Re: Reading LiPo sensor FLVSS with Arduino Uno

Post by Raythegreat »

Hi Mike,

I have a strange problem related to the compiler and the SportToHub files.

When I add in any very simple function the Arduino function delay(1000); to generate a one second stop or delay, the compiler generates errors.
I have no idea why.
Once I comment this line the compiler has no errors and everything compiles well. ex: // delay(1000);
Strange for me but maybe not for you. The simple addition of the delay function causes compiler errors??

Any idea what is going on?

Thank you
Ray

User avatar
MikeB
9x Developer
Posts: 17993
Joined: Tue Dec 27, 2011 1:24 pm
Country: -
Location: Poole, Dorset, UK

Re: Reading LiPo sensor FLVSS with Arduino Uno

Post by MikeB »

The Arduino Delay function will pull in other Arduino library functions that will conflict with the millis() and micros() functions already in. These have to be the ones I've written as the Arduino library functions upset the critical timing for the SPort.

If you need a delay function, include this:

Code: Select all

void delay(unsigned long ms)
{
   uint16_t start = (uint16_t)micros();
   uint16_t lms = ms ;

   while (lms > 0) {
      if (((uint16_t)micros() - start) >= 1000) {
         lms--;
         start += 1000;
      }
   }
}
Mike
erskyTx/er9x developer
The difficult we do immediately,
The impossible takes a little longer!
Raythegreat
Posts: 284
Joined: Sat Apr 16, 2016 11:33 pm
Country: -

Re: Reading LiPo sensor FLVSS with Arduino Uno

Post by Raythegreat »

Hi Mike,

Thank you for the source code.
So if I understand , I can't use some of the Arduino library or simply the delay function? Example: No Serial.print(number);
This might complicate things for me. If it's only delay, then you provided the solution.

Where in your loop() function is safe to insert a long delay or wait for a switch to be pressed without disturbing the sport timing?
I tried to understand your code and could not understand all the subtleties.

Thanks,
Ray
User avatar
MikeB
9x Developer
Posts: 17993
Joined: Tue Dec 27, 2011 1:24 pm
Country: -
Location: Poole, Dorset, UK

Re: Reading LiPo sensor FLVSS with Arduino Uno

Post by MikeB »

Serial.print may work, but the Arduino delay() won't.

No quick answer as loop() is always checking 4 timing values to schedule operations. Any long delay will cause problems.
You could wait for a switch, but on return from the wait, you will need to have:
now = millis() ;
LedMillis = now ;
LastMillis = now ;
SlotMillis = now ;
HubMillis = now ;
to restore the timing. Only have this done the once when returning having found the switch active.

Also note that millis() (or micros() ) must be called at least once every 4 milliseconds to maintain timing.

Mike
erskyTx/er9x developer
The difficult we do immediately,
The impossible takes a little longer!
Raythegreat
Posts: 284
Joined: Sat Apr 16, 2016 11:33 pm
Country: -

Re: Reading LiPo sensor FLVSS with Arduino Uno

Post by Raythegreat »

Thank you Mike,

Very helpful.
OUFFF... it's a good thing you gave me this info, I was violating this timing a lot.

I will try to make this work.

Thank you
Ray

Post Reply

Return to “General help (FrSky Taranis radio)”