1

I come to you again because I have a problem with the Arduino SoftwareSerial library. With a basic example I fail to see results in the serial monitor.

The basic code example:

#include <SoftwareSerial.h>
SoftwareSerial mySerial(10, 11);
void setup() {
  mySerial.begin(4800);
}
void loop() {
    mySerial.println("HELLO");
    delay(100);
}

I guess it should show the string "HELLO" on the serial port, but nothing appears. I have found that the baud setting is correct. The hardware is simple. Only an Arduino Uno v3 without any connected component.

1

If your Arduino is connected via the built-in USB port then you need to use the hardware serial port (pins 0 and 1). To do that, call Serial.begin(..) and Serial.println(..), instead of mySerial....

SoftwareSerial is used when you want to connect via serial on some other pins. It allows your program to emulate serial input/output in software instead of relying on dedicated hardware. In this case, your program is trying to setup software serial on pins 10 and 11. That won't show up on the serial monitor because it's not connected to those pins.

  • Thanks for your answer. Yes, I am aware that I can use the serial hardware, but the fact is that I need to connect a device to these two pins (10 and 11), because in the serial hardware and I have a connected device is busy. I try to make a mySerial.print to test the serial communication with the "virtual serial" but does not show anything printed on the serial monitor. thank you very much – xavi Nov 19 '14 at 13:20
1

Addition to Peter R. Blommfield

What is your problem?

Connect your device, run this sketch and you are good to go :)

/* TEST */
#include <SoftwareSerial.h>

/* Connect device Rx - 10, Tx - 11 */
SoftwareSerial mySerial(10, 11);


void setup() {
  Serial.begin(9600);   // This will communicate with PC via USB
  mySerial.begin(4800); // This will communicate with device via 10,11 pins with 4800 baud rate
}
void loop() {
    Serial.println("HELLO");   // Sends string to PC to Serial Monitor
    mySerial.println("HELLO"); // Sends string to device
    delay(100);                // Waits here 100ms and then goes on
}
  • Thanks for your answer, With the example you've happened to me, I open the serial monitor and print me "hello" well at 9600 baud, but when I set the serial monitor at 4800 baud, it prints very strange characters, not the word "hello" as I think it is expected. Thanks for your help! – xavi Nov 19 '14 at 13:38
  • In serial monitor you have to change the baud rate manually. At the bottom right corner there is drop down menu. Choose 4800 – Martynas Nov 19 '14 at 13:42
  • Also let me ask, what is the device you connect? – Martynas Nov 19 '14 at 13:45
  • yeah, I've changed but I keep getting weird characters... – xavi Nov 19 '14 at 13:45
  • ...its a module gprs by cooking-hacks.com/gprs-quadband-module-sim900-for-arduino .But I put the RX/TX pins on a 10/11 pins oin arduino board – xavi Nov 19 '14 at 13:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.