Hoping someone can help me determine an issue I am experiencing.
When I plugin a grove 4 port SPDT relay to a i2c port my 2x16 LCD goes blank the first row show very faintly black square boxes
When I unplug the relay and reboot the arduino everything works fine.
I am trying to create a project to control turn on a dehumidifier if the room gets too humid, and 2 separate fans if the room gets too hot.
Current Setup
Aruduino Uno
Grove Hat
Temperature / Humidity Sensor (pro)
2x16 LCD on i2c port
4 port spdt relay on i2c port
power 9v battery
Any advice or documents you can forward me to would be greatly appreciated.
Hi there.
please remove these lines(use to change the device i2c address), it reads the i2c device address, if we plug one more i2c device, the code will detect 2 address and stop at this line.
/* Scan I2C device detect device address /
uint8_t old_address = relay.scanI2CDevice() ;
if((0x00 == old_address) || (0xff == old_address)) {
while(1);
}
Serial.println(“Start write address”);
relay.changeI2CAddress(old_address, 0x11); / Set I2C address and save to Flash */
Serial.println(“End write address”);
I also attached my code for lcd and spdt relay.
[code]#include <multi_channel_relay.h>
Multi_Channel_Relay relay;
#include <Wire.h>
#include “rgb_lcd.h”
rgb_lcd lcd;
const int colorR = 255;
const int colorG = 0;
const int colorB = 0;
void setup()
{
lcd.begin(16, 2);
lcd.setRGB(colorR, colorG, colorB);
// Print a message to the LCD.
lcd.print("hello, world!");
Serial.begin(9600);
while(!Serial);
/* Scan I2C device detect device address */
/*uint8_t old_address = relay.scanI2CDevice();
if((0x00 == old_address) || (0xff == old_address)) {
while(1);
}
Serial.println(“Start write address”);
relay.changeI2CAddress(old_address, 0x11);
Serial.println(“End write address”); */
/* Read firmware version */
Serial.print("firmware version: ");
Serial.print(“0x”);
Serial.print(relay.getFirmwareVersion(), HEX);
Serial.println();
}
void loop()
{
/**
- channle: 8 7 6 5 4 3 2 1
- state: 0b00000000 -> 0x00 (all off)
- state: 0b11111111 -> 0xff (all on)
*/
/* Begin Controlling Relay */
Serial.println(“Channel 1 on”);
relay.turn_on_channel(1);
delay(500);
Serial.println(“Channel 2 on”);
relay.turn_off_channel(1);
relay.turn_on_channel(2);
delay(500);
Serial.println(“Channel 3 on”);
relay.turn_off_channel(2);
relay.turn_on_channel(3);
delay(500);
Serial.println(“Channel 4 on”);
relay.turn_off_channel(3);
relay.turn_on_channel(4);
delay(500);
relay.turn_off_channel(4);
relay.channelCtrl(CHANNLE1_BIT |
CHANNLE2_BIT |
CHANNLE3_BIT |
CHANNLE4_BIT);
Serial.print("Turn all channels on, State: ");
Serial.println(relay.getChannelState(), BIN);
delay(2000);
relay.channelCtrl(CHANNLE1_BIT |
CHANNLE3_BIT);
Serial.print("Turn 1 3 channels on, State: ");
Serial.println(relay.getChannelState(), BIN);
delay(2000);
relay.channelCtrl(CHANNLE2_BIT |
CHANNLE4_BIT);
Serial.print("Turn 2 4 channels on, State: ");
Serial.println(relay.getChannelState(), BIN);
delay(2000);
relay.channelCtrl(0);
Serial.print("Turn off all channels, State: ");
Serial.println(relay.getChannelState(), BIN);
delay(2000);
}[/code]
Thank you, your solution worked!