Reading Battery Data With an Arduino

Joined
Sep 28, 2016
Messages
6
Reaction score
8
Age
44
I am using bassmission code on the Arduino Pro mini, but I cant display anything :( I get no error when uploading the code, but nothing happends when I put the battery on.
I got OLED display that has 4 pins VCC GND SCL SDA.
 
Joined
Jun 18, 2017
Messages
74
Reaction score
12
Age
43
Location
France-Alpes Maritimes
EDIT: I AM CURRENTLY USING A PCA9306 LEVEL SHIFTER TO TRANSLATE 5V I2C FROM THE ARDUINO TO 3.3V I2C ON THE BATTERY. THIS IS THE PROPER WAY TO DO THIS AND DOES NOT REQUIRE ADDITIONAL EXTERNAL RESISTORS. SO THE METHOD BELOW WORKS BUT IS NOT RECOMMENDED FOR LONG TERM USE.

To make this compatible with the Arduino UNO R3, you will have to make some changes. The internal pull up resistors of the ATMEGA328PU IC are too large for I2C communications. You will need to disable them and modify the wiring. The 2 changes below are required.:

1. You will need to add a 4.7k-ohm external pull up resistor on each of the SCL and SDA lines. You need to pull the lines up to 3.3 volts (on your arduino).

View attachment 4870

I believe the reason you don't need to make this change on the Mega 2560 is that it has an internal and an external pull up resistor, and their equivalent resistance is about 5k-ohm. If I recall, the UNO's internall pull up resistor is something like 20k which is not always good for I2C.

2. You will need to change the code as follows:

Code:
  #define SCL_PIN 5                 //Arduino UNO R3???
  #define SCL_PORT PORTC

  #define SDA_PIN 4                 //Arduino UNO R3???
  #define SDA_PORT PORTC


//AND ALSO COMMENT OUT THE PIN MODES
  //SETUP I2C INPUT PINS
    //pinMode(27,INPUT_PULLUP);
    //pinMode(28,INPUT_PULLUP);

Hi @pious_greek, i've tested both on arduino mega and arduino duemilanove, the two sketches seem to work correctly. but when i measure the voltage on SCL and SDA lines it is 5V not 3.3V. Same result for mega (without 4.7k resistances) and for duemilanove (with 2 4.7 k resistances).

I said 'seem to work' because i don't try on 3dr solo batt yet but on my custom batt with BMS card like this, the IC on it is bq 20z95dbt from TI:

Li Ion Battery Communication Pcb Manufacturer/1s-4s Communication Bms 7a Pcm For Li Ion/lipo/lifepo4 Battery Pack - Buy Li Ion Battery Communication Pcb Manufacturer,Pcm For Li Ion/lipo/lifepo4 Battery Pack,Communication Bms 7a Pcm Product on Alibaba.com

In my attached file is the manufacturer default parameters not my old LiPo (nanotech 5000 mAh, 4S)
20180119_193630.jpg
 

Attachments

Joined
Oct 12, 2018
Messages
3
Reaction score
1
Age
39
Hello,

I found this post, because I try to reset a DJI Phantom 2 battery after I replaced the cells. The battery works, but the controller seems to be all screwed up.

It says that the LiPo has 2 cycles, 100% lifetime left, full capacity 70mA, current capacity 1mA. The indicator bars show that the battery is empty, but the cell voltage is at 4,15V each. My Phantom blinks red because it thinks the battery is empty, but I can give full throttle for 15min until the Cells reach 3.2V @ 30A load (they recover to 3.7V if the load is removed).

After trying a lot of things, like disconnecting the balancing plug, pushing buttons while playing with the balaning connector and so on I think the only way is to somehow reset the battery controller.

Does anyone know where I can find a full documentation of the controller - I kinda can't belive that this interface is just read only ...
I don't think that there is a custom firmware installed, it's more a standard charge controller with monitoring.
 
Joined
Jun 18, 2017
Messages
74
Reaction score
12
Age
43
Location
France-Alpes Maritimes
Hi kutt,
I don't know P2 battery but did you try to maintain the power switch 5s when power on?

some battery internal chip can autocalibrate like that. Here after what i read in a datasheet of BMS:

"Auto Calibration
The bq20z95 provides an auto-calibration feature to cancel the voltage offset error across SRN and SRP for
maximum charge measurement accuracy. The bq20z95 performs auto-calibration when the SMBus lines stay
low continuously for a minimum of 5 s.
"

good luck
 
Joined
Oct 12, 2018
Messages
3
Reaction score
1
Age
39
[..]he bq20z95 provides [..]

I'll try to figure out what kind of chip the Phantom2 battery uses (was away for the weekend). Maybe I find a datasheet.

Do you have any idea at which level the Battery should be when resetting the chip? Some say it should be full, some say it should be empty. From my feeling I would say LiPo at 3.0V (= empty), reset controller and charge it to full. So the controller should count how many Ah went into the battery.

Or is this mistaken?

PS: look at this image: There the controller is shown at the bottom right:
https://phantompilots.com/attachments/20160504_215804-jpg.52691/
It's some type of quad flat package

I somehow have the feeling DJI removed the part number from the IC :(
 
Last edited:
Joined
Jun 18, 2017
Messages
74
Reaction score
12
Age
43
Location
France-Alpes Maritimes
[..]he bq20z95 provides [..]

I'll try to figure out what kind of chip the Phantom2 battery uses (was away for the weekend). Maybe I find a datasheet.

Do you have any idea at which level the Battery should be when resetting the chip? Some say it should be full, some say it should be empty. From my feeling I would say LiPo at 3.0V (= empty), reset controller and charge it to full. So the controller should count how many Ah went into the battery.

Or is this mistaken?

PS: look at this image: There the controller is shown at the bottom right:
https://phantompilots.com/attachments/20160504_215804-jpg.52691/
It's some type of quad flat package

I somehow have the feeling DJI removed the part number from the IC :(
On the Solo BMS board the chip reference is also erased. Maybe there is a reason for that?
 
Joined
Oct 12, 2018
Messages
3
Reaction score
1
Age
39
There's a chance the same procedure of the Solo battery recalibration would also work on a P2 battery:
3DR Solo - Smart Battery Calibration — Copter documentation
awesome!

The DJI Battery has a microcontroller installed with a charge controller I could no find any datasheet ;(

However: This tutorial works!

I discharged the battery slowly until it shut down itself. Then I did a reset of the controller and charged it again. In the DJI manual they write that you have to remove the charger when the battery is full, but I left it on for 2 days.
After disconnecting I waited 6h and put the battery into my phantom 2.

Now it says: "Full capacity: 5373mA of 5200mA" . I'll do an other show cycle and recharge it. Let's see what it tells me then. (before using it to fly this thing ... )
 

Attachments

  • Like
Reactions: bassmission
Joined
Jan 30, 2019
Messages
1
Reaction score
0
Age
46
I dont have an UNO, but I'll try to look into it this weekend; i have some atmega328 chips i can put to use.

I think the arduino UNO R3 A4 A5 pins are on pins 4 and 5 of Port C so you'd have to change the code to reflect the following pins and ports:

#define SCL_PIN 5 //Arduino UNO R3???
#define SCL_PORT PORTC

#define SDA_PIN 4 //Arduino UNO R3???
#define SDA_PORT PORTC


//AND ALSO COMMENT OUT THE PIN MODES
//SETUP I2C INPUT PINS
//pinMode(27,INPUT_PULLUP);
//pinMode(28,INPUT_PULLUP);


Arduino UNO R3 Pins 16/17 are PB2 and PB3 respectively, that would be Port B pins 2 and 3.

Give that a shot, if still no luck let me know and i'll see what i can put together.

EDIT: you will need to use 4.7k-ohm pull up resistors to 3.3v[/QUOTE
I dont have an UNO, but I'll try to look into it this weekend; i have some atmega328 chips i can put to use.

I think the arduino UNO R3 A4 A5 pins are on pins 4 and 5 of Port C so you'd have to change the code to reflect the following pins and ports:

#define SCL_PIN 5 //Arduino UNO R3???
#define SCL_PORT PORTC

#define SDA_PIN 4 //Arduino UNO R3???
#define SDA_PORT PORTC


//AND ALSO COMMENT OUT THE PIN MODES
//SETUP I2C INPUT PINS
//pinMode(27,INPUT_PULLUP);
//pinMode(28,INPUT_PULLUP);


Arduino UNO R3 Pins 16/17 are PB2 and PB3 respectively, that would be Port B pins 2 and 3.

Give that a shot, if still no luck let me know and i'll see what i can put together.

EDIT: you will need to use 4.7k-ohm pull up resistors to 3.3v
I'm a complete new comer to Arduino. This will be my first project. I have an Arduino UNO r3 with a surface mount Atmega 328p on it. I have the software and the Serial USB is working (tested with the blink sketch). I want to test 11.1v laptop batteries (3 Lipo cells in series). I know that the data output terminals on my batteries work with 3.3v. I am a bit of an electronics freak so I have plenty of 4,7k ohm resistors lying around. I usually don't hook anything up until I'm convinced that I know what I'm doing, especially with power levels that could blow up my new Arduino. There's a slightly confusing schematic posted here that shows SDA and SCL with pull up resistors to +VCC. It doesn't specify which +VCC but I'm assuming in my case that would be the one labeled 3.3v on my Arduino board. The other end is going to B1 and B4 (whatever that’s supposed to be). I'm thinking it should be the SB data and clock lines coming from my battery. My batteries have 9 wires on pin connectors, three are black and three are red; those are the + and – terminals. There’s a brown wire which is the battery present sensor, which allows output when connected to ground. The other two (yellow and blue) are probably the battery data and clock wires. They show up as 3.3v on the computer’s motherboard. I downloaded your sketch and the modifications you're talking about are already included. I'm really confused about the pin and port labeling. Looking at the Atmega chip, the pinout does not correspond to the numbering on the Arduino board. I too have 0 to 17 on the PWM side with 16 and 17 labeled SDA and SDL. I don't know how that translates to Pin5 or portC or Pin2 portB but I guess that isn't important as long as it works. I'm assuming these sockets need to be connected via pull up resistors with the socket labeled 3.3v on the power side of the Arduino board. In addition, the side before the pull up resistor would connect to the battery's data output lines. Ground should be connected to battery ground. Of course, there are several grounds to choose from on the Arduino board. I'm assuming they're all connected together. This also means that the Arduino ground (which is coming from my laptop's USB port) is indirectly connected to mains ground through the laptop’s switch mode power supply. I'm also assuming that I don't need to hook up the battery positive (+11.1v) to the Arduino at all because the data lines will also give me a readout of the voltage. Can you verify all of this and correct me where I'm wrong so I don't have to go around assuming things that I really should know before I start this project. Thanks in advance ;-)
 
Last edited:

New Threads

Members online

No members online now.

Forum statistics

Threads
11,923
Messages
139,813
Members
13,783
Latest member
bassanamit5