Advertisement
RichPyke

2S LiPo Monitor Script V1.0

Jul 22nd, 2013
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.01 KB | None | 0 0
  1. # Read voltage level of 2S LiPo battery and report to software.
  2. # Set variables
  3. # Change $vundervoltage to the under voltage of your specific battery (leave at 3v if unsure)
  4. # Change $vcritical to your lowest voltage you wish for the battery to get before human intervention
  5. # Change $vmin to low level alert value
  6. # Change $vmax to battery full charge
  7. # Change $multiplyer if using voltage divider
  8. # Factor is 5/255 for adc value conversion to volts
  9. $vundervoltage = 3
  10. $vcritical = 3.5
  11. $vmin = 3.7
  12. $vmax = 4.5
  13. $multiplier = 2
  14. $factor = 0.019607843
  15.  
  16. :ReadCells
  17. # Get ADC values
  18. $vc1 = GetADC(ADC0)
  19. $vc2 = GetADC(ADC1)
  20.  
  21. # Convert values to voltage
  22. $cell2 = $vc1 * $factor
  23. $cell1 = $vc2 * $factor * $multiplier
  24. $cell1 = $cell1 - $cell2
  25. $batteryv = $cell1 + $cell2
  26.  
  27. # Check for errors on circuit
  28. IF ($cell1 > $vmax or $cell2 > $vmax)
  29. Print("Battery Monitor Error")
  30. Print("Check Monitor Circuits")
  31.  
  32. # Check for errors on battery connection
  33. ELSEIF ($cell1 <= 0 or $cell2 <= 0)
  34. Print ("Battery Connection Error")
  35. Print("Check Battery Connection")
  36.  
  37. # Check for under voltage
  38. ELSEIF ($cell1 <= $vundervoltage or $cell2 <= $undervoltage)
  39. Print ("Battery Under Voltage")
  40. Print("Check Or Replace Battery")
  41.  
  42. # Check if at critical levels
  43. # Cell 1
  44. ELSEIF ($cell1 <= $vcritical)
  45. # Do sometihing if critical
  46. Print("Cell 1 Critical")
  47. # Shut down all power, switch to back up battery alarm?
  48.  
  49. # Cell 2
  50. ELSEIF ($cell2 <= $vcritical)
  51. # Do sometihing if critical
  52. Print("Cell 2 Critical")
  53. # Shut down all power, switch to back up battery alarm?
  54.  
  55. # Check if below recommended levels
  56. # Cell 1
  57. ELSEIF ($cell1 < $vmin)
  58. # Do sometihing if voltage low
  59. Print("Cell 1 Low")
  60.  
  61. # Cell 2
  62. ELSEIF ($cell2 < $vmin)
  63. # Do sometihing if voltage low
  64. Print("Cell 2 Low")
  65.  
  66. ELSE
  67. # Output voltages
  68. Print("C1 Round($cell1,2)V")
  69. Print("C2 Round($cell2,2)V")
  70. Print("To Round($batteryv,2)V")
  71. ENDIF
  72. # Wait 5 seconds
  73. Sleep(5000)
  74.  
  75. # Go back to the start
  76. Goto(ReadCells)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement