Skip to content

Commit 6d33afc

Browse files
committed
Version 4.0.0 Improved LCD output
1 parent 47dea57 commit 6d33afc

File tree

4 files changed

+21
-20
lines changed

4 files changed

+21
-20
lines changed

README.md

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# [SMB](https://github.com/ArminJo/Smart-Battery-Module-Info_For_Arduino) - Smart Battery Module (Laptop Battery Pack) Info
22
### Version 4.0.0
33
[![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)
45
[![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)
56
[![Hit Counter](https://hitcounter.pythonanywhere.com/count/tag.svg?url=https%3A%2F%2Fgithub.com%2FArminJo%2FSmart-Battery-Module-Info_For_Arduino)](https://github.com/brentvollebregt/hit-counter)
67

@@ -18,8 +19,8 @@ Download and extract the repository. In the Arduino IDE open the sketch with Fil
1819

1920
## Identifying the right connection
2021
The minimal connector layout is: | GROUND | THERMISTOR (103AT) | CLOCK | DATA | VCC (11 or 14 volt) | (clock and data my be switched).
21-
- The **thermistor** connection has 10 kOhms to ground at 25 degree celsius.
22-
- **Clock** und data connectors have the same resistance (around 1 MOhm) to ground.
22+
- The **thermistor** connection has 10 kOhm to ground at 25 degree celsius.
23+
- **Clock** und data connectors have the same resistance (around 0.3 to 1 MOhm) to ground.
2324
- **VCC** may not be enabled. Sometimes it gets enabled when *Host Present* is connected to ground or clock and data are pulled high to 3.3 or 5 volt.
2425

2526
Some packs (e.g.for IBM-T41 with bq29310) require once an external voltage (e.g. 11 volt) at the VCC connector to initially get alive after full discharge condition.
@@ -35,7 +36,7 @@ Examples:
3536
After startup, the program scans for a connected I2C device.<br/>
3637
In version 4.0 a voltage and resistance measurement by means of 4 additional resistors is integrated **to identify the I2C pins**.
3738
It measures voltage or resistance to ground (if voltage is zero).<br/>
38-
**The I2c pins have around 300 kOhm to 1000 kOhm**, the thermistor 10 kOhm.
39+
**The I2c pins have around 300 kOhm to 1000 kOhm**, the thermistor 10 kOhm (sometimes up to 40 kOhm).
3940

4041
You can try different I2C pin combinations until led stops blinking and `Found I2C device attached at address: 0x0B` is printed.
4142
If you connect clock or data with the thermistor connector or ground, the scanning stops.<br/>
@@ -195,6 +196,7 @@ Average minutes remaining until empty: 16 h 11 min
195196
- Integrated voltage and resistance measurement.
196197
- Major improvements in I2C communication and output.
197198
- Detection of disconnect.
199+
- Improved LCD output.
198200

199201
### Version 3.1.1
200202
- Better prints at scanning.

SBMInfo/ADCUtils.cpp

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,11 @@
2828
// Union to speed up the combination of low and high bytes to a word
2929
// it is not optimal since the compiler still generates 2 unnecessary moves
3030
// but using -- value = (high << 8) | low -- gives 5 unnecessary instructions
31-
union Myword {
31+
union WordUnionForADCUtils {
3232
struct {
3333
uint8_t LowByte;
3434
uint8_t HighByte;
35-
} byte;
35+
} UByte;
3636
uint16_t UWord;
3737
int16_t Word;
3838
uint8_t *BytePointer;
@@ -42,7 +42,7 @@ union Myword {
4242
* Conversion time is defined as 0.104 milliseconds by ADC_PRESCALE in ADCUtils.h.
4343
*/
4444
uint16_t readADCChannel(uint8_t aChannelNumber) {
45-
Myword tUValue;
45+
WordUnionForADCUtils tUValue;
4646
ADMUX = aChannelNumber | (DEFAULT << SHIFT_VALUE_FOR_REFERENCE);
4747

4848
// ADCSRB = 0; // Only active if ADATE is set to 1.
@@ -53,8 +53,8 @@ uint16_t readADCChannel(uint8_t aChannelNumber) {
5353
loop_until_bit_is_clear(ADCSRA, ADSC);
5454

5555
// Get value
56-
tUValue.byte.LowByte = ADCL;
57-
tUValue.byte.HighByte = ADCH;
56+
tUValue.UByte.LowByte = ADCL;
57+
tUValue.UByte.HighByte = ADCH;
5858
return tUValue.UWord;
5959
// return ADCL | (ADCH <<8); // needs 4 bytes more
6060
}
@@ -63,7 +63,7 @@ uint16_t readADCChannel(uint8_t aChannelNumber) {
6363
* Conversion time is defined as 0.104 milliseconds by ADC_PRESCALE in ADCUtils.h.
6464
*/
6565
uint16_t readADCChannelWithReference(uint8_t aChannelNumber, uint8_t aReference) {
66-
Myword tUValue;
66+
WordUnionForADCUtils tUValue;
6767
ADMUX = aChannelNumber | (aReference << SHIFT_VALUE_FOR_REFERENCE);
6868

6969
// ADCSRB = 0; // Only active if ADATE is set to 1.
@@ -74,8 +74,8 @@ uint16_t readADCChannelWithReference(uint8_t aChannelNumber, uint8_t aReference)
7474
loop_until_bit_is_clear(ADCSRA, ADSC);
7575

7676
// Get value
77-
tUValue.byte.LowByte = ADCL;
78-
tUValue.byte.HighByte = ADCH;
77+
tUValue.UByte.LowByte = ADCL;
78+
tUValue.UByte.HighByte = ADCH;
7979
return tUValue.UWord;
8080
}
8181

@@ -160,7 +160,7 @@ uint16_t readADCChannelWithReferenceOversample(uint8_t aChannelNumber, uint8_t a
160160

161161
ADCSRA |= _BV(ADIF); // clear bit to enable recognizing next conversion has finished
162162
// Add value
163-
tSumValue += ADCL | (ADCH << 8); // using myWord does not save space here
163+
tSumValue += ADCL | (ADCH << 8); // using WordUnionForADCUtils does not save space here
164164
// tSumValue += (ADCH << 8) | ADCL; // this does NOT work!
165165
}
166166
ADCSRA &= ~_BV(ADATE); // Disable auto-triggering (free running mode)
@@ -189,7 +189,7 @@ uint16_t readADCChannelWithReferenceOversampleFast(uint8_t aChannelNumber, uint8
189189

190190
ADCSRA |= _BV(ADIF); // clear bit to enable recognizing next conversion has finished
191191
// Add value
192-
tSumValue += ADCL | (ADCH << 8); // using myWord does not save space here
192+
tSumValue += ADCL | (ADCH << 8); // using WordUnionForADCUtils does not save space here
193193
// tSumValue += (ADCH << 8) | ADCL; // this does NOT work!
194194
}
195195
ADCSRA &= ~_BV(ADATE); // Disable auto-triggering (free running mode)
@@ -217,7 +217,7 @@ uint16_t readADCChannelWithReferenceMultiSamples(uint8_t aChannelNumber, uint8_t
217217

218218
ADCSRA |= _BV(ADIF); // clear bit to enable recognizing next conversion has finished
219219
// Add value
220-
tSumValue += ADCL | (ADCH << 8); // using myWord does not save space here
220+
tSumValue += ADCL | (ADCH << 8); // using WordUnionForADCUtils does not save space here
221221
// tSumValue += (ADCH << 8) | ADCL; // this does NOT work!
222222
}
223223
ADCSRA &= ~_BV(ADATE); // Disable auto-triggering (free running mode)

SBMInfo/SBMInfo.ino

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -308,7 +308,7 @@ BQ20Z70_PackVoltage, Pack_Voltage, &printVoltage } };
308308
/*
309309
* From the specs:
310310
* Its clock frequency range is 10 kHz to 100 kHz.
311-
* The charger must NOT charge a battery when it senses the resistance between the Safety Signal pin and ground to be in the range between 425 and 3150 ohms.
311+
* The charger must NOT charge a battery when it senses the resistance between the Safety Signal pin and ground to be in the range between 425 and 3150 ohm.
312312
* E.g. NiMH battery may use a 103AT thermistor for this.
313313
* Only Read Word, Write Word, Read Block or Write Block protocol is used.
314314
* bq2084 spec: With SMBus, the most-significant bit (MSB) of a data byte is transmitted first.
@@ -784,16 +784,15 @@ void printCapacity(struct SBMFunctionDescriptionStruct *aSBMFunctionDescription,
784784
myLCD.print(sDesignCapacity);
785785
if (sCapacityModePower) {
786786
myLCD.print('0'); // here we have units of 10 mWh
787+
myLCD.print("->");
788+
} else {
789+
myLCD.print(" -> ");
787790
}
788-
myLCD.print(" -> ");
789791
// if (tPercent < 100) {
790792
// myLCD.print(' ');
791793
// }
792794
myLCD.print(aCapacity);
793-
if (sCapacityModePower) {
794-
myLCD.print('0'); // here we have units of 10 mWh
795-
}
796-
myLCD.print((getCapacityModeUnit() + 1));
795+
myLCD.print((getCapacityModeUnit()));
797796
myLCD.print('h');
798797

799798
Serial.print(" = ");

extras/IdeaPadIntern.log

2.54 KB
Binary file not shown.

0 commit comments

Comments
 (0)