Go Down

Topic: DUE Serial Communication problem (Read 804 times) previous topic - next topic

646464

Hey,
I am working with Due board.
I am doing Serial communication with due but when i am compiling program, error is SoftwareSerial library not found

Palliser

Hello 646464,

With due you don't need the SoftwareSerial library given that Due has four available serial ports (0 to 3). SoftwareSerial was created to cover the lacking of serial ports in boards like Arduino UNO (with only one serial port). If for example you are using SoftwareSerial(2,3), connect your serial device for example in Due serial port 2 (TX2,RX2) and use Serial2.xxx functions. Regards,

p

wassmann69

Hello,
I have the problem with the example (https://github.com/adafruit/Adafruit-Thermal-Printer-Library). I use the Arduino IDE 1.5.8 and 1.6. I keep getting the error that is not the 'SoftwareSerial.h' there. Actually, this was supposed to be there since 1.0 ...

Can someone help me?

Thx

Palliser

Attached a test example that works with Arduino Due (no need of SoftwareSerial library).

Green wire (Printer TX) connected to Arduino Due RX1
Yellow wire (Printer RX) connected to Arduino Due TX1

p

Sahana

Hi,

  I have problem with serial communication in Arduino DUE.
Am using Serial3 for my bluetooth communication.

 Here is my code
byte serialData[10];
String readString;
void setup()
{
 
  Serial3.begin(9600);  //using serial port 3, Tx3, Rx3, pins 14 and 15
 // Serial.begin(9600);
 
}

void loop()
{
  while (Serial3.available())
  {
   delay(10);  //small delay to allow input buffer to fill

   char c = Serial3.read();  //gets one byte from serial buffer

   readString += c;
 }

 if (readString.length() >0)
 {
   Serial.println(readString); //prints string to serial port

    readString=""; //clears variable
 }
   
   
}


can any one say wt s wrong in it . am not getting any error and am not able to transmit or receive the data.

But if I change Serial3 to Serial am able to transmit and receive data.


please help me

SurferTim

How are you determining the Serial3 interface is not receiving data? If you are using this, it is not Serial3 that is failing. It is your code. You are not initializing Serial, but you are using it here.
Code: [Select]
if (readString.length() >0)
 {

// Serial is not initialized in your code, but here you are using it. ??
   Serial.println(readString); //prints string to serial port

    readString=""; //clears variable
 }

Please put your code in code tags so it is easier to read.

danieloba

#6
Dec 15, 2015, 03:44 pm Last Edit: Dec 15, 2015, 03:54 pm by danieloba
Guys,

I'm using the Arduino Due board to communicate with a HC-05, I can use only the TX2/RX2 and TX3/RX3. I tried to use the TX0/RX0 and TX1/RX1 without any success and when I connect on these pins the led start HIGH different when I connect on TX2/RX2 or TX3/RX3. Could someone tell me if is there something wrong?

void setup()
{
Serial.begin(38400); // Default Baud rate of HC-05
pinMode(8, OUTPUT); //Pin Led

}

void loop()
{
char c;
if (Serial.available())
{
 c = Serial.read();

 if (c == 'l' || c == 'L')
 {
    digitalWrite (8, HIGH);
 }

 if (c == 'd' || c == 'D')
 {
    digitalWrite (8, LOW);
 }

}

}

Matze2211

#7
Dec 15, 2015, 08:50 pm Last Edit: Dec 15, 2015, 09:14 pm by Matze2211
Hello,
I need really 5 Uarts on my Due. Is there an option to get one more Uart? I want to collect data from 4 devices and I have got a Nextion Display.
Maybe there is another option to solve my problem?
The 4 devices only sends every 200ms data to the Arduino, they don't receive data.

Regards,
Matthias

Collin80

There is a fifth serial uart on the Due. It is currently unused for some reason. If you look at the unofficial pinout you can find on this forum you'll see that one of the serial uarts is unused (the Due uses 0, 1, 3 and skips 2). So, you could add in support for that missing serial uart.

Matze2211

That sounds great Collin.
How can I add this uart?

MartinL

The additional USART2 is available on analog pin A11 (TX4) and digital pin D52 (RX4).

To use this additional USART you must first create it in your own Arduino sketch, (before setup{}):

Code: [Select]
// Use the Arduino core to set-up the unused USART2 on Serial4
RingBuffer rx_buffer5;
RingBuffer tx_buffer5;
USARTClass Serial4(USART2, USART2_IRQn, ID_USART2, &rx_buffer5, &tx_buffer5);
//void serialEvent4() __attribute__((weak));
//void serialEvent4() { }

void USART2_Handler(void)   // Interrupt handler for UART2
{
  Serial4.IrqHandler();     // In turn calls on the Serial2 interrupt handler
}

You can then use Serial4 in your sketch just like the other serial ports, e.g. Serial4.begin(115200), with the exception of serial events.

I've commented out the serial events, as the function used to call them is held in the Due's "variant.cpp" file. In fact the code used by Arduino to create the other USARTs is also contained there.

Matze2211

Hi Martin,
thank you very much. This will solve all of my problems...at the moment ;)
I copied the code to a empty sketch, added Serial.begin and Serial4.begin and wanted to send Testdata, but it did not work. Do you know why? Is there something else to add or change?

Here is my code:

Code: [Select]
// Use the Arduino core to set-up the unused USART2 on Serial4
RingBuffer rx_buffer5;
RingBuffer tx_buffer5;
USARTClass Serial4(USART2, USART2_IRQn, ID_USART2, &rx_buffer5, &tx_buffer5);
//void serialEvent4() __attribute__((weak));
//void serialEvent4() { }

void USART2_Handler(void)   // Interrupt handler for UART2
{
  Serial4.IrqHandler();     // In turn calls on the Serial2 interrupt handler
}


void setup() {
  // put your setup code here, to run once:
  Serial.begin(9600);
  Serial4.begin(9600);
  Serial.println("Test");
  Serial4.println("Test");
}

void loop() {
  // put your main code here, to run repeatedly:

}

MartinL

Hi Matze2211

Oops, I need to switch the A11 and D52 pins over from GPIO pins to USART. I'm working on a solution. I'll let you know ASAP.

MartinL

#13
Dec 16, 2015, 12:48 pm Last Edit: Dec 16, 2015, 05:27 pm by MartinL
Hi Matze2211,

I missed a line. You just need to include the following line of code, just before Serial4.begin():

Code: [Select]
PIO_Configure(PIOB, PIO_PERIPH_A, PIO_PB20A_TXD2 | PIO_PB21A_RXD2, PIO_DEFAULT);
This switches the pins A11 (TX4) and D52 (RX4) from GPIO to a USART IO.

Here's a test program that echos back characters from the console:

Code: [Select]
// Use the Arduino core to set-up the unused USART2 on Serial4
RingBuffer rx_buffer5;
RingBuffer tx_buffer5;
USARTClass Serial4(USART2, USART2_IRQn, ID_USART2, &rx_buffer5, &tx_buffer5);
//void serialEvent4() __attribute__((weak));
//void serialEvent4() { }

void USART2_Handler(void)   // Interrupt handler for UART2
{
  Serial4.IrqHandler();     // In turn calls on the Serial2 interrupt handler
}

void setup() {
  // put your setup code here, to run once:
  PIO_Configure(PIOB, PIO_PERIPH_A, PIO_PB20A_TXD2 | PIO_PB21A_RXD2, PIO_DEFAULT);
  Serial4.begin(115200);
}

void loop() {
  // put your main code here, to run repeatedly:
  if (Serial4.available())        // Check if incoming data is available
  {
    byte byteRead = Serial4.read();    // Read the most recent byte 
    Serial4.write(byteRead);      // Echo the byte back out on the serial port
  }
}

Go Up
 


Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

Arduino
via Egeo 16
Torino, 10131
Italy