LM75A, Arduino Nano

I am having difficulty connecting/reading a LM75A sensor. I don't do a lot with I2C, so I thought I would experiment with this sensor as it seemed fairly straight forward...

I don't see where the example code requires an I2C address...??? This library defaults to 0x48, which is what I am using... #define LM75A_DEFAULT_ADDRESS 0x48

  1. Example code from the library. No modifications
  2. Tried with and without pullup resistors
  3. A0-A2 pull down
  4. powered from 3.3v Nano
  5. Tried powering LM75A from external 3.3v source

==== Test result: FAILED ====Testing communication

isConnected: False - FAIL (1)
Testing temperature getters

getTemperature: LM75A_INVALID_TEMPERATURE - FAIL
getTemperatureInFarenheit: -1768.00 - OK
getHysterisisTemperature: LM75A_INVALID_TEMPERATURE - FAIL
getOSTripTemperature: LM75A_INVALID_TEMPERATURE - FAIL
Testing other getters

getFaultQueueValue: NUMBER_OF_FAULTS_4 - FAIL (NUMBER_OF_FAULTS_1)
getOsPolarity: OS_POLARITY_ACTIVEHIGH - FAIL (OS_POLARITY_ACTIVELOW)
getDeviceMode: DEVICE_MODE_INTERRUPT - FAIL (DEVICE_MODE_COMPARATOR)
Testing temperature setters

setHysterisisTemperature: -1000.00 - FAIL (62.00)
setOsTripTemperature: -1000.00 - FAIL (59.00)
Testing other setters

setFaultQueueValue: : NUMBER_OF_FAULTS_4 - OK
setOsPolarity: OS_POLARITY_ACTIVEHIGH - OK
setDeviceMode: DEVICE_MODE_INTERRUPT - OK
Testing shutdown

shutdown: True - OK
shutdown: True - FAIL (0)
==== Test result: FAILED ====



//---------------------------------------------------------------------------------------------
//
// Full library test example for the M2M_LM75A Arduino library.
//
// Copyright 2016-2017, M2M Solutions AB
// Written by Jonny Bergdahl, 2016-11-18
//
// Licensed under the MIT license, see the LICENSE.txt file.
//
//---------------------------------------------------------------------------------------------
//
////////////////////////////////////////////////////////////////////////////////////////////////
//
// Includes
//
#include <M2M_LM75A.h>

////////////////////////////////////////////////////////////////////////////////////////////////
//
// Global variables
//
M2M_LM75A lm75a;
bool testResult = true;
float oldHysterisisTemperature;
float oldOsTripTemperature;
FaultQueueValue oldFaultQueueValue;
OsPolarity oldOsPolarity;
DeviceMode oldDeviceMode;
float newHysterisisTemperature = 62.0f;
float newOsTripTemperature = 59.0f;
FaultQueueValue newFaultQueueValue = FaultQueueValue::NUMBER_OF_FAULTS_6;
OsPolarity newOsPolarity = OsPolarity::OS_POLARITY_ACTIVEHIGH;
DeviceMode newDeviceMode = DeviceMode::DEVICE_MODE_INTERRUPT;

////////////////////////////////////////////////////////////////////////////////////////////////
//
// Setup
//
void setup()
{
  lm75a.begin();
  while (!Serial); // Leonardo: wait for serial monitor
  Serial.begin(115200);
  Serial.println("Running M2M_LM75A Arduino library full test");
  Serial.println("===========================================");
  Serial.println("");
}

////////////////////////////////////////////////////////////////////////////////////////////////
//
// Loop
//
void loop()
{
  float temperature;

  Serial.println("Testing communication");
  checkTrueValue("isConnected", lm75a.isConnected(), true);
  Serial.println();

  Serial.println("Testing temperature getters");
  Serial.println("---------------------------");
  checkTemperatureResult("getTemperature", lm75a.getTemperature());
  checkTemperatureResult("getTemperatureInFarenheit", lm75a.getTemperatureInFarenheit());
  checkTemperatureResult("getHysterisisTemperature", lm75a.getHysterisisTemperature());
  checkTemperatureResult("getOSTripTemperature", lm75a.getOSTripTemperature());
  Serial.println();

  Serial.println("Testing other getters");
  Serial.println("---------------------");  
  checkFaultQueueValue("getFaultQueueValue", lm75a.getFaultQueueValue(), FaultQueueValue::NUMBER_OF_FAULTS_1);
  checkOsPolarityValue("getOsPolarity", lm75a.getOsPolarity(), OsPolarity::OS_POLARITY_ACTIVELOW);
  checkDeviceModeValue("getDeviceMode", lm75a.getDeviceMode(), DeviceMode::DEVICE_MODE_COMPARATOR);
  Serial.println();

  Serial.println("Testing temperature setters");
  Serial.println("---------------------------"); 
  oldHysterisisTemperature = lm75a.getHysterisisTemperature();
  oldOsTripTemperature = lm75a.getOSTripTemperature();

  lm75a.setHysterisisTemperature(newHysterisisTemperature);
  lm75a.setOsTripTemperature(newOsTripTemperature);

  checkTemperatureValue("setHysterisisTemperature", lm75a.getHysterisisTemperature(), newHysterisisTemperature);
  checkTemperatureValue("setOsTripTemperature", lm75a.getOSTripTemperature(), newOsTripTemperature);

  lm75a.setHysterisisTemperature(oldHysterisisTemperature);
  lm75a.setOsTripTemperature(oldOsTripTemperature);
  Serial.println();

  Serial.println("Testing other setters");
  Serial.println("---------------------");      
  oldFaultQueueValue = lm75a.getFaultQueueValue();
  oldOsPolarity = lm75a.getOsPolarity();
  oldDeviceMode = lm75a.getDeviceMode();

  lm75a.setFaultQueueValue(newFaultQueueValue);
  lm75a.setOsPolarity(newOsPolarity);
  lm75a.setDeviceMode(newDeviceMode);
  checkFaultQueueValue("setFaultQueueValue: ", lm75a.getFaultQueueValue(), newFaultQueueValue);
  checkOsPolarityValue("setOsPolarity", lm75a.getOsPolarity(), newOsPolarity);
  checkDeviceModeValue("setDeviceMode", lm75a.getDeviceMode(), newDeviceMode);

  lm75a.setFaultQueueValue(oldFaultQueueValue);
  lm75a.setOsPolarity(oldOsPolarity);
  lm75a.setDeviceMode(oldDeviceMode);

  Serial.println();

  Serial.println("Testing shutdown");
  Serial.println("----------------");      
  lm75a.shutdown();
  checkTrueValue("shutdown", lm75a.isShutdown(), true);
  lm75a.wakeup();
  checkTrueValue("shutdown", lm75a.isShutdown(), false);
  Serial.println();

  Serial.print("==== ");
  Serial.print("Test result: ");
  Serial.print(testResult ? "OK" : "FAILED");
  Serial.print(" ====");

  // while (true)
  //   ;
  delay(10000);
}

void checkTemperatureResult(const char* caption, const float value)
{
  bool fail = value == LM75A_INVALID_TEMPERATURE;
  if (fail)
  {
    testResult = false;
  }
  Serial.print(caption);
  Serial.print(": ");
  if (fail)
  {
    Serial.print("LM75A_INVALID

_TEMPERATURE");
  }
  else
  {
    Serial.print(value);
  }
  Serial.print(" - ");
  Serial.println(fail ? "FAIL" : "OK");
}

void checkTemperatureValue(const char* caption, const float value, const float expected)
{
  bool fail = value != expected;
  Serial.print(caption);
  Serial.print(": ");
  Serial.print(value);
  Serial.print(" - ");
  if (fail)
  {
    testResult = false;
    Serial.print("FAIL (");
    Serial.print(expected);
    Serial.println(")");
  }
  else
  {
    Serial.println("OK");
  }
}

void check8BitValue(const char* caption, const uint8_t value, const uint8_t expected)
{
  bool fail = value != expected;
  Serial.print(caption);
  Serial.print(": ");
  Serial.print(value);
  Serial.print(" - ");
  if (fail)
  {
    testResult = false;
    Serial.print("FAIL (");
    Serial.print(expected);
    Serial.println(")");
  }
  else
  {
    Serial.println("OK");
  }
}

void checkFaultQueueValue(const char* caption, const FaultQueueValue value, const FaultQueueValue expected)
{
  bool fail = value != expected;
  Serial.print(caption);
  Serial.print(": ");
  Serial.print(getFaultQueueValueString(value));
  Serial.print(" - ");
  if (fail)
  {
    testResult = false;
    Serial.print("FAIL (");
    Serial.print(getFaultQueueValueString(expected));
    Serial.println(")");
  }
  else
  {
    Serial.println("OK");
  }  
}

void checkOsPolarityValue(const char* caption, const OsPolarity value, const OsPolarity expected)
{
  bool fail = value != expected;
  Serial.print(caption);
  Serial.print(": ");
  Serial.print(getOsPolarityString(value));
  Serial.print(" - ");
  if (fail)
  {
    testResult = false;
    Serial.print("FAIL (");
    Serial.print(getOsPolarityString(expected));
    Serial.println(")");
  }
  else
  {
    Serial.println("OK");
  }
}

void checkDeviceModeValue(const char* caption, const DeviceMode value, const DeviceMode expected)
{
  bool fail = value != expected;
  Serial.print(caption);
  Serial.print(": ");
  Serial.print(getDeviceModeString(value));
  Serial.print(" - ");
  if (fail)
  {
    testResult = false;
    Serial.print("FAIL (");
    Serial.print(getDeviceModeString(expected));
    Serial.println(")");
  }
  else
  {
    Serial.println("OK");
  }
}

void checkTrueValue(const char* caption, const bool value, const bool expected)
{
  bool fail = value != expected;
  Serial.print(caption);
  Serial.print(": ");
  Serial.print(value ? "True" : "False");
  Serial.print(" - ");
  if (fail)
  {
    testResult = false;
    Serial.print("FAIL (");
    Serial.print(expected);
    Serial.println(")");
  }
  else
  {
    Serial.println("OK");
  }
}

const char* getFaultQueueValueString(const FaultQueueValue value)
{
  switch (value)
  {
    case FaultQueueValue::NUMBER_OF_FAULTS_1:
      return "NUMBER_OF_FAULTS_1";
    case FaultQueueValue::NUMBER_OF_FAULTS_2:
      return "NUMBER_OF_FAULTS_2";
    case FaultQueueValue::NUMBER_OF_FAULTS_4:
      return "NUMBER_OF_FAULTS_4";
    case FaultQueueValue::NUMBER_OF_FAULTS_6:
      return "NUMBER_OF_FAULTS_4";
    default:
      return "** ILLEGAL VALUE **";
  }
}

const char* getOsPolarityString(const OsPolarity value)
{
  switch (value)
  {
    case OsPolarity::OS_POLARITY_ACTIVEHIGH:
      return "OS_POLARITY_ACTIVEHIGH";
    case OsPolarity::OS_POLARITY_ACTIVELOW:
      return "OS_POLARITY_ACTIVELOW";
    default:
      return "** ILLEGAL VALUE **";
  }
}

const char* getDeviceModeString(DeviceMode value)
{
  switch (value)
  {
    case DeviceMode::DEVICE_MODE_COMPARATOR:
      return "DEVICE_MODE_COMPARATOR";
    case DeviceMode::DEVICE_MODE_INTERRUPT:
      return "DEVICE_MODE_INTERRUPT";
    default:
      return "** ILLEGAL VALUE **";
  }
}

You seem to have a 5volt-logic 16Mhz Nano v3.
Why did you power the LM75 from 3.3volt, while it should be powered with 5volt.
That may not fix your problem though.

Did you use an I2C scanner, to make sure the chip is recognised.
Leo..

I am not sure what the BOLD screaming is about but after carefully studying the Schematic you did not post I cannot find the required pull up resistors for the I2C bus to the +5 (3V3 does not make sense on 5V parts [Nano and Sensor]). The missing link on your module does not show anything. Another thing that is confusing

There are 2x 10K, 1x 200K and 1x 1K resistors on the module. I assume I don't need external pullups with this module? Examples online doesn't seem to use external resistors pullups with this module. I'm reading 4.7v on the SCL and SDA lines w/o any external pullups.

"Power supply range: 2.8V ~ 5.5V, temperature range: -55 ° C ~ +125 ° C"
I tried 5v too, but that didn't work either. I loaded the scanner example and I get nothing, so maybe bad module?

I tried a second module (accidently soldered the header upside down) 5v, and ran the I2CScanner with and without 2.2k pullup resistors:

--- Scan started ---
No I2C devices found
--- Scan finished ---

#include "I2CScanner.h"
#include <Wire.h>

I2CScanner scanner;

//if you use ESP8266-01 with not default SDA and SCL pins, define these 2 lines, else delete them	
#define SDA_PIN 4	
#define SCL_PIN 5

void setup() 
{	
	//uncomment the next line if you use custom sda and scl pins for example with ESP8266-01 (sda = 4, scl = 5)
	//Wire.begin(SDA_PIN, SCL_PIN);
	
	Serial.begin(9600);
	while (!Serial) {};

	scanner.Init();
}

void loop() 
{
	scanner.Scan();
	delay(5000);
}

thanks for your feedback.
I didn't make that bold. That was done by the website. I think the website thinks it's code...?
I posted the photo instead of a schematic. I thought that was enough for the 4 wires, but I can post one if you think a schematic will help.
The IC itself will run at 2.8v. I thought 3.3 was enough, but I tested up to 5v anyway with no improvement

A lower supply voltage for the LM75 means a different (higher) logic voltage on the I2C lines. The internal 5volt pull up of the Nano will try to phantom-power the LM75 through it's data lines, which can be bad.
Leo..

That's good to know... I'm used to ESP32, so I was being conservative. with 3.3v. But, I tried 5v and didn't get anything better. I had a second module, but that gave the same results. I tried the scanner example, but got nothing from that on either module.

The ESP32 is a 3.3volt-logic processor. Then the LM75 must be powered from 3.3volt.

No idea what's wrong. Wiring and soldering looks fine.
The I2C scanner is your first stop, and should return something.
So both sensors could be faulty.

Did you try the Nano v3 with a different I2C module.
Leo..

The only other I2C sensor I have is a VL53L0X. I tried that with another scanner sketch and got the same...

I2C scanner. Scanning ...
Done.
Found 0 device(s).

I've read where people were having problems with I2C on the "nano", so I ordered a couple UNO boards and will try that.

Did you try an I2C scanner, to see whether the module even responds to a connection attempt - and at the same time to which address it responds?

I used the same scanner sketch on an ESP32 and made the 4-wire connections. Worked perfectly... There seems to be something about the nano that's the issue.

--- Scan started ---
I2C device found at address 0x29 !
--- Scan finished ---

I wonder if you need a Wire.begin(); in setup().
Some libraries do, others don't.
Leo..

Wonder how many bytes of Nano's 2048 byte SRAM is taken up with all those character strings?

Here is a link to example usage of the LM75A with Arduino:

They do use: #include <Wire.h>

Hi, @mej7000

Did you measure those pullup resistors?
They look like 5 band resistors and 220R in value.
If they are 4 band then 22R.

Tom.. :grinning: :+1: :coffee: :australia:

red = 2
red = 2
black = 0
brown = one zero

2200 = 2k2

The thin brown line is the 1% tolerance indicator.

The module has 10k pull up, the Nano adds ~30k to that.
I don't see why extra external pull up is needed with these short wires.
Leo..

As for your Nano, has it been used for other projects? You could always verify that SCL and SDA are good by simply using Blink.ino with a resistor and LED; make sure you try both high and low level drives for the LED(don't forget to reverse the LED when you make the change), so you completely trust the pins going forward. Seriously, nothing like going back to boot camp to make sure you're not fighting a broken Nano. If it works, you look elsewhere, if it doesn't then it hits the garbage can.

That's a good thought. I measured the resistors and they are 2.2K.

Thanks! That's what I did, but with a Nano. I ordered some Uno's to double check, but I got I2C Scanner working immediately on an ESP32, where I couldn't get it to work on the Nano... I think there is something weird about my Nano or the Nano's generally... I need to check the actual pin outputs, but my Nano has no problem with "Hello World"

FWIW, the I2C scan works on my clone nanos, clone and real Unos, and my Mega. So, I still think you are, or have, done something 'off' to your device(s).