Toggle Menu

Arduino interactive commands SerialCommander is born


Months ago, some friends were having troubles with the water tanks on their farm, so I started to play with a couple of Arduino boards.

The goal? keep the water tanks filled by running a remote pump.

As usual, as a proof of concept, this started as a bunch of code and wires entangled together with hot glue.

Since this has been working stable for some time, now I have started the development of a real version, with the hardware in a more permanent setup and cleaner code.

Receiver and transmitter are using Ethernet shields and they are connected by a local network that connect multiple buildings across large distances over the farm.

Having the boards connected to a network allowed the addition of some extra goodies, like having Pushover notifications when something is wrong and real time monitoring of the tank status.

Long life to the serial port

The first thing I wanted to add to this project is an “easy enough” way to configure the devices in case they need to be replaced or the network configuration is changed.

Yes, I know.. would be nice to have a web page since this is using Ethernet, but the extra cost on memory and code does not make sense for something that would be done one or twice over the lifespan of each board.

Anyone replacing the boards should know how to use a serial port, right? :)

Interactive command line for Arduino (or similar)

The solution is quite simple, accept characters until a new line is detected or a timeout is reached.

	...
	if (MyCommander.read() &&
		MyCommander.is("surrender") &&
		MyCommander.confirm(F("Are you sure?")) {
		// do something
	}
	...

PlatformIO

platformio lib install 288

http://platformio.org/lib/show/288/SerialCommander

Source code

Get the source code from GitHub

Example

Source Code

SerialCommander