Netduino home hardware projects downloads community

Jump to content


The Netduino forums have been replaced by new forums at community.wildernesslabs.co. This site has been preserved for archival purposes only and the ability to make new accounts or posts has been turned off.
Photo

Getting Battery Level Reading from LiPower Shield

lipower sparkfun i2c lipo battery

  • Please log in to reply
5 replies to this topic

#1 Chas.

Chas.

    New Member

  • Members
  • Pip
  • 8 posts

Posted 19 January 2013 - 07:06 PM

Anyone figure out how to get the battery level reading from Sparkfun's LiPower shield using a Netduino Plus 2?

 

I've added the shield and connected the shield's A04 to N+2's SDA and A05 to SCL.  Also tried no additional connections (just the A04/05 connected through the stackable headers).

 

Specifically, I'm just trying to get the percentage battery level from the LiPower's MAX17043's SOC (state of charge) register.  I'm using 0x36 to identify the device and 0x04 to identify the SOC register, as per Sparkfun's sample Arduino code.

 

Here's my code.  It always returns exec = 0, so even the write transaction fails.

 

I2CDevice.Configuration con = new I2CDevice.Configuration(0x36, 50);I2CDevice MyI2C = new I2CDevice(con);I2CDevice.I2CTransaction[] xActions = new I2CDevice.I2CTransaction[2];byte[] RegisterNum = new byte[1] { 0x04 };xActions[0] = I2CDevice.CreateWriteTransaction(RegisterNum);byte[] RegisterValue = new byte[2] { 0, 0 };xActions[1] = I2CDevice.CreateReadTransaction(RegisterValue);int exec = 0;exec = MyI2C.Execute(xActions, 1000);if (exec == 0){ Debug.Print("Failed to perform I2C transaction"); }else{ Debug.Print("Register value: " + RegisterValue[0].ToString()); }

 

Anyone able to get battery level readings from LiPower?  How?



#2 JerseyTechGuy

JerseyTechGuy

    Advanced Member

  • Members
  • PipPipPip
  • 870 posts

Posted 19 January 2013 - 11:49 PM

Sometimes you can have a noisy startup and need to issue a quick reset with this fuel gauge chip.  Try to write a 0x4000 to the MODE register before performing any reads or writes and give it a short sleep after the reset.  Other than that the code looks ok.



#3 Chas.

Chas.

    New Member

  • Members
  • Pip
  • 8 posts

Posted 20 January 2013 - 04:56 PM

Sometimes you can have a noisy startup and need to issue a quick reset with this fuel gauge chip.  Try to write a 0x4000 to the MODE register before performing any reads or writes and give it a short sleep after the reset.  Other than that the code looks ok.

 

Great point.  Missed that QuickStart in the data sheet.  Thanks.  Unfortunately, after giving it a try I'm getting 0 successful transactions executed, even when writing 0x4000 to the MODE register.  Here's the code I added before trying to read the SOC register:

 

I2CDevice.I2CTransaction[] I2CLiPowerQuickStart = new I2CDevice.I2CTransaction[2];byte[] RegisterMode = new byte[1] { 0x06 };I2CLiPowerQuickStart[0] = I2CDevice.CreateWriteTransaction(RegisterMode);byte[] RegisterModeValue = new byte[2] { (byte)(0x4000 >> 8), (byte)(0x4000 & 0xFF) };I2CLiPowerQuickStart[1] = I2CDevice.CreateWriteTransaction(RegisterModeValue);int exec = 0;exec = MyI2C.Execute(I2CLiPowerQuickStart, 1000);Thread.Sleep(1000);

 

Maybe I'm making a newbie mistake with the way I'm wiring up the LiPower shield?  Currently I'm trying it in 2 configurations:

 

(1) I soldered stackable headers onto the shield and just put it on the Netduino Plus 2, nothing else, which I believe means A04==SDA and A05==SCL

 

(2) In addition to #1, I used standard male/male jumper wires in the shield's stackable headers to connect the shield's A04 to N+2's dedicated SDA (not A04) and the shield's A05 to N+2's dedicated SCL (not A05).

 

Neither configuration works.  Both give exec==0 after both attempts at Execute()--first attempt to write 0x4000 to MODE, second attempt to read the SOC register.

 

Am I doing something wrong in how I use the shield?  Any other software mistakes?



#4 JerseyTechGuy

JerseyTechGuy

    Advanced Member

  • Members
  • PipPipPip
  • 870 posts

Posted 20 January 2013 - 05:24 PM

Out of curiosity what firmware version are you running on the ND+2?  If it hasn't been upgraded to the latest version or at least 4.2.1.0 there were I2C issues in the version that somes with the ND+2.



#5 Chas.

Chas.

    New Member

  • Members
  • Pip
  • 8 posts

Posted 20 January 2013 - 05:49 PM

I'll upgrade to Chris' latest in this post to see if that helps.

 

Currently I'm using what was the latest on the Downloads page as of end of 2012 (just days before Chris' post).  References in the VS2010 project are...

 

Microsoft.SPOT.Hardware = 4.2.0.0

Microsoft.SPOT.Hardware.PWM = 4.2.0.1

Microsoft.SPOT.Hardware.SerialPort = 4.2.0.0

Microsoft.SPOT.Native = 4.2.0.0

Microsoft.SPOT.Net = 4.2.0.0

mscorlib = 4.2.0.0

SecretLabs.NETMF.Hardware = 4.2.0.0

SecretLabs.NETMF.Hardware.Netduino = 4.2.1.0

 

Dump from MFDeploy's "Device Capabilities:"

 

 

HalSystemInfo.halVersion:               4.2.0.0
HalSystemInfo.halVendorInfo:            Netduino Plus 2 (v4.2.1.2) by Secret Labs LLC
HalSystemInfo.oemCode:                  34
HalSystemInfo.modelCode:                177
HalSystemInfo.skuCode:                  4102
HalSystemInfo.moduleSerialNumber:       00000000000000000000000000000000
HalSystemInfo.systemSerialNumber:       0000000000000000
ClrInfo.clrVersion:                     4.2.0.0
ClrInfo.clrVendorInfo:                  Netduino Plus 2 (v4.2.1.2) by Secret Labs LLC
ClrInfo.targetFrameworkVersion:         4.2.0.0
SolutionReleaseInfo.solutionVersion:    4.2.1.2
SolutionReleaseInfo.solutionVendorInfo: Netduino Plus 2 (v4.2.1.2) by Secret Labs LLC
SoftwareVersion.BuildDate:              Dec  3 2012
SoftwareVersion.CompilerVersion:        410894
FloatingPoint:                          True
SourceLevelDebugging:                   True
ThreadCreateEx:                         True
LCD.Width:                              0
LCD.Height:                             0
LCD.BitsPerPixel:                       0
AppDomains:                             True
ExceptionFilters:                       True
IncrementalDeployment:                  True
SoftReboot:                             True
Profiling:                              False
ProfilingAllocations:                   False
ProfilingCalls:                         False
IsUnknown:                              False
 
Will try the release in Chris' post and report how it goes.


#6 Chas.

Chas.

    New Member

  • Members
  • Pip
  • 8 posts

Posted 20 January 2013 - 07:48 PM

Upgraded, but getting same result.  exec == 0 for both I2C transactions.

 

VS2010 project references are the same versions as I listed before the upgrade.  (I'm assuming that's OK.)

 

New dump from MFDeploy Device Capabilities:  (I'm assuming this is OK, since SolutionReleaseInfo.solutionVersion is now 4.2.2.0, where it was 4.2.1.2 before.)

 

 

HalSystemInfo.halVersion:               4.2.0.0
HalSystemInfo.halVendorInfo:            Netduino 2 (v4.2.2.0) by Secret Labs LLC
HalSystemInfo.oemCode:                  34
HalSystemInfo.modelCode:                177
HalSystemInfo.skuCode:                  4101
HalSystemInfo.moduleSerialNumber:       00000000000000000000000000000000
HalSystemInfo.systemSerialNumber:       0000000000000000
ClrInfo.clrVersion:                     4.2.0.0
ClrInfo.clrVendorInfo:                  Netduino 2 (v4.2.2.0) by Secret Labs LLC
ClrInfo.targetFrameworkVersion:         4.2.0.0
SolutionReleaseInfo.solutionVersion:    4.2.2.0
SolutionReleaseInfo.solutionVendorInfo: Netduino 2 (v4.2.2.0) by Secret Labs LLC
SoftwareVersion.BuildDate:              Jan  9 2013
SoftwareVersion.CompilerVersion:        410894
FloatingPoint:                          True
SourceLevelDebugging:                   True
ThreadCreateEx:                         True
LCD.Width:                              0
LCD.Height:                             0
LCD.BitsPerPixel:                       0
AppDomains:                             True
ExceptionFilters:                       True
IncrementalDeployment:                  True
SoftReboot:                             False
Profiling:                              False
ProfilingAllocations:                   False
ProfilingCalls:                         False
IsUnknown:                              False
 

Any other ideas what might be going wrong?  (Thanks for your help so far.)







Also tagged with one or more of these keywords: lipower, sparkfun, i2c, lipo, battery

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users

home    hardware    projects    downloads    community    where to buy    contact Copyright © 2016 Wilderness Labs Inc.  |  Legal   |   CC BY-SA
This webpage is licensed under a Creative Commons Attribution-ShareAlike License.