BLYNK
HOME       📲 GETTING STARTED       📗 DOCS       ❓HELP CENTER       👉 SKETCH BUILDER

Double serial communication on arduino Due

I am trying to receive data from serial 2 and I added void rxdata () with a timer, but the system crashes.

(Unformatted code removed)

This is a Blynk forum and your question seems more like a general programming one.

Regardless, when posting code here it needs to be properly formatted… Please repost your code properly formatted as directed.

I am trying to receive data from serial 2 and I added void rxdata () with a timer, but the system crashes.

void rxdata (){
 
   Serial.println("start rx");  // 4 debug
if (mySerial.available()) {              
    inByte[1] = mySerial.read();
    delayMicroseconds(tim);
    inByte[2] = mySerial.read();
    delayMicroseconds(tim);
    inByte[3] = mySerial.read();
    delayMicroseconds(tim);
    inByte[4] = mySerial.read();
    delayMicroseconds(tim);
    inByte[5] = mySerial.read();
    delayMicroseconds(tim); 
    inByte[6] = mySerial.read();
    delayMicroseconds(tim);
    inByte[7] = mySerial.read();
    delayMicroseconds(tim);
    inByte[8] = mySerial.read();
    delayMicroseconds(tim);
    inByte[9] = mySerial.read();
    delayMicroseconds(tim);
    inByte[10] = mySerial.read();
    delayMicroseconds(tim);
    inByte[11] = mySerial.read();
    delayMicroseconds(tim);
    inByte[12] = mySerial.read();
    delayMicroseconds(tim);
    inByte[13] = mySerial.read();
    
    }
//************* data check + Verifica errori  ***************************
if ((inByte[1] == 0xff)&&(inByte[12] == 0xD) && (inByte[13] == 0xA) ){  
     verifysum = ((inByte[2]<<8) |inByte[3])+((inByte[4]<<8) |inByte[5]) +((inByte[6]<<8) |inByte[7]);
     verifysum =  verifysum <<16 ;
     verifyrx1 = (inByte[8]<<8 |inByte[9]); 
     verifyrx2 =  ( inByte[10]<<8|inByte[11]);
     verifyrx3 = ( verifyrx1<<16 | verifyrx2);
     if ( verifysum ==  verifyrx3){   Serial.println("ok verify");  
         okrx = 1;
         }
     }
 else {( okrx = 0);} 
     
//************* ID check ************************************************
if (( okrx == 1) &&(inByte[2] == myid)&&(inByte[3] == myid)){
    msg1 =inByte[5] ;Serial.println("i'm");}
}   

on seral monitor I only see “st” instead of “start rx”

Despite the limited info and partial snippet of code, I can see a few questionable issues…

But again, what does this have to do with Blynk? Sounds like you should be asking about this over on the Arduino forum.

because if I don’t run it it blink my communication on serial 2 works perfectly

Then you need to systematically break down what your Blynk code is doing that may interfere or be interfered with by your serial code… recalling that Blynk needs constant communication to the server via whatever method you are using.

You cannot share the same Serial port with Blynk and whatever else you are doing.

the serial ports are different obviously serial1 for ESP8266 and serial 2 for a serial communication with a PLC

I see nothing obvious about that in your code… I ONLY see reference to Serial, which is the primary USB port.

I think you need to read up about the serial ports available on your board…

https://www.arduino.cc/en/Guide/ArduinoDue#toc13

:sleeping::sleeping::sleeping:

Still trying to make a silk purse out of the Due?

image

Pete.

1 Like

I think even an ESP8266 would choke on this… perhaps an ESP32 with its multi-serial port options? or even (GASP :scream: ) a Mega 2560 with its total of 4 hardware serial ports.

I thought the need for a second serial port was because one was being used to connect to an ESP-01 as a WiFi modem?

Pete.

@PeteKnight that would make the most logical sense…

I haven’t a clue what this OP is actually doing… just that it probably exceeds the DUE’s available Serial ports for both Blynk connectivity and whatever else is trying to happen. And that seems to be the extent of the Blynk relivency of this topic :stuck_out_tongue_winking_eye:

1 Like

communication on two serials is working only I cannot receive more than 12 bytes.
if I try to receive the 13 bytes it goes to block, maybe for the long communication times, maybe because blinking goes out time

As mentioned, doing so will cause disruption with Blynk’s communications and thus a disconnection with the server.

However, you have not clarified what you are doing, how you are doing it, what “system crashes” actually refers to, etc.

Perhaps look into possible SoftwareSerial options for your non-Blynk serial stuff and leave the ESP link alone.

serial.begin for the serial monitor
serial1 for the ESP
serial 2 for rs232

OK, it seems the DUE should have 4 hardware serial ports… not clear on the precise commands to use them.

https://store.arduino.cc/usa/due

image

Check out here… https://blog.startingelectronics.com/tag/arduino-due/

The Due serial commands/reference syntax should work the same way as on the Mega…

Serial
Serial1  // Not serial1, case matters
Serial2  // Not serial 2, case matters and no spaces
Serial3

You need to study up on the available ports, precise commands to use them, and confirm that nothing is being shared between the Blynk link and whatever other serial stuff you are doing.

None of this is truly relevant for this forum as it is very specific to your board type, and it does not seem like a very common type of Arduino board for Blynk use… particularly with multi-serial application.

And remember any blocking process WILL still affect Blynk’s server connection… so avoid blocking commands like while(), delay(), and locking loops like if() wherein the solution takes too long to complete, etc.