mLink 4x4 Matrix Keypad (HCMODU0188)
Re: mLink 4x4 Matrix Keypad (HCMODU0188)
Thank you. I'll give that a try. PhillipH
Re: mLink 4x4 Matrix Keypad (HCMODU0188)
I am happy to say your solution is now working well but is identifying a problem with the receiving slave sketch: copy below.
When the Route 1 is selected, the relay cycles continuously between open and closed and only stops when Route 2 is selected, when it's relay cycles continuously. The serial monitor also shows either 1 or 2 repeatedly.
I appreciate this is not a problem with your hardware but apparently a software one. As far as I can tell my hardware is fully serviceable. I'd appreciate any assistance you can give.
Many thanks
PhillipH
/*
4x4 I2C Slave Relay Demo
using Arduino Mega
*/
// Include Arduino Wire library for I2C
#include <Wire.h>
// Define Slave I2C Address
#define SLAVE_ADDR 9
//define Relay States
#define N_CLOSED 1
#define N_OPEN 0
#define Relay_1 53
#define Relay_2 52
// Variable for received data
int rd;
void setup() {
pinMode(Relay_1, OUTPUT);
pinMode(Relay_2, OUTPUT);
digitalWrite(Relay_1, N_CLOSED);
digitalWrite(Relay_2, N_CLOSED);
// Initialize I2C communications as Slave
Wire.begin(SLAVE_ADDR);
// Function to run when data received from master
Wire.onReceive(receiveEvent);
// Setup Serial Monitor
Serial.begin(9600);
Serial.println("Waiting valid route selection");
}
void receiveEvent() {
// read one character from the I2C
rd = Wire.read();
// Print value of incoming data
Serial.println(rd);
}
void loop() {
delay(50);
if (rd != 255)
{
switch(rd)
{
case 1:
delay(500);
digitalWrite(Relay_1, N_OPEN);
delay(500);
digitalWrite(Relay_1, N_CLOSED);
break;
case 2:
delay(500);
digitalWrite(Relay_2, N_OPEN);
delay(500);
digitalWrite(Relay_2, N_CLOSED);
}
}
}
When the Route 1 is selected, the relay cycles continuously between open and closed and only stops when Route 2 is selected, when it's relay cycles continuously. The serial monitor also shows either 1 or 2 repeatedly.
I appreciate this is not a problem with your hardware but apparently a software one. As far as I can tell my hardware is fully serviceable. I'd appreciate any assistance you can give.
Many thanks
PhillipH
/*
4x4 I2C Slave Relay Demo
using Arduino Mega
*/
// Include Arduino Wire library for I2C
#include <Wire.h>
// Define Slave I2C Address
#define SLAVE_ADDR 9
//define Relay States
#define N_CLOSED 1
#define N_OPEN 0
#define Relay_1 53
#define Relay_2 52
// Variable for received data
int rd;
void setup() {
pinMode(Relay_1, OUTPUT);
pinMode(Relay_2, OUTPUT);
digitalWrite(Relay_1, N_CLOSED);
digitalWrite(Relay_2, N_CLOSED);
// Initialize I2C communications as Slave
Wire.begin(SLAVE_ADDR);
// Function to run when data received from master
Wire.onReceive(receiveEvent);
// Setup Serial Monitor
Serial.begin(9600);
Serial.println("Waiting valid route selection");
}
void receiveEvent() {
// read one character from the I2C
rd = Wire.read();
// Print value of incoming data
Serial.println(rd);
}
void loop() {
delay(50);
if (rd != 255)
{
switch(rd)
{
case 1:
delay(500);
digitalWrite(Relay_1, N_OPEN);
delay(500);
digitalWrite(Relay_1, N_CLOSED);
break;
case 2:
delay(500);
digitalWrite(Relay_2, N_OPEN);
delay(500);
digitalWrite(Relay_2, N_CLOSED);
}
}
}
Re: mLink 4x4 Matrix Keypad (HCMODU0188)
Hi Phillip, you're missing the break statement at the bottom of your second case (case 2). Although this isn’t a problem for your sketch as it currently stands it will cause issues when you add more cases.
The thing that will be causing your sketch to not work properly though is your missing the line that sets the 'value' variable back to 255 (value = 255;). It’s in the example I posted so just reference that for where to add it.
viewforum.php?f=49
- thanks.
The thing that will be causing your sketch to not work properly though is your missing the line that sets the 'value' variable back to 255 (value = 255;). It’s in the example I posted so just reference that for where to add it.
If you have any further non-product related issues could you post them in the general discussion section of this forum:I appreciate this is not a problem with your hardware but apparently a software one. As far as I can tell my hardware is fully serviceable. I'd appreciate any assistance you can give.
viewforum.php?f=49
- thanks.
Comments made by this poster do not necessarily reflect the views of Hobby Components Ltd.