I2C and analog together?

Grove is a modulated, ready-to-use tool set.
Much like Lego, it takes a building block approach to assembling electronics.

Moderators: lily.li, violet, jeremy882, crail.lyu969

Post Reply
weibull760
Pre-kindergarten
Pre-kindergarten
Posts: 5
Joined: Thu Dec 20, 2018 3:13 pm

I2C and analog together?

Post by weibull760 » Sat Jan 12, 2019 4:17 pm

So I'm trying to create a temperature gauge using a Seeeduino V4.2, the LCD RGB Backlight, and the High Temp sensor. I know that the LCD uses I2C and that the Temp sensor is analog but I can't seem to get them both working at the same time. The LCD basically freezes up when the temp sensor is plugged in either the second I2C port or the UART port.

Is this because the analog signal is interfering with the I2C data?

I can get the temp to read through the serial monitor if the LCD isn't plugged in, or the LCD working with the code below if the temp sensor isn't plugged in.

Is there anyway to get them both to work at the same time? The code below is basically my starting point for my future project.

Thanks!

Code: Select all

#include <Wire.h>
#include "rgb_lcd.h"
#include "High_Temp.h"

rgb_lcd lcd;

HighTemp ht(A4, A5);

void setup() 
{
    // set up the LCD's number of columns and rows:
    lcd.begin(16, 2);
    // Print a message to the LCD.
    lcd.print("Fade/Temp Demo");
    ht.begin();
}

void breath(unsigned char color)
{

    for(int i=10; i<255; i++)
    {
        lcd.setPWM(color, i);
        delay(5);
    }

    lcd.setCursor(0, 1);
    lcd.print("Temp = ");
    lcd.setCursor(7, 1);
    lcd.print(ht.getThmc());
    
    for(int i=254; i>=10; i--)
    {
        lcd.setPWM(color, i);
        delay(5);
    }

}

void loop() 
{
    breath(REG_RED);
    breath(REG_GREEN);
    breath(REG_BLUE);
}

weibull760
Pre-kindergarten
Pre-kindergarten
Posts: 5
Joined: Thu Dec 20, 2018 3:13 pm

Re: I2C and analog together?

Post by weibull760 » Wed Jan 16, 2019 1:44 am

Has anyone here used I2C and analog sensors together before? I'm new to Arduino and Grove so I'm not sure if I'm trying to do something that isn't possible or if I just need to connect them differently.

Thanks.

pbanders
Pre-kindergarten
Pre-kindergarten
Posts: 11
Joined: Mon Dec 10, 2018 10:48 pm

Re: I2C and analog together?

Post by pbanders » Wed Jan 16, 2019 12:02 pm

I think the problem you're having is that you're using A4/A5 for the analog input for the temp sensor, right? A4 and A5 are also SCL and SDA on the I2C bus, you can't be using them and I2C at the same time. Try switching to A0/A1 for the temperature sensor.

weibull760
Pre-kindergarten
Pre-kindergarten
Posts: 5
Joined: Thu Dec 20, 2018 3:13 pm

Re: I2C and analog together?

Post by weibull760 » Thu Jan 17, 2019 1:21 am

Thank you so much! Yep that was it. I had to wire the temp sensor directly to the analog pins A0 & A1 on the side to get it to work.

Things seem to be working nicely now. Appreciate the help.

Post Reply