Serial.Write with MKR wifi 1010

Hello everybody!

Please, I need some help! This code works perfectly with my Arduino Mega 2560, but with my MKR WiFi 1010 it doesnt work. Of course, I changed the pins, this version is the MKR version.
wired on the pin 13, 14 and 2 is a DEBO RS 485 TTL - Shield. Is it a problem with the voltage of the mkr (3.3V)?

#define RXpin 13  //Serial Receive pin
#define TXpin 14  //Serial Transmit pin
#define DEpin 2 // Data Enable Pin
#define BaudRate 19200

int x = 0;

void setup() {

Serial.begin (BaudRate);

}


void loop() {

    Serial.end();
    pinMode(TXpin, OUTPUT);
    digitalWrite(TXpin, LOW);
    delay(10);
    Serial.begin(BaudRate);
    Serial.write(0xff); //start byte
    Serial.write(0xC0); //command
    Serial.write(byte(1)); //adress
    Serial.write(byte(x)); //position
    delay(10);

    x++;
  
   delay(500);

}

pins 13 and 14 are Serial1. Serial is USB.

why would you use Serial for this on Mega too? than you can't debug with Serial Monitor. Mega has 3 other hardware Serial interfaces

hey! thanks for your fast answer!

so, i have to change every Serial to Serial1? then it doesnt work at all. :frowning_face:

ehm, Serial Monitor works with the mega. I have no idea how i could write it in other way. on the mega it was working perfectly, but i would change it to the mkr to synchronize it with an ntp.

behind its an old flip-flap from a train station.

should it work with this code?

#define RXpin 13  //Serial Receive pin
#define TXpin 14  //Serial Transmit pin
#define DEpin 2 // Data Enable Pin
#define BaudRate 19200


int x = 0;

void setup() {

  Serial1.begin (BaudRate);
}



void loop() {

  Serial1.end();
  pinMode(TXpin, OUTPUT);
  digitalWrite(TXpin, LOW);
  delay(10);
  Serial1.begin(BaudRate);
  Serial1.write(0xff); //start byte
  Serial1.write(0xC0); //command
  Serial1.write(byte(1)); //adress
  Serial1.write(byte(x)); //position


  delay(10);

  x++;
  delay(500);

}


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