Serial Port Testing

Hello,

I want to give commands to a stepper motor to tell it to turn a certain amount of times. I am doing this by having a user input a number (In cm) on a different program that will then send the data to the serial port on the UNO. I have never done this before so I wanted to ask a few questions in regards to testing my code:

  1. If I wanted to send data to the serial port, is there a way I can do that with the Arduino programmer interface or some downloadable library without having to also fully program the UI software that would send the commands?

  2. I know I need to use the function: Serial.read() however, does this mean it outputs the value in the Arduino programmer interface or do I need to set something else up for that?

  3. Any suggestions to resources where I could figure out how to make the proper cable to connect to these ports with my computer to test the inputs and outputs?

tkeaton:

  1. If I wanted to send data to the serial port, is there a way I can do that with the Arduino programmer interface or some downloadable library without having to also fully program the UI software that would send the commands?

Sure, just use Tools > Serial Monitor. That will open the serial port you have selected from the Arduino IDE's Tools > Port menu. Serial Monitor has a text field where you can input text and a "Send" button you click to send the text to the serial port.

tkeaton:
2) I know I need to use the function: Serial.read() however, does this mean it outputs the value in the Arduino programmer interface or do I need to set something else up for that?

Serial.read() reads one byte of incoming data on the Serial interface of your Arduino board. Please take some time to read the documentation:

If you want to output data to the Serial interface from your Arduino board, you will want to use Serial.print(), Serial.println(), or Serial.write(). Those are all documented here:

tkeaton:
Hello,
3) Any suggestions to resources where I could figure out how to make the proper cable to connect to these ports with my computer to test the inputs and outputs?

What do you mean by "ports"? Serial is already connected to your computer via the Arduino board's USB cable so there is no need for an additional cable. You can create an additional software serial port on your Uno if you need an extra, and to connect that port to your computer you do need a special adapter or cable (commonly called an "FTDI", though that is not really an accurate name). However, I don't see why you would need to do that. Just use Serial and everything is simple.

Thanks for the answers Pert! I did read the documentation on all the serial functions and I reread my questions and realized that I mistakenly put "Serial.read()" instead of "Serial.println" or "Serial.print()". I meant to ask if either of those functions output the values it reads from the serial into the Arduino interface.

Along the lines of question 3, the "ports" I was talking about were actually the TX and RX pins. I wanted to use those because in the end I wanted to bunch up those and the analog input pins into a single cable and then to a serial connector so that a user can just plug into it. I am going to program another piece of software that controls a daqcard (Made by NI) that connects to that serial connector and gives commands. This is why I want to use the TX and RX pins and not USB and why I wanted to see if there was a way to test that the board was receiving correct commands for the RX pin without having to pre-program the daqcard and just use the Arduino interface.

Go to the Arduino Examples. Either via the Arduino folder on your computer or File->Examples in the Arduino IDE. Look for 04.Communication then ReadASCIIString.

It's not great code that's suitable for a large project but if you are pretty sure that your project is a small one, this will get you up and running quickly.

tkeaton:
I am going to program another piece of software that controls a daqcard (Made by NI) that connects to that serial connector and gives commands. This is why I want to use the TX and RX pins and not USB and why I wanted to see if there was a way to test that the board was receiving correct commands for the RX pin without having to pre-program the daqcard and just use the Arduino interface.

We'd need more information on the daqcard to give further advice about this. What you need to be aware of is that the Arduino uses 5 V TTL logic levels. If your daqcard uses an RS-232 serial interface then that uses voltage levels that would destroy your Arduino if connected directly. So you would need to use an adapter like the MAX232 to safely convert between the voltage levels.

@MorganS thanks for the answer! I checked it out and it helped me to write a program that compiles correctly!

@pert I actually just checked that and found that the Daqcard I am using outputs 4.35 V on its digital I/O channels so it will work. However, I realized that it does not have any serial connections so my original idea to include serial in the cable will not work. I am just going to have to go with using the USB for serial data which is fine.

I am having software issues moment now that I am testing the program (Since the serial is not outputting anything into the Serial Monitor when it is supposed to) so I am going to start a new post on that. Thanks for all the help!