user3194881
user3194881

Reputation: 55

Arduino Serial1

I'm using an Arduino Micro. When I use "Serial.write", etc. with the Arduino's IDE serial monitor, everything is working fine.

However, when I try to read or send data via "Serial1", I get nothing. "Serial1" is supposed to use 0 and 1, RX and TX, respectively.

Do I need to connect these pins through a USB converter or are they connected on the boards USB converter?

Here is the code:

Void setup(){ Serial1.begin(4800); }
Void loop(){ Serial1.prrint('X'); }

Upvotes: 2

Views: 38181

Answers (9)

Mohammad Jbber
Mohammad Jbber

Reputation: 84

You have to define Serial1 by using SoftwareSerial class from SoftwareSerial library, google and download the library:

The code should be something like this:

// Example
SoftwareSerial Serial1(9, 10); // RX and TX, respectively

Void setup() {
    Serial1.begin(4800); // Here is your New serial
    Serial.begin(9600); // This is where Arduino is connected to your PC
}

Void loop() {
    // Code goes Here
}

Upvotes: -1

Muhammed Almaz
Muhammed Almaz

Reputation: 55

When you open the Arduino IDE, write this code block:

Void setup()
{
    Serial.begin(9600);
}

void loop()
{
    if(Serial.available())
    {
        char get = Serial.read();
        Serial.Write(get);
    }
}

Select the Arduino 9600 port and write something. If you get your written text, your Arduino is ready for serial communication.

Upvotes: -1

jyongc
jyongc

Reputation: 11

You said it right. Serial1 is the RX and TX pin, while Serial is a virtual interface between the computer and Arduino. I have used the TX and RX pins for a wireless module, and if you need to use Serial1, it would have to occupy pins 0 and 1, and switch from DLINE to UART on your board.

Upvotes: 1

Miguel Muñiz
Miguel Muñiz

Reputation: 61

"Serial1" in Arduino Micro is physically connected to the TX and RX pins (TTL), and "Serial" is just a "virtual port" which you can read using Arduino IDE's Serial Monitor. That’s why Arduino Micro is a little different from another, such as Arduino Nano or Arduino Pro Mini.

If you use Serial and Serial1, you can approach this advantage, upload code using USB and make a connection through Bluetooth (using HC06 connected to physical pins) without disconnecting the USB cable and powered both devices (Arduino Micro and Bluetooth).

If you can't upload code to your Arduino Micro sometimes, press the Arduino Micro's reset button, release it, and press the upload button in Arduino IDE's. "virtual port" sometimes needs to restart and connect using USB.

This is from Arduino's documentation website:

...Serial: 0 (RX) and 1 (TX). Used to receive (RX) and transmit (TX) TTL serial data using the ATmega32U4 hardware serial capability. Note that on the Micro, the Serial class refers to USB (CDC) communication; for TTL serial on pins 0 and 1, use the Serial1 class.

Upvotes: 4

user3647272
user3647272

Reputation: 76

Use:

Void setup()
{
    Serial.begin(4800);  // 9600....
}

void loop()
{
    if(Serial.available())
    {
        int a = Serial.read();
        Serial.Writeln(a);
    }
    else
    {
        Serial.Writeln("Error");
    }
}

Open the serial monitor with the icon placed in right corner of Arduino IDE. It will be available if you connect the Arduino with PC.

Upvotes: -1

Eugene
Eugene

Reputation: 335

The only serial port connected to the USB that the serial monitor can read from is Serial.

Serial1, Serial2, and Serial3 are all logic level serial and will not show up on the Arduino serial monitor.

If you want to see the output from these on your computer, it will require extra hardware.

Upvotes: 8

Ercan Ersoy
Ercan Ersoy

Reputation: 27

Serial1 is the wrong class for pin 0 and pin 1. You should use Serial class.

Do I need to connect these pins through a USB converter or are they connected on the boards USB converter?

It makes no difference for Serial class.

Upvotes: -1

techset
techset

Reputation: 7

Make sure you go to tool/board: and select Arduino Mega (or other board with multiply serial ports) or it won't work, because the Uno only has one Serial communication port (aka The TX and RX pins on pins on 1 and 0)! Write 1,2 or 3 depending on what TX and RX pins you are using on the Board. The mega has a whole set of extra pins for Serial 1,2 and 3, for example:

Arduino Uno (etc):

Serial.begin(9600)
Serial.write("testing")

Arduino Mega:

Serial1.begin(9600) // <{or what even baud rate you should use}
Serial1.write("testing")

or

Serial2.begin(9600)
Serial2.write("testing")

or

Serial3.begin(9600)
Serial3.write("testing")

Upvotes: 0

jithinmdas
jithinmdas

Reputation: 61

Serial is the only serial port connected to USB. So serial monitor can access only that port. If you need Serial1 or Serial2 to be accessed by serial monitor, then you should use 'USB to TTL Serial Cable' and connect this to RX and TX pins of the arduino's Serial1 port. Please visit link for USB to TTL Serial Cable, enter link description here

Upvotes: 6

Related Questions