I2C Connections...Arduino Nano

I've done some very basic stuff with Arduino's and I'm looking for some help to build a small project simply for testing purposes. I have an Arduino nano, and I have a board called the Amp Ripper 4000. The amp ripper board has I2C connections so battery voltage can be measured, they even include some basic Arduino sketches. What I don't know is how to connect the two together for I2C communication.

Here is the data sheet for the amp ripper

Here is the sketch I'm using:

/******************************************************************************
Example1_Simple
By: Paul Clark
Date: October 23rd 2020

Based extensively on:
MAX17043_Simple_Serial.cpp
SparkFun MAX17043 Example Code
Jim Lindblom @ SparkFun Electronics
Original Creation Date: June 22, 2015

This file demonstrates the simple API of the SparkFun MAX17043 Arduino library.

This example will print the gauge's voltage and state-of-charge (SOC) readings
to Serial (115200 baud)

This code is released under the MIT license.

Distributed as-is; no warranty is given.
******************************************************************************/

#include <Wire.h> // Needed for I2C

#include <SparkFun_MAX1704x_Fuel_Gauge_Arduino_Library.h> // Click here to get the library: http://librarymanager/All#SparkFun_MAX1704x_Fuel_Gauge_Arduino_Library

SFE_MAX1704X lipo; // Defaults to the MAX17043

//SFE_MAX1704X lipo(MAX1704X_MAX17043); // Create a MAX17043
//SFE_MAX1704X lipo(MAX1704X_MAX17044); // Create a MAX17044
//SFE_MAX1704X lipo(MAX1704X_MAX17048); // Create a MAX17048
//SFE_MAX1704X lipo(MAX1704X_MAX17049); // Create a MAX17049

double voltage = 0; // Variable to keep track of LiPo voltage
double soc = 0; // Variable to keep track of LiPo state-of-charge (SOC)
bool alert; // Variable to keep track of whether alert has been triggered

void setup()
{
	Serial.begin(115200); // Start serial, to output debug data
  while (!Serial)
    ; //Wait for user to open terminal
  Serial.println(F("MAX17043 Example"));

  Wire.begin();

  lipo.enableDebugging(); // Uncomment this line to enable helpful debug messages on Serial

  // Set up the MAX17043 LiPo fuel gauge:
  if (lipo.begin() == false) // Connect to the MAX17043 using the default wire port
  {
    Serial.println(F("MAX17043 not detected. Please check wiring. Freezing."));
    while (1)
      ;
  }

	// Quick start restarts the MAX17043 in hopes of getting a more accurate
	// guess for the SOC.
	lipo.quickStart();

	// We can set an interrupt to alert when the battery SoC gets too low.
	// We can alert at anywhere between 1% - 32%:
	lipo.setThreshold(20); // Set alert threshold to 20%.
}

void loop()
{
  // lipo.getVoltage() returns a voltage value (e.g. 3.93)
  voltage = lipo.getVoltage();
  // lipo.getSOC() returns the estimated state of charge (e.g. 79%)
  soc = lipo.getSOC();
  // lipo.getAlert() returns a 0 or 1 (0=alert not triggered)
  alert = lipo.getAlert();

  // Print the variables:
  Serial.print("Voltage: ");
  Serial.print(voltage);  // Print the battery voltage
  Serial.println(" V");

  Serial.print("Percentage: ");
  Serial.print(soc); // Print the battery state of charge
  Serial.println(" %");

  Serial.print("Alert: ");
  Serial.println(alert);
  Serial.println();

  delay(500);
}

SDA to SDA
SCL to SCL
GND to GND

You may need to add pull-ups to these lines if they are not already there; 4.7k to 10k.

1 Like

Nano SDA is A4, SCL is A5 and GND is, of course, GND

1 Like

Working on this...

The documentation for both SDA and SCL states "Pulled up to LV+ with a 10K resistor."

Right now I have the resistors in line on both the SCL and SDA and I'm not getting any data. Does it mean one end of the resistor needs to be connected to a 5v rail?

I've attached a screen shot as well of the doc section.

Are they really in line ? They should be used as pull-ups

I'm still learning here...forgive me for my stupidity...pull up means connected to a 5v rail as noted?

The pull-up resistor goes from the pin to 5V to keep the pin state HIGH until pulled LOW by the signal

1 Like

Something like these can be used with 3v3 to 5v communications.

i2c level shifter

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.