-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathreading_voltage.txt
52 lines (31 loc) · 3.07 KB
/
reading_voltage.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
Jan 20, 2019
These are my notes on how to read the voltage from the cell groups in the Segway Lithium-Ion battery. They are not definitive or complete, however they will suffice to read all 23 cell groups in the battery.
The Segway lithium battery has an i2c device at address 0x31. If the i2c bus is scanned, this is the only device that will return an acknowledge.
The BMS in the battery is powered by the internal cell. If the cell is compeltely drained and there is insuficcient power to run the BMS, this code may not work. If the battery does not have at least 12V the BMS may not power up.
First, you will need to apply 12V to the BATTERY ENABLE (J5) pin. See the diagram on the github site to identify this pin. If you are using a 12V power adapter on your Arduino, you can use the VIN pin and directly connect it to the BATTERY ENABLE.
There is a DC/DC converter in the battery, but it is NOT recommended to connect the +5V line of the Arduino to the BATTERY ENABLE line. The amount of current the DC/DC converter will need to draw exceeds the 60mA capacity of the Arduino to provide and you could damage the Arduino, the BMS, or both.
You will then need to connect the Arduino GND to the battery GND to make sure both are at an even ground potential and get a clean I2C signal from SCK/SDA.
Last, you will need to connect SCK and SDA lines from the battery to the Arduino. Different models of Arduino have this line on different pins. The Uno and Leonardo have these pins broken out in two locations on the header. If in doubt, check the hardware pages on http://www.arduino.cc.
You should now be able to compile and upload the .ino sketch in this repository to your Arduino and read the voltages on the cell groups.
NOTE! If you have a NiMH battery, there are only six cell groups and your i2c bus address is different! Remember to uncomment the correct lines in the code.
=== METHOD ===
The Segway BMS register to store the voltages of the cell groups is at offset 0x96.
In order to read the voltage and identity of a cell group that register needs to be addressed, then three bytes read from the address. Each repeated call then reads the next cell group up.
first byte is a checksum for the data
second byte is the MSB
third byte is the LSB
The five top bits of the 16 bit integer contain the identity of the cell group
The lower 10 bits are a 10 bit analog A/D value from the battery monitor of the voltage!
The scaling factor is 8000 milivolts * 1023 steps ( 10 bit ) or about 7.820 mV per step.
In Arduino there is a handy macro to re-assemble MSB/LSB into an integer - word()
Mask that integer with a 12 bit mask to zero out the top bits to get the voltage:
i.e.) volage & 0xFFF
Take that integer, and shift it 11 bits over to be left with the value of the battery group
i.e.) word(high,low)>>11
To get the actual voltage of the cell group in milivolts you multiply the resultant value by 7.820
i.e.) 420 * 7.820 = 3284.400 ... 3284 milivolts -> 3.284 volts
Hopefully you find this as entertaining, and useful, as I have!
Sincerely,
Martin Bogomolni
Battery Hacker