Connect 2 I2C HW to NodeMCU - OLED and ADS1115

Hello,

is it possible to connect 2 I2C devices to NodeMUC?

I have:

  • ADS1115 for using more than 1 analog input
  • OLED 0,96 inches

They both seem to be using the pins D1 and D2 for SCL/SDA.

Is there a way to use both?

is it possible to connect 2 I2C devices to NodeMUC?

Yes.

They both seem to be using the pins D1 and D2 for SCL/SDA.

Yes that is how the I2C system works you connect the same two pins to the two devices. The only caveat is that the two devices must have different addresses. This is normally achieved by changing a link on one of them.

Grumpy_Mike:
This is normally achieved by changing a link on one of them.

However in this case, the two you cite probably already have different I2C addresses.

How about you examine their datasheets? :cold_sweat:

Could also try an I2C scanner program
See Nick Gammon's about 2/3 of the way down this page.

Do you have 4.7K pullup resistors installed?

Or 3.3Ks to 3.3V?

Thanks a lot for the replies... very helpful!

Do I need resistors to connect OLED and ADS1115 (it already has some resistors built in) ?

As I understand, ASD1115 can easily change address connecting the ADR pin:
ADR -> GND 0x48
ADR -> VDD 0x49
ADR -> SDA 0x4A
ADR -> SCL 0x4B

While for Oled it should be 0x3C.

I'm a newby to this, and I'm trying to design this circuit on the paper first.

I want to connect:

  • NodeMCU 12F
  • ADS1115
  • OLED 0,96 inch
  • GY-68 BMP180 - (Pressure Sensor)
  • MQ-2 - (Gas Sensor - Analog)
  • AM312 - (PIR)
  • KY-108 - (Light Sensor - Analog)
  • DHT22 - (Temperature/Humidity Sensor)
  • RGB common catode led

Do you think I can connect all? Any idea of the schema?

Do you think I can connect all?

Yes probably but not all of these have an I2C interface. You have to sort out exactly what sort of interface that have before you can design a schematic. And some devices / boards offer a choice of interface. The two most common are SPI and I2C and both can have multiple devices connected to them.

Some devices require connections to an analogue input pin and others to PWM capable pins. You need to look up the data sheet for each device or board you have.

Do I need resistors to connect OLED and ADS1115 (it already has some resistors built in)

The I2C lines need a pull up resistor on each line. That is a resistor from the line to 5V, a 4K7 will do. Some boards do have built in pull up resistors but these are often a high value so you are better off using external ones. These are needed because I2C lines only need pulling to ground, they never send a 5V signal. In that way you can connect many lines together.

I want to connect:

  • NodeMCU 12F
  • ADS1115
  • OLED 0,96 inch
  • GY-68 BMP180 - (Pressure Sensor)
  • MQ-2 - (Gas Sensor - Analog)
  • AM312 - (PIR)
  • KY-108 - (Light Sensor - Analog)
  • DHT22 - (Temperature/Humidity Sensor)
  • RGB common catode led

The NodeMCU looks like it has lots of pins, but unfortunately many of them are not useful. There are only in fact 8 digital pins you can use, and one analog, as you already figured out, so you have to be a little careful with your choice of components, or you will run out of pins very quickly.

I guess you already have these components because they came in an Arduino starter kit?

The bmp180 is also i2c, so that can share the same pins as the oled and ads1115. However if you buy a bme280 (not a bmp280, they are not the same) then that is also i2c and can replace the bmp180 and the dht22, because bme280 measures pressure, temp and humidity.

You could also get a bh1750 light sensor, which is also i2c. If you do that, the only remaining analog sensor is the gas sensor, so you could use the NodeMCU's analog pin for that, and you would not need the ads1115.

When connecting the RGB led, take care with the series resistor values. The NodeMCU's pins can only source about 12mA, much lower than most Arduino, so you will need to use higher value resistors and the led will not be as bright.

But if you must use those components because you already have them...

Oled, bmp180, ads1115 ..... 2 pins
Gas sensor and light sensor connect to the ads1115 .... so no pins
PIR sensor .... 1 pin
Dht22 sensor .... 1 pin
Rgb led .... 3 pins

Total .... 7 pins, so you should be ok.

Thanks for your comprehensive reply. I already ordered the above components from AliExpress and I need to deal with them... :frowning:

Would you mind showing me how to wire the 7 pins and the I2C components, with the resistors?

I would really appreciate it.

Thanks!!!

Why not wait until after your components have arrived and ask about wiring then?

This wiring is simple. Google for example of how to wire each of your components to an Arduino. Then draw a schematic and post it here. We will check it for you.

I will post a wiring schema, thanks

As I see there are 9 D pins (from D0 to D8) that I can use, and I need 7... but 3 of them doesn't seem to be usable:

D0, D3, D4.

Why can't I use them? If I try to connect something to them, either I'm not able to flash or the NodeMCU doesn't start.

Yes, D0 is a little strange, avoid using that if you can.

D3 & D4 need to be pulled up by on-board resistors for boot, so don’t attach anything that would pull them down. D8 is also important. It is pulled down by on-board resistor, so don’t attach anything that would pull it up.

I think both the PIR sensor and the DHT require pull-ups, so you should be able to use D3 & D4 for those.

Don’t use D3 or D4 for your RGB led, because that will pull them down. But you can use D8 for the RGB LED.

On second thoughts, don't use D3 or D4 for the PIR sensor. You would either have to disconnect it or keep very still during boot/flash!

I wired all except AM312 - (PIR) cause they didn’t deliver it to me, yet.

I seem to get reasonable values except from analog devices (MQ-2 and KY-108) connected to ADS1115.

  • For KY-108 I got values of 10924, while using A0 pin I was getting values between 50 and 1024.
  • For MQ-2 I got values of 10054 with no fire :D, while the expected threshold is 600…

I’m using:
#include <Adafruit_ADS1015.h>
Adafruit_ADS1115 ads(0x48);

light = ads.readADC_SingleEnded(0);
gas = ads.readADC_SingleEnded(1);

Shall I set the gain? How to calculate it?

What about the KY-108 value? Real ones seem to be between 50 max light and 1024 zero light… how can I calculate the lux ?

Wiring

Btw... KY-018 is connected to Vin 5V while MQ-2 is connected to 3V3...

Is it a problem?

Please select More:Modify on your post, and use the Attachment and other options to Attach your wiring diagram. Folks will not chase imgur to find your diragram/

Done!


Holy crap!!!

Pardon my language. That's not how you use a breadboard.

Plug the devices directly into the breadboard.

Have a look at this. It's an extreme example, but hopefully you get the idea.

I use breadboard only for test... I will solder all together later on