Serial Monitor Communication

Welcome back to the Digilent Blog!

 

MPIDE comes with a nice serial monitor where you are able to print out values that your system board has measured onto your computer screen. But if you are able to print things onto your computer screen, wouldn’t it make sense if the chipKIT board also accepted and processed values that we typed into the serial monitor? It would make a lot of sense, which is probably why we can do just that. Let’s find out how.

 

For those of you who might not know, the MPIDE’s serial monitor is a type of interface that monitors (no surprise there) and displays what is happening in the USB-UART terminal that is connecting your chipKIT to the computer. Whenever you call the “Serial.print” function, all of the information that is sent to this UART interface is displayed on your computer screen.

Typecasting to turn a character 7 into a number 7 and add it to an existing number
This screenshot with the serial monitor on the right-hand side shows what we have printed to UART terminal.

What this picture does not show is that there is a text box and a “Send” button where you are able to type text into the Serial Monitor and send it off to the chipKIT board. Naturally, the chipKIT board will only respond to this information if it has been programmed to do so. Luckily, this is surprisingly easy to do with the Serial.available() and Serial.read() functions. The Serial.available() checks to see if any data is available in UART buffer. If there is, then it will return how many bytes are currently present inside the buffer.

 

Serial.read() will read and remove one byte at a time from the UART buffer. The single removal makes it very convenient to combine this function with a while loop. That way, we can tell the chipKIT board:

While there is data available in the Serial Monitor, read and remove a byte.
While there is data available in the serial monitor, read and remove a byte.

Once all of the characters have been collected, you can compare your set of characters (also known as a string) to a user defined set of options. If the set of characters matches one of the options, you can then have the chipKIT board send a response back over the serial monitor or run a routine such as flashing an LED multiple times.

MPIDE's Serial Monitor opens up a lot of options in your project design.
MPIDE’s serial monitor opens up a lot of options in your project design (click on the picture to enlarge).

Check it out!

Author

  • James Colvin

    A local Digilent employee who is sometimes tricked into making other content besides documentation and supporting customers on the Digilent Forum, but then I get to write a little more informally so that's a plus. A sassy engineer, lover of puns and dad jokes, father and husband. I know both way too much and simultaneously almost nothing about a number of nerdy topics. If you want to hear me rant, ask me what data rate USB C operates at.

Be the 1st to vote.

About James Colvin

A local Digilent employee who is sometimes tricked into making other content besides documentation and supporting customers on the Digilent Forum, but then I get to write a little more informally so that's a plus. A sassy engineer, lover of puns and dad jokes, father and husband. I know both way too much and simultaneously almost nothing about a number of nerdy topics. If you want to hear me rant, ask me what data rate USB C operates at.

View all posts by James Colvin →

Leave a Reply

Your email address will not be published. Required fields are marked *