Fork me on GitHub

Project Notes

#746 Serial Control

Using serial commands to control and query information from an Arduino.

Build

Notes

This is a simple Arduino sketch that responds to serial control. As well as providing a simple demonstration of Arduino serial coding, I made this sketch so that I could use the Uno as an intelligent responder for testing client-side serial code.

Form more information on serial communications, see Arduino Cookbook: 4. Serial Communications

Code

The SerialControl.ino sketch listens for commands on the serial port and then responds accordingly.

Currently, it supports the following commands:

  • d : show system information
  • i : generate a random 8-bit integer
  • s<length> : generate a random string of specified length
  • t : toggle the LED on pin 13
  • ? : show this message

A blank line will follow the output of all commands. This indicator may be used for client-side flow control if required.

Using the Arduino IDE

The script can be compiled and uploaded from the IDE, and used with the built-in serial monitor set for 115200 baud:

ide-example

Using Screen

I’m using macOS, so (as with Linux) the most handy console utility is screen.

The Arduino is showing up as a character and TTY device with ID 2430:

$ ls -1 /dev/*serial*
/dev/cu.usbserial-2430
/dev/cu.wchusbserial2430
/dev/tty.usbserial-2430
/dev/tty.wchusbserial2430

For simple character interaction, any of these devices with work, but cu devices are preferred. For example:

screen /dev/cu.usbserial-2430 115200

screen-example

Credits and References

About LEAP#746 ArduinoSerial

This page is a web-friendly rendering of my project notes shared in the LEAP GitHub repository.

Project Source on GitHub Return to the LEAP Catalog
About LEAP

LEAP is my personal collection of electronics projects - usually involving an Arduino or other microprocessor in one way or another. Some are full-blown projects, while many are trivial breadboard experiments, intended to learn and explore something interesting.

Projects are often inspired by things found wild on the net, or ideas from the many great electronics podcasts and YouTube channels. Feel free to borrow liberally, and if you spot any issues do let me know or send a pull-request.

NOTE: For a while I included various scale modelling projects here too, but I've now split them off into a new repository: check out LittleModelArt if you are looking for these projects.

Project Gallery view the projects as an image gallery Notebook reference materials and other notes Follow the Blog follow projects and notes as they are published in your favourite feed reader