1
\$\begingroup\$

I am trying to read two gas sensors (MQ4 for methane and MQ7 for carbon monoxide) with my NodeMCU ESP8266. Both sensors require 5v (for the heaters) and have 4 pins (GND, VCC, DO, AO). Digital outputs are HIGH when a threshold is exceeded (adjustable on the breakout board). In order to read analog outputs, I am using MCP3008 10 bit ADC, which works with higher accuracy at 5V. ESP8266 is however 3.3V.

I am using 8-channel bi-directional level shifter to communicate with MCP3008. MCP3008 and sensors are connected to Vin and GND on NodeMCU ESP8266 board, which provides 5V.

Level shifter is also connected to 5V on HV side and 3.3V on LV side. Level shifter works fine for digital outputs of sensors. But when it comes to SPI between MCP3008 and NodeMCU ESP8266, I always read high values (1023). When I get rid of the level shifter and power MCP3008 with 3.3V with a potentiometer, I can read values between 0-1023. Also the sensors output analog values between 0-5V (tested with lighter gas and multimeter). So there must be a problem between level shifter and SPI communication.

On the software side, I tried to do the communication manually, with SPI.h and Adafruit_MCP3008.h libraries. They work fine, when I remove level shifter and operate MCP3008 with 3.3V.

I was wondering, what the problem might be? I don't have an oscillator and it is my first "real" electronics project. Excuse my lack of jargon... Thanks!

EDIT: I use this level shifter: https://www.amazon.de/gp/product/B01FRQUQCS/ref=oh_aui_detailpage_o00_s00?ie=UTF8&psc=1 Schematic Level shifter

\$\endgroup\$
20
  • \$\begingroup\$ Which level shifter are you using (I do not see it mentioned in your question)? Schematics would be nice to add too. \$\endgroup\$
    – Martin
    Commented Feb 18, 2018 at 20:32
  • \$\begingroup\$ @Martin I added the information. \$\endgroup\$ Commented Feb 18, 2018 at 20:40
  • 1
    \$\begingroup\$ @ChrisStratton Ok, I grounded LV3 (low voltage side of MISO), which reads 0. But when I ground HV3 (high voltage side it reads 1 (high)). Which is weird to me. When I plug the D6 MISO wire on LV side from LV3 during operation it is still high for a while. It gets low (0) when I insert it in GND. \$\endgroup\$ Commented Feb 19, 2018 at 0:50
  • 1
    \$\begingroup\$ That link is irrelevant and the "conclusion" there all but meaningless. You have a fundamental problem that your circuit does not work properly even when the input is produced by human hands. Until you fix that, there's little point in theorizing about anything else. \$\endgroup\$ Commented Feb 19, 2018 at 5:58
  • 2
    \$\begingroup\$ I’m voting to close this question because the asker has stated they no longer have access to the system and cannot remember the nature of the problem \$\endgroup\$ Commented Dec 9, 2020 at 4:12

1 Answer 1

0
\$\begingroup\$

My guess is that the problem is caused by the edges of the outgoing clock getting messed up by the level translator. That translator is really designed for I2C signals, which have very slow edges. SPI signals are designed to be driven high and low, while I2C signals are driven low and pulled high by resistors. You might be able to get it working by changing the HV side pullups to a lower value.

TI makes the SN74GTL2003 which is similar to the NMOS level translator you are using, but is designed to work at high speed. The main difference is that the TI part has several matched MOSFETs and uses one of them that's not used as an I/O to set the gate voltage for all of the MOSFETs. This sets the maximum voltage that is passed through. Pull up resistors on the high side then set the maximum voltage on the high side. This is all explained in the TI documentation.

\$\endgroup\$

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