0

Situation

I wanna measure the temperature using LM35DZ on raspberry pi 3.

I'm using MCP3208 ADC. And since the other analogue sensors (eg. flame sensor..) are working normally, I have no problem with MCP3208.

Problem

But LM35DZ are not working with MCP3208, the outputs are always 0.

Here are my code with nodejs, a circuit and a pin map.

Code

var mcpadc = require('mcp-spi-adc');
var pigpio = require('pigpio');

function analogRead(channel) {
    return new Promise((resolve, reject) => {
        var sensor = mcpadc.openMcp3208(channel, (err) => {
            if (err) reject(err);
            sensor.read((err, reading) => {
                if (err) reject(err);
                resolve(reading);
            });
        });
    });
}

var Gpio = pigpio.Gpio;
var lm35;
var iv;

iv = setInterval(() => {
    analogRead(7).then((value) => {
        console.log(value);
    })

}, 300);

Result

...
{ rawValue: 0, value: 0 }
{ rawValue: 0, value: 0 }
{ rawValue: 0, value: 0 }
...

Circuit

pin map

sorry for my poor painting skills..
MCP3208 Din is not connected directly to GND.

And I add voltage divider on connection between MCP3208 Din and Pi MISO because someone said I must not put 5V signal into Rpi.

My Circuit and code are working well with the other sensors, but not working on LM35DZ.

1
  • Another thing to check. Make sure you have all your grounds tied together. I assumed that you did but if you are powering one or more of the devices with a separate source without a common gnd that will cause issues. Commented Feb 2, 2018 at 21:13

1 Answer 1

1

Have you confirmed communication is working between the RPi and the MCP3208 in this configuration? If it IS working then skip the next paragraph and start checking for functionality.

Both the LM35 and the MCP3208 can run on 3V3. (Always look at the datasheets to confirm.) So first thing is loose the voltage divider you made as I suspect that is probably messing up your communication between the RPi and the MCP3208.

You should be checking the functionality of the system starting at the LM35. Get a volt meter and confirm the LM35 is giving you a voltage level on the DATA pin.

If the DATA pin has a voltage then you have an issue further up the line.

If you have other sensors attached and they ARE working then simply swap out the data line from another sensor for the LM35 and confirm you are still seeing a value on Ch7. If you are seeing a value then try a pull down resistor of around 18K Ohm or more.

If you don't see a voltage value then you have an issue with either the port or the code you are using to read that port.

I'd first see if changing the port[Channel] in your code fixes the problem. If it does then you know that the port is suspect and you should avoid using it. If it doesn't work then time for you to debug the code.

LM35-datasheet

MCP3208-datasheet enter image description here

5
  • Thank you for your kind reply :D I checked as you said, but it didn't work. 1. functionality I didn't check a LM35DZ's DATA pin with a volt meter, but I confirm there's no problem with LM35DZ. Because when I tested LM35DZ on Arduino with same pin map on LM35DZ, it works well. 2. communication between RPi and MCP3208 LM35DZ operates on 4V ~ 30 V and MCP3208 does on 2.7V ~ 5.5V. I confirmed there's no problem 5V to LM35DZ, MCP3208. 3. swapping lines with working sensors. I did swap lines with other working sensors and tested port all of the port. It did not work on all ports.
    – Josh
    Commented Jan 31, 2018 at 8:47
  • so confused. Instead of solving this problem, I connected a additional Arduino to RPi via a serial port so Arduino is getting LM35DZ's data and sending them to Rpi. But I hope to solve this problem, and I will keep struggling. If you have other my problem's reason, please comment.
    – Josh
    Commented Jan 31, 2018 at 8:54
  • LM35 works. RPi to MCP3208 works. Using a known good sensor for an input you tested all the channels and found some channels[ports] NOT working. Did you check your code to see if there are code errors for those channels? Commented Jan 31, 2018 at 9:24
  • Sorry I said it wrong. All the ports on MCP3208 are working well with other working sensors but with LM35DZ , not working. And I checked code, there's no error. I tested other working sensors with SAME CODE, they worked well.
    – Josh
    Commented Jan 31, 2018 at 9:33
  • So you have a sensor (LM35) that works with direct connection to the Arduino but not to the MCP3208. Next is to look at what the difference is between the Arduino input and the MCP3208 input. I think the Arduino has built in pull-up or pull-down resistors (not 100% certain). I don't think the MCP has those. Try a pull down resistor like in Fig 16 of the TI datasheet. Commented Jan 31, 2018 at 17:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.