Is it convenient to build and upload your sketch for every configuration change?
Are switches the easiest UI to debug your project?
Is it convenient to build and upload a new version of your sketch every time you want to change the configuration?
How many switches will you have to wire up to control your project?
Interested in an easier way?
MegunoLink lets you quickly build simple interfaces to control your project.
- Drag and drop controls onto the interface.
- Set the command to send.
MegunoLink can send commands when buttons are clicked or values are changed. You can send commands in any format you like. And command messages can include values from other controls.
Start with our Arduino Library
In your Arduino sketch you’ll need something to receive serial messages and decode commands. If you have a command handler already, that’s fine. MegunoLink will work with your prototocol.
If you don’t already have a command handler, our MegunoLink library for Arduino includes an extensively tested, easy to use one all ready to go. You don’t have to build your own.
MegunoLink’s command handler for Arduino lets you set a function that gets called each time a command is received. Your function could, for example:
- get parameters sent with the command,
- updating a variable,
- turn on a light,
- move a motor.
The command handler looks after receiving characters from the serial port and decoding commands for you. Using it is very simple:
- Include the library and define a command handler at the top of your sketch. The library is included free with MegunoLink.
- In your
setup()
function, add each command and the function to call when the command is received. - Implement the command function. It must take 1
CommandParameters &
argument, but it can do anything you like. - Call the command handler’s
Process();
function in yourloop()
to process serial characters.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
#include "CommandHandler.h" // Create a command handler variable CommandHandler<> MyCommands; void setup() { Serial.begin(9600); // Setup commands. Up to 10 by default. // For each, set the command name and the function to call. MyCommands.AddCommand(F("SetTemperature"), Cmd_SetTemperature); } // Define the functions which handle commands void Cmd_SetTemperature(CommandParameter ¶meters) { int NewTemperature = parameters.NextParameterAsInteger(); Serial.print(F("I got a new temperature: ")); Serial.println(NewTemperature); } void loop() { // Call the process function to process serial characters and // decode commands and call the handler functions. MyCommands.Process(); } |
That’s all you need to start using serial commands instead of rebuilding and uploading a new program every time you want to change something.
Sending Serial Commands to your Arduino
MegunoLink gives you an easy way to quickly build a user interface so you can use normal controls to enter parameter values and send commands.
Just fire up the interface designer and drop controls in the window. Perhaps a label, a number box and a button. Set the button’s OnClickSend
property to the command you want to send. Commands can include parameters and functions inside <code>[…]</code> that take values from other controls: !SetTemperature [Temperature.Value]\r\n
, for example. Apply the design and your done.
When you click the button, MegunoLink will substitute [Temperature.Value]
with the value from the temperature control and sent it to your Arduino program.
Building interfaces with MegunoLink makes it easier to use your latest creations. And when you’re ready to share with others, we have Builder to create stand-alone installers which you can distribute to your colleagues and end-users.