I want to write some data (GPS) to a digital port on Arduino. As far as I understand sending data via a pin as if it were USB is possible. But I don't know what function to use. digital.Write doesn't expect any data or strings. How do I write serial data on to a digital pin

  • 2
    Digital.Write takes exactly two arguments, the pin number and 'high' or 'low' - so you look at your bit stream and write the port accordingly, or speed things up by using a built in protocol like I2C, SPI etc... arduino.cc/en/Reference/DigitalWrite
    – Tim Mottram
    Jul 20 '17 at 13:42
  • USB is a complex protocol which is not supported by most of the simpler processors used in most of the simpler Arduino boards. So you need to specify your exact hardware or answers to your questions will have to be generic and vague. The USB port on an Arduino Uno is actually a separate chip from that which you run your Arduino sketches on. What your Arduino Uno program can do is send out serial data to this separate chip. Not USB protocol. Also, as far as I know, the only USB protocol supported on an Arduino Uno is Serial Data over USB. Hopefully that is what the GPS uses.
    – st2000
    Jul 20 '17 at 14:07
  • It would help if you edited your title so that people know that you are asking about connecting a Arduno to a USB Device.
    – st2000
    Jul 20 '17 at 14:23
  • You need to edit this to be clear what exact "serial" signalling scheme you need to use, and if you are able to choose the pin on which the chip can do that best, or if it has to be a particular pre-chosen and specified in the question pin even if that requirement makes the task far more difficult or impossible. Jul 20 '17 at 14:40
  • I am talking about an arduino uno the data from which I am connecting to some other device to read. Right now just to an oscilloscope. I am not sure about the pin. I'm talking about a digital pin on an arduino. The GPS data can be transmitted using the serial protocol as far as I understand, I'm just not sure how exactly to do that in terms of software.
    – Anthropomorphous Dodecahedron
    Jul 20 '17 at 15:05

Using the arduino library "software Serial" (https://www.arduino.cc/en/Reference/SoftwareSerial) you can use any pin to write/read serial data.


The Aruduino Uno uses an ATmega328P which only has 1 hardware UART to help the software communicate serially with the outside world. If you are already using this hardware resource (for example through the normal Arduino serial library), it is unavailable to talk to a 2nd external device. In such a case you can emulate a UART in software using this Software Serial Library in exchange for some processor time (that is, using a software emulated serial port will slow down your program's execution).

  • This is likely not what the asker is trying to do - by appearances the data is GPS-like (probably NMEA or something) but they probably don't want to output it to a GPS. Unless they mean some kind of moving map display for a GPS, but that probably won't want USB input, rather some suitable marine grade serial interface. Jul 20 '17 at 14:38
  • 1
    Yeah, I'm not trying to output it to a GPS. I am collecting some set of data, and trying to send it to some other device using a digital pin on my arduino. Most likely using serial connection.
    – Anthropomorphous Dodecahedron
    Jul 20 '17 at 15:02
  • Again, it pays to tell which Arduino / processor you are using. If the processor only has 1 UART you will need to use a software implemented library to talk to a 2nd device over a serial port. If the processor has 2 UARTs, then the serial communications will be more robust. But you will have to figure out if the Arduino serial port library you are using will support the 2nd UART of the processor you are using.
    – st2000
    Jul 20 '17 at 16:45
  • Oh I see, thanks. The arduino I'm using is uno with ATMEGA32BP-PU. However, if I'm using a digital pin to communicate do I just configure it as a serial port and then use the serial library?
    – Anthropomorphous Dodecahedron
    Jul 20 '17 at 17:20
  • Please re-word (edit) your Title & Question. Make it clear you are already using the serial port built into the Arduino Uno. And you wish to create a 2nd serial port. I will in turn make my answer fit the re-worded (edited) question.
    – st2000
    Jul 23 '17 at 15:42

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.