Skip to content

Commit 9648e27

Browse files
committed
Fixed no voltage measurement bug. Improved print and LCD display after I2C reconnection.
1 parent be755e0 commit 9648e27

File tree

7 files changed

+181
-93
lines changed

7 files changed

+181
-93
lines changed

README.md

Lines changed: 63 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,43 @@
1+
<div align = center>
2+
13
# [SMB](https://github.com/ArminJo/Smart-Battery-Module-Info_For_Arduino) - Smart Battery Module (Laptop Battery Pack) Info
2-
### Version 4.1.0
3-
[![License: GPL v3](https://img.shields.io/badge/License-GPLv3-blue.svg)](https://www.gnu.org/licenses/gpl-3.0)
4-
[![Commits since latest](https://img.shields.io/github/commits-since/ArminJo/Smart-Battery-Module-Info_For_Arduino/latest)](https://github.com/ArminJo/Smart-Battery-Module-Info_For_Arduino/commits/master)
5-
[![Build Status](https://github.com/ArminJo/Smart-Battery-Module-Info_For_Arduino/workflows/TestCompile/badge.svg)](https://github.com/ArminJo/Smart-Battery-Module-Info_For_Arduino/actions)
6-
![Hit Counter](https://visitor-badge.laobi.icu/badge?page_id=ArminJo_Smart-Battery-Module-Info_For_Arduino)
4+
Prints SBM controller info.<br/>
5+
Based on the unmaintained [PackProbe program](https://github.com/PowerCartel/PackProbe) from Power Cartel http://powercartel.com/projects/packprobe/.
76

8-
Prints SBM controller info
97

10-
Based on the unmaintained [PackProbe program](https://github.com/PowerCartel/PackProbe) from Power Cartel http://powercartel.com/projects/packprobe/.
8+
[![Badge License: GPLv3](https://img.shields.io/badge/License-GPLv3-brightgreen.svg)](https://www.gnu.org/licenses/gpl-3.0)
9+
&nbsp; &nbsp;
10+
[![Badge Version](https://img.shields.io/github/v/release/ArminJo/Smart-Battery-Module-Info_For_Arduino?include_prereleases&color=yellow&logo=DocuSign&logoColor=white)](https://github.com/ArminJo/Smart-Battery-Module-Info_For_Arduino/releases/latest)
11+
&nbsp; &nbsp;
12+
[![Badge Commits since latest](https://img.shields.io/github/commits-since/ArminJo/Smart-Battery-Module-Info_For_Arduino/latest?color=yellow)](https://github.com/ArminJo/Smart-Battery-Module-Info_For_Arduino/commits/master)
13+
&nbsp; &nbsp;
14+
[![Badge Build Status](https://github.com/ArminJo/Smart-Battery-Module-Info_For_Arduino/workflows/TestCompile/badge.svg)](https://github.com/ArminJo/Smart-Battery-Module-Info_For_Arduino/actions)
15+
&nbsp; &nbsp;
16+
![Badge Hit Counter](https://visitor-badge.laobi.icu/badge?page_id=ArminJo_Smart-Battery-Module-Info_For_Arduino)
17+
<br/>
18+
<br/>
19+
[![Stand With Ukraine](https://raw.githubusercontent.com/vshymanskyy/StandWithUkraine/main/badges/StandWithUkraine.svg)](https://stand-with-ukraine.pp.ua)
20+
21+
</div>
22+
23+
#### If you find this program useful, please give it a star.
24+
25+
<br/>
26+
1127

1228
# Disclaimer
1329
**I do not know how to enter full access mode, clear permanent failure or unlock any controller IC.** Unfortunately according to most datasheets, you need an unlock key.
1430
See also this [article from 2011](https://media.blackhat.com/bh-us-11/Miller/BH_US_11_Miller_Battery_Firmware_Public_WP.pdf).
1531
Extract: *Macbook batteries ship with a default unseal password (0x36720414). This was found by reverse engineering a Macbook battery update. On Macbook batteries, the full access mode password is also hardcoded and default (0xffffffff).*
1632

17-
## Compile with the Arduino IDE
33+
<br/>
34+
35+
# Compile with the Arduino IDE
1836
Download and extract the repository. In the Arduino IDE open the sketch with File -> Open... and select the SBMInfo folder.
1937

20-
## Identifying the right connection
38+
<br/>
39+
40+
# Identifying the right connection
2141
Valuable information about battery pinout can also be found [here](https://www.laptopu.ro/community/laptop-battery-pinout/) or [here](https://powercartel.com/projects/packprobe/battery-connection/).<br/>
2242
The minimal connector layout is: | GROUND | THERMISTOR (103AT) | CLOCK | DATA | VCC (11 or 14 volt) | (clock and data my be switched).
2343
- The **thermistor** connection has 10 k&ohm; to ground at 25 degree celsius.
@@ -50,11 +70,15 @@ An example schematic for a SBM module can be found in the datasheet of TI bq2931
5070

5171
![Simple breadboard setup](pictures/Breadboard.jpg)
5272

73+
<br/>
74+
5375
# Support for automatic discharge and charge
5476
The charge control pin (9) is high as long as relative charge is below 95%. It can be used to control a NPN transistor, which collector controls a high side P FET.<br/>
5577
The discharge control pin (10) is high as long as relative charge is above 5% and voltage, if available, is below 3300 mV. It can be used to control a logic level FET directly.<br/>
5678
The switch off values can be changed [here](https://github.com/ArminJo/Smart-Battery-Module-Info_For_Arduino/blob/master/SBMInfo/SBMInfo.ino#L42)
5779

80+
<br/>
81+
5882
# LCD display content
5983
### LCD Display before device connected
6084
1. line: "SBMInfo" | Version | VCC voltage
@@ -79,18 +103,20 @@ The switch off values can be changed [here](https://github.com/ArminJo/Smart-Bat
79103
|-|-|
80104
| ![LCD start](pictures/LCDDisplay_DynamicData.jpg) | ![Dynamic data discharging](pictures/LCDDisplay_DynamicData_Discharging.jpg) |
81105

82-
## German Documentation
106+
<br/>
107+
108+
# Deutsche Documentation
83109
Gibt die Daten des SMB Controllers aus.
84110
Basiert auf https://github.com/PowerCartel/PackProbe von Power Cartel http://powercartel.com/projects/packprobe/. Hier gibt es auch weitere wertvolle Informationen.
85111

86-
## Finden der Anschlüsse.
87-
In der Version 4.0 ist eine Spannungs und Widerstandsmessung mittels 4 Widerständen integriert, um die I2C Pins zu identifizieren.
88-
Die Clock und Data Eingänge waren bei meinen Packs die Anschlüsse mit einem Widerstand von ca. 300 k bis 1 M&ohm; nach Masse.
112+
## Finden der Anschl&uuml;sse.
113+
In der Version 4.0 ist eine Spannungs und Widerstandsmessung mittels 4 Widerst&auml;nden integriert, um die I2C Pins zu identifizieren.
114+
Die Clock und Data Eing&auml;nge waren bei meinen Packs die Anschl&uuml;sse mit einem Widerstand von ca. 300 k bis 1 M&ohm; nach Masse.
89115
Nach dem Booten sucht das Programm nach einem angeschlossenen I2C Device.
90-
Man kann also alle möglichen Pinkombinationen von Clock und Data am Battery Pack ausprobieren.
91-
Bei der Richtigen hört das Blinken der Led auf und es kommt sofort die Ausgabe `Found I2C device attached at address: 0x0B` und direkt danach werden die Daten ausgegeben.
116+
Man kann also alle m&ouml;glichen Pinkombinationen von Clock und Data am Battery Pack ausprobieren.
117+
Bei der Richtigen h&ouml;rt das Blinken der Led auf und es kommt sofort die Ausgabe `Found I2C device attached at address: 0x0B` und direkt danach werden die Daten ausgegeben.
92118

93-
Bei den Laptop Battery Packs war Plus und Masse immer außen.
119+
Bei den Laptop Battery Packs war Plus und Masse immer au&szlig;en.
94120
Wenn mehr als 5 Kontakte vorhanden waren, waren sie wie folgt belegt:
95121
- Masse und Plus doppelt. z.B. + | + | Thermistor | Data | Clock | - | -
96122
- Ein Enable (nur im Laptop mit Masse verbunden) und eine Signal Anschluss (nur im Battery Pack mit Masse verbunden). z.B. VCC | VCC | CLOCK | DATA | Signal | Enable | THERMISTOR | GROUND | GROUND |
@@ -99,19 +125,22 @@ Der Thermo-Sensor Anschluss war uneinheitlich, mal nicht messbar beschaltet, mal
99125

100126
Zur Verbindung mit den Kontakten habe ich normales 1,5 qmm Kupferkabel aus der Hausinstallation genommen, dessen eines Ende ich mit einem Hammer etwas plattgeklopft hab. Stecknadeln oder Breadboard Wires gehen auch.
101127

102-
Die Daten werden nur einmalig nach dem Reset ausgegeben, nur die veränderlichen Werte wie Spannung / Strom / Temperatur / Ladung werden alle 3 Sekunden auf Veränderungen gecheckt.
128+
Die Daten werden nur einmalig nach dem Reset ausgegeben, nur die ver&auml;nderlichen Werte wie Spannung / Strom / Temperatur / Ladung werden alle 3 Sekunden auf Ver&auml;nderungen gecheckt.
103129

104130
Tested with bq20z70, bq20z451, bq2084, bq80201DBT, bq40z50.
105131

106132
Einen Schaltplan zu den Batterie Modulen gibt es im Datenblatt zum TI bq29311 auf Seite 9.
107133

108-
### Sample output:
134+
<br/>
135+
136+
# Sample output:
109137
Sample outputs can be found in folder [extras](https://github.com/ArminJo/Smart-Battery-Module-Info_For_Arduino/tree/master/extras).
110138

111139
```
112140
START ../src/SBMInfo.cpp
113-
Version 4.0 from Oct 12 2021
114-
No LiPo supply detected -> fast display timing
141+
Version 4.3 from Nov 23 2023
142+
Configured to set charge control pin 9 to low above 95 %
143+
Configured to stop discharge control pin 10 to low below 5 % or 3300 mV
115144
Found attached I2C device at 0xB
116145
117146
Battery mode 0x6081 | 0b110000010000001
@@ -163,7 +192,11 @@ Battery status 0xC0 | 0b11000000
163192
80 Initialized
164193
40 Discharging
165194
166-
Pack config and status 0x6B | 0b11010110000
195+
Pack config and status 0x8230 | 0b1000001000110000
196+
- Pack not inserted
197+
- Voltage > EDV2
198+
- Pack sealed
199+
- Discharge is qualified for capacity learning
167200
168201
169202
*** DYNAMIC NON STANDARD INFO ***
@@ -193,15 +226,21 @@ Minutes remaining until empty 4 h 7 min
193226
Average minutes remaining until empty: 16 h 11 min
194227
```
195228

196-
### Fritzing board
229+
<br/>
230+
231+
# Fritzing board
197232
![Fritzing board](extras/SBMInfo_Steckplatine.png)
198-
### Fritzing schematics
233+
# Fritzing schematics
199234
![Fritzing schematics](extras/SBMInfo_Schaltplan.png)
200235

201236
# Revision History
237+
### Version 4.3
238+
- Fixed no voltage measurement bug.
239+
- Improved print and LCD display after I2C reconnection.
240+
202241
### Version 4.2
203242
- Removed compile time warnings.
204-
243+
205244
### Version 4.1.0
206245
- Support for automatic discharge and charge.
207246
- Improved output.
@@ -214,5 +253,3 @@ Average minutes remaining until empty: 16 h 11 min
214253

215254
### Version 3.1.1
216255
- Better prints at scanning.
217-
218-
#### If you find this program useful, please give it a star.

SBMInfo/ADCUtils.h

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -112,9 +112,6 @@
112112
#error "No temperature channel definitions specified for this AVR CPU"
113113
#endif
114114

115-
extern float sVCCVoltage;
116-
extern uint16_t sVCCVoltageMillivolt;
117-
118115
extern long sLastVCCCheckMillis;
119116
extern uint8_t sVCCTooLowCounter;
120117

@@ -124,7 +121,6 @@ uint16_t waitAndReadADCChannelWithReference(uint8_t aADCChannelNumber, uint8_t a
124121
uint16_t waitAndReadADCChannelWithReferenceAndRestoreADMUXAndReference(uint8_t aADCChannelNumber, uint8_t aReference);
125122
uint16_t readADCChannelWithOversample(uint8_t aADCChannelNumber, uint8_t aOversampleExponent);
126123
void setADCChannelAndReferenceForNextConversion(uint8_t aADCChannelNumber, uint8_t aReference);
127-
uint16_t readADCChannelWithReferenceOversample(uint8_t aADCChannelNumber, uint8_t aReference, uint8_t aOversampleExponent);
128124
uint16_t readADCChannelWithReferenceOversampleFast(uint8_t aADCChannelNumber, uint8_t aReference, uint8_t aOversampleExponent);
129125
uint16_t readADCChannelWithReferenceMultiSamples(uint8_t aADCChannelNumber, uint8_t aReference, uint8_t aNumberOfSamples);
130126
uint16_t readADCChannelWithReferenceMax(uint8_t aADCChannelNumber, uint8_t aReference, uint16_t aNumberOfSamples);
@@ -139,9 +135,7 @@ uint8_t checkAndWaitForReferenceAndChannelToSwitch(uint8_t aADCChannelNumber, ui
139135
*/
140136
float getVCCVoltageSimple(void);
141137
void readVCCVoltageSimple(void);
142-
uint16_t getVCCVoltageMillivoltSimple(void);
143138
void readVCCVoltageMillivoltSimple(void);
144-
float getVCCVoltage(void);
145139
void readVCCVoltage(void);
146140
uint16_t getVCCVoltageMillivolt(void);
147141
void readVCCVoltageMillivolt(void);
@@ -163,4 +157,17 @@ bool isVCCTooHigh();
163157
bool isVCCTooHighSimple();
164158

165159
#endif // defined(__AVR__) ...
160+
161+
/*
162+
* Variables and functions defined as dummies to allow for seamless compiling on non AVR platforms
163+
*/
164+
extern float sVCCVoltage;
165+
extern uint16_t sVCCVoltageMillivolt;
166+
167+
uint16_t readADCChannelWithReferenceOversample(uint8_t aADCChannelNumber, uint8_t aReference, uint8_t aOversampleExponent);
168+
169+
uint16_t getVCCVoltageMillivoltSimple(void);
170+
float getVCCVoltage(void);
171+
float getCPUTemperature(void);
172+
166173
#endif // _ADC_UTILS_H

SBMInfo/ADCUtils.hpp

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -481,7 +481,7 @@ void readAndPrintVCCVoltageMillivolt(Print *aSerial) {
481481
void readVCCVoltageSimple(void) {
482482
// use AVCC with (optional) external capacitor at AREF pin as reference
483483
float tVCC = readADCChannelWithReferenceMultiSamples(ADC_1_1_VOLT_CHANNEL_MUX, DEFAULT, 4);
484-
sVCCVoltage = (1023 * 1.1 * 4) / tVCC;
484+
sVCCVoltage = (1023 * (((float) ADC_INTERNAL_REFERENCE_MILLIVOLT) / 1000) * 4) / tVCC;
485485
}
486486

487487
/*
@@ -688,10 +688,28 @@ float getCPUTemperature(void) {
688688
#endif
689689
}
690690

691-
#elif defined(ARDUINO_ARCH_APOLLO3) // defined(ADC_UTILS_ARE_AVAILABLE)
692-
void ADCUtilsDummyToAvoidBFDAssertions(){
693-
;
694-
}
691+
#else // defined(ADC_UTILS_ARE_AVAILABLE)
692+
// Dummy definition of functions defined in ADCUtils to compile examples without errors
693+
/*
694+
* Persistent storage for VCC value
695+
*/
696+
float sVCCVoltage;
697+
uint16_t sVCCVoltageMillivolt;
698+
699+
uint16_t getVCCVoltageMillivoltSimple(void){
700+
return 3300;
701+
}
702+
703+
uint16_t readADCChannelWithReferenceOversample(uint8_t aChannelNumber __attribute__((unused)),
704+
uint8_t aReference __attribute__((unused)), uint8_t aOversampleExponent __attribute__((unused))) {
705+
return 0;
706+
}
707+
float getCPUTemperature() {
708+
return 20.0;
709+
}
710+
float getVCCVoltage() {
711+
return 3.3;
712+
}
695713
#endif // defined(ADC_UTILS_ARE_AVAILABLE)
696714

697715
#if defined(LOCAL_DEBUG)

0 commit comments

Comments
 (0)