NEED HELP, Serial Communication between MKR 1010 Wifi and MKR 1000 not working

Hi,

I have a motion detection system using 2 boards. The first board is a MEK 1010 Wifi and its only job is to display data on LCD and communiacte to second board if it needs to be looking for motion or not.

There are three modes Off (0), On (1), Auto (2), if the system is in auto it checks a daylight sensor before checking PIR.

Currently the MKR 1010 is writing successfully on the Serial Monitor but the second board is not receiving. I feel like I have tried everything. The RX and TX pins are cross connected, both boards share same ground. Both PORTS are corrects and correct boards are selected.
I believe it may have something to do with the code and if its 'Serial' or 'Serial1'. I am used to working with UNO's but need to use the wifi board as later on i will need to display data on website.
I have attached code below any help is welcome.

//Master Board MKR 1010 Wifi
#include <LiquidCrystal.h>  
//adding LCD library to programm

LiquidCrystal lcd(A0,A1,A2,A3,A4,A5);//LCD connections on board

int pushButtonOff = 5;//Push button conections on board
int pushButtonOn = 6;//Push button conections on board
int pushButtonAuto = 7;//Push button conections on board

int LEDOff = 1;//LED conections on board
int LEDOn = 2;//LED conections on board
int LEDAuto = 3;//LED conections on board

int systemMode = 0;//Creating Int Value for System Mode 0 = Off, 1 = On, 2 = Auto

void setup()//Setup Function initilization
{
  Serial.begin(9600);
 // Serial1.begin(9600);//Starts serial communications with a vaulue of 9600
  
  lcd.begin(16,2);//Starts the LCD screen with 16 columns and 2 rows
  
  pinMode(pushButtonOff, INPUT);//Sets push button off as an input device
  pinMode(pushButtonOn, INPUT);//Sets push button on as an input device
  pinMode(pushButtonAuto, INPUT);//Sets push button auto as an input device

  pinMode(LEDOff, OUTPUT);//Sets LED off as an OUTPUT device
  pinMode(LEDOn, OUTPUT);//Sets LED off as an OUTPUT device
  pinMode(LEDAuto, OUTPUT);//Sets LED off as an OUTPUT device

  lcd.clear();//Clears the LCD
  lcd.setCursor(1,0);//sets LCD cursor
  lcd.print("Select Mode:");//Prints text to LCD
  
  
  
}

void loop()
{
  if (digitalRead(pushButtonOff) == HIGH && systemMode != 0)
  {
   
      systemMode = 0;
    
   lcd.clear();//Clears the LCD
   lcd.setCursor(1,0);//sets LCD cursor
   lcd.print("Current Mode:");//Prints text to LCD
   lcd.setCursor(1,1);//sets LCD cursor
   lcd.print(systemMode);//Prints text to LCD

delay(100);
   
   digitalWrite(LEDOff, HIGH);
   digitalWrite(LEDOn, LOW);
   digitalWrite(LEDAuto, LOW);
    
   Serial.print(systemMode);

   delay(1000);
  }
  
  else if(digitalRead(pushButtonOn) == HIGH && systemMode != 1)
  {
   systemMode = 1;
    
   lcd.clear();//Clears the LCD
   lcd.setCursor(1,0);//sets LCD cursor
   lcd.print("Current Mode:");//Prints text to LCD
   lcd.setCursor(1,1);//sets LCD cursor
   lcd.print(systemMode);//Prints text to LCD

delay(100);
   
   digitalWrite(LEDOff, LOW);
   digitalWrite(LEDOn, HIGH);
   digitalWrite(LEDAuto, LOW);
    
   Serial.print(systemMode);

   delay(1000);
  }
  
  else if(digitalRead(pushButtonOn) == HIGH && systemMode != 2)
  {
   systemMode = 2;
    
   lcd.clear();//Clears the LCD
   lcd.setCursor(1,0);//sets LCD cursor
   lcd.print("Current Mode:");//Prints text to LCD
   lcd.setCursor(1,1);//sets LCD cursor
   lcd.print(systemMode);//Prints text to LCD

delay(100);
   
   digitalWrite(LEDOff, LOW);
   digitalWrite(LEDOn, HIGH);
   digitalWrite(LEDAuto, HIGH);
    
   Serial.print(systemMode);

   delay(1000);
  }

}

//Slave Board MKR 1000
// C++ code
//
int PIR1pin = 4;
int PIR2pin = 5;

int echoPin = 6;    // ECHO pin

int LEDCountermeasure1 = 0;//LED conections on board
int LEDCountermeasure2 = 1;//LED conections on board
int LEDCountermeasure3 = 2;//LED conections on board
int LEDCountermeasure4 = 3;//LED conections on board

int LEDSystemActive = 7;

int systemMode;//Creating Int Value for System Mode 0 = Off, 1 = On, 2 = Auto
void setup()
{
   Serial.begin(9600);
   //Serial1.begin(9600);//Starts serial communications with a vaulue of 9600
  
   pinMode(PIR1pin, INPUT);
   pinMode(PIR2pin, INPUT);
  
   pinMode(LEDCountermeasure1, OUTPUT);
   pinMode(LEDCountermeasure2, OUTPUT);
   pinMode(LEDCountermeasure3, OUTPUT);
   pinMode(LEDCountermeasure4, OUTPUT);
   pinMode(LEDSystemActive, OUTPUT);
  
   pinMode(echoPin, INPUT);
}

void loop()
{
  if (Serial.available() > 0)
  {
   char systemModeChar = Serial.read();
   
   systemMode = systemModeChar - '0'; //Converts Char to int

   digitalWrite(LEDSystemActive, HIGH);
    
  }
  
  if (systemMode == 1 ||(systemMode == 2 && analogRead(A0) < 100))
   //If system mode is euql to 1 it will check PIR but if it is equal to 2 it will 
   //check the Photoresistor then check PIR if daylight isnt detected
  {
    
              if(digitalRead(PIR1pin == HIGH || PIR2pin == HIGH))
                 {
               Serial.println("Motion Detected");
      countermesures();
                 }
  }
  
}
  
 void countermesures()
  {
    digitalWrite(LEDCountermeasure1, HIGH);
    digitalWrite(LEDCountermeasure2, HIGH);
    digitalWrite(LEDCountermeasure3, HIGH);
    digitalWrite(LEDCountermeasure4, HIGH);
    pulseIn(echoPin, HIGH);
    delay(3000);
    digitalWrite(LEDCountermeasure1, LOW);
    digitalWrite(LEDCountermeasure2, LOW);
    digitalWrite(LEDCountermeasure3, LOW);
    digitalWrite(LEDCountermeasure4, LOW);
    pulseIn(echoPin, LOW); 
  }

when using Serial1 on a MKRFOX I use pin D14 Tx and D13 Rx, e.g.

// Arduino MKRFOX hardware serial1 port Serial1 on Tx pin 14 Rx pin 13

// on the MKRFOX Serial is used for USB communications and Serial1 is a hardware serial port on Tx pin 14 Rx pin 13

// NOTE: MKRFOX uses 3.3V logic 
// - if commected to UNO 5V logic use a voltage divider 2.2K to ground 1K to UNO Tx

// MKRFOX pin 14 is TX
// MKRFOX pin 13 is Rx
// for loopback test connect pin 13 to pin 14

void setup() {
  Serial.begin(115200);   // initialise serial monitor port
  while (!Serial) {
      ; // wait for serial port to connect. Needed for native USB port only
    }  
  Serial1.begin(115200);  // initialise Serial1
  Serial.println();
  Serial.write("Arduino MKRFOX Serial1 test -  for loopback test connect pin 13 to pin 14\n");
}

void loop() {
  if (Serial1.available())        // read from Serial1 output to Serial
    Serial.write(Serial1.read());
  if (Serial.available()) {       // read from Serial outut to Serial1
    int inByte = Serial.read();
    //Serial.write(inByte);     // local echo if required
    Serial1.write(inByte);
  }
}

looking at the MKR1010 and MKR1000 pinouts D14 and D13 should also work as Serial1

you should therefore be able to cross connect the D13 and D14 pins on the MKR boards and communicate using Serial1

Hi Horace,

I have amended the 2 boards to use serial1 now i no longer see any data on the serial monitor, any thoughts? See below for code

#include <LiquidCrystal.h>  
//adding LCD library to programm

LiquidCrystal lcd(A0,A1,A2,A3,A4,A5);//LCD connections on board

int pushButtonOff = 5;//Push button conections on board
int pushButtonOn = 6;//Push button conections on board
int pushButtonAuto = 7;//Push button conections on board

int LEDOff = 1;//LED conections on board
int LEDOn = 2;//LED conections on board
int LEDAuto = 3;//LED conections on board

int systemMode = 0;//Creating Int Value for System Mode 0 = Off, 1 = On, 2 = Auto

void setup()//Setup Function initilization
{
 Serial.begin(115200);   // initialise serial monitor port
  while (!Serial) {
      ; // wait for serial port to connect. Needed for native USB port only
    }  
  Serial1.begin(115200);  // initialise Serial1
  
  lcd.begin(16,2);//Starts the LCD screen with 16 columns and 2 rows
  
  pinMode(pushButtonOff, INPUT);//Sets push button off as an input device
  pinMode(pushButtonOn, INPUT);//Sets push button on as an input device
  pinMode(pushButtonAuto, INPUT);//Sets push button auto as an input device

  pinMode(LEDOff, OUTPUT);//Sets LED off as an OUTPUT device
  pinMode(LEDOn, OUTPUT);//Sets LED off as an OUTPUT device
  pinMode(LEDAuto, OUTPUT);//Sets LED off as an OUTPUT device

  lcd.clear();//Clears the LCD
  lcd.setCursor(1,0);//sets LCD cursor
  lcd.print("Select Mode:");//Prints text to LCD
  
  
  
}

void loop()
{
  if (digitalRead(pushButtonOff) == HIGH && systemMode != 0)
  {
   
      systemMode = 0;
    
   lcd.clear();//Clears the LCD
   lcd.setCursor(1,0);//sets LCD cursor
   lcd.print("Current Mode:");//Prints text to LCD
   lcd.setCursor(1,1);//sets LCD cursor
   lcd.print(systemMode);//Prints text to LCD

delay(100);
   
   digitalWrite(LEDOff, HIGH);
   digitalWrite(LEDOn, LOW);
   digitalWrite(LEDAuto, LOW);
    
   Serial1.print(systemMode);

   delay(1000);
  }
  
  else if(digitalRead(pushButtonOn) == HIGH && systemMode != 1)
  {
   systemMode = 1;
    
   lcd.clear();//Clears the LCD
   lcd.setCursor(1,0);//sets LCD cursor
   lcd.print("Current Mode:");//Prints text to LCD
   lcd.setCursor(1,1);//sets LCD cursor
   lcd.print(systemMode);//Prints text to LCD

delay(100);
   
   digitalWrite(LEDOff, LOW);
   digitalWrite(LEDOn, HIGH);
   digitalWrite(LEDAuto, LOW);
    
   Serial1.print(systemMode);

   delay(1000);
  }
  
  else if(digitalRead(pushButtonOn) == HIGH && systemMode != 2)
  {
   systemMode = 2;
    
   lcd.clear();//Clears the LCD
   lcd.setCursor(1,0);//sets LCD cursor
   lcd.print("Current Mode:");//Prints text to LCD
   lcd.setCursor(1,1);//sets LCD cursor
   lcd.print(systemMode);//Prints text to LCD

delay(100);
   
   digitalWrite(LEDOff, LOW);
   digitalWrite(LEDOn, HIGH);
   digitalWrite(LEDAuto, HIGH);
    
   Serial1.print(systemMode);

   delay(1000);
  }

}

// C++ code
//
int PIR1pin = 4;
int PIR2pin = 5;

int echoPin = 6;    // ECHO pin

int LEDCountermeasure1 = 0;//LED conections on board
int LEDCountermeasure2 = 1;//LED conections on board
int LEDCountermeasure3 = 2;//LED conections on board
int LEDCountermeasure4 = 3;//LED conections on board

int LEDSystemActive = 7;

int systemMode;//Creating Int Value for System Mode 0 = Off, 1 = On, 2 = Auto
void setup()
{
   Serial.begin(115200);   // initialise serial monitor port
  while (!Serial) {
      ; // wait for serial port to connect. Needed for native USB port only
    }  
  Serial1.begin(115200);  // initialise Serial1
  
   pinMode(PIR1pin, INPUT);
   pinMode(PIR2pin, INPUT);
  
   pinMode(LEDCountermeasure1, OUTPUT);
   pinMode(LEDCountermeasure2, OUTPUT);
   pinMode(LEDCountermeasure3, OUTPUT);
   pinMode(LEDCountermeasure4, OUTPUT);
   pinMode(LEDSystemActive, OUTPUT);
  
   pinMode(echoPin, INPUT);
}

void loop()
{
  if (Serial1.available() > 0)
  {
   char systemModeChar = Serial1.read();
   
   systemMode = systemModeChar - '0'; //Converts Char to int

   digitalWrite(LEDSystemActive, HIGH);
    
  }
  
  if (systemMode == 1 ||(systemMode == 2 && analogRead(A0) < 100))
   //If system mode is euql to 1 it will check PIR but if it is equal to 2 it will 
   //check the Photoresistor then check PIR if daylight isnt detected
  {
    
              if(digitalRead(PIR1pin == HIGH || PIR2pin == HIGH))
                 {
               Serial1.println("Motion Detected");
      countermesures();
                 }
  }
  
}
  
 void countermesures()
  {
    digitalWrite(LEDCountermeasure1, HIGH);
    digitalWrite(LEDCountermeasure2, HIGH);
    digitalWrite(LEDCountermeasure3, HIGH);
    digitalWrite(LEDCountermeasure4, HIGH);
    pulseIn(echoPin, HIGH);
    delay(3000);
    digitalWrite(LEDCountermeasure1, LOW);
    digitalWrite(LEDCountermeasure2, LOW);
    digitalWrite(LEDCountermeasure3, LOW);
    digitalWrite(LEDCountermeasure4, LOW);
    pulseIn(echoPin, LOW); 
  }

are you only writing information to Serial1?
in addition write to Serial if you require a local copy

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.