Connect with us

Arduino UNO Serial Question

Discussion in 'Microcontrollers, Programming and IoT' started by Old Steve, Sep 9, 2015.

Scroll to continue with content
  1. Old Steve

    Old Steve

    734
    169
    Jul 23, 2015
    I'm unsure of a point regarding serial comms on an Arduino UNO. My Arduino hasn't arrived yet, so I can't do any experimenting to find out the hard way.

    I need to receive serial raw data from one remote device, process it, then send the processed data on to another remote device, again using serial comms.

    There's a built-in UART connected to pins 0 and 1, which I can use for one serial stream.
    For the second, is it possible to use the Arduino Software Serial Library, utilising whichever pins I want, or is that library only for the Mega?

    Or am I out of luck? If it is impossible with a UNO, I can use a PIC with PICBasic Pro and set up software serial on any (or all) pins, but I'd prefer to use the Arduino for this.

    Thanks in advance.

    Edit: Like so:-
    Code:
    #include <SoftwareSerial.h>
    
    SoftwareSerial mySerial(10, 11); // RX, TX
    
    void setup()
    {
      // put your setup code here, to run once:
      Serial.begin(9600);
      mySerial.begin(19200);
    }
     
    Last edited: Sep 9, 2015
    sandeep1729 likes this.
  2. Old Steve

    Old Steve

    734
    169
    Jul 23, 2015
    Just thinking about it, I guess there's an alternative - use the inbuilt RX pin to receive from one device and the TX pin to send the processed data to the other. (I won't be doing any software handshaking, so it wouldn't hurt to split the pins.)

    I'd still like an answer to my original question though, if anyone knows about the software serial library with UNO.
     
    sandeep1729 likes this.
  3. Harald Kapp

    Harald Kapp Moderator Moderator

    10,053
    2,144
    Nov 17, 2011
    It states here:
    but I like your second idea much more.
     
  4. Old Steve

    Old Steve

    734
    169
    Jul 23, 2015
    Yes, I read that Harald, but it didn't say 'which' Arduino. For now, until my board arrives, I'm assuming it means all of them, and writing some code accordingly.
    (It compiles OK with the board set to "UNO" under "Tools".)

    Which idea, using a PIC or splitting the pins?
     
  5. Harald Kapp

    Harald Kapp Moderator Moderator

    10,053
    2,144
    Nov 17, 2011
    Splitting the pins. Aöthough you then are stuck with the same baudrate for both Tx and Rx whereas using two separate UARTS you could have different baudrates - if that matters at all.
     
    Old Steve likes this.
  6. Old Steve

    Old Steve

    734
    169
    Jul 23, 2015
    Good point Harald.
    There aren't two UARTS though. Just the one on a UNO. The second serial stream would use software serial.

    Just thinking, in my application I could split the pins and have two different baud rates. The raw data will only arrive once per second. More than enough time in between to call Serial.end(), then Serial.begin() again with a different baud rate.
    (Luckily, for this application, I know exactly when to expect new data to arrive. :cool: )
     
  7. Harald Kapp

    Harald Kapp Moderator Moderator

    10,053
    2,144
    Nov 17, 2011
    I'm aware of this, I was referring to the UART function regardless of the implementation in HW or SW.

    In that case you could use the hardware UART for the fast transmission to relief the CPU from servicing a fast SW-UART and use the SW-UART for the slow connection which would not impose that much CPU load due to the slow speed.
     
    Old Steve likes this.
  8. Old Steve

    Old Steve

    734
    169
    Jul 23, 2015
    I thought you might have been, but just thought I'd make it clear.

    Yep, my thoughts exactly. I'll use 9600 baud in, 19200 baud out.
    I could even set a timer, to produce aninterrupt on overflow, to ensure I didn't miss any input data packets.

    Edit: I'll dedicate the Arduino to this. It's only purpose will be to receive data packets, quickly process them, pass them on, then back to the receiving/processing. Even the interrupt will be overkill and not needed, just thinking about it. I wish that Arduino would hurry up and get here. There's only so much I can do in the simulator.
     
    Last edited: Sep 10, 2015
Ask a Question
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.
Electronics Point Logo
Continue to site
Quote of the day

-