Tests are identified either by name or an integer (test id) when you send results from your Arduino program. Only results for pre-configured tests will be display; other results will be ignored. Your Arduino program can send a pass or fail result for each test. It can also include a value, which will be displayed next to the test result. For example, if you’re testing the power supply voltage is within the allowed range it can be helpful to include the actual voltage as well as the pass/fail indication.
The Test Monitor is ready to display results as soon as the serial port is connected. So if you send the test results from the end of your loop, and your Arduino resets whenever a connection is made, the results will display automatically. Sometimes a small delay (1 – 2 seconds) is needed before the results are sent, to allow time for the connection to be made.
The Test Monitor panel can send a command to the Arduino when you push the Run button. This command can start the test on the Arduino and send back the results.
Creating a Test Monitor Panel
To create a test results panel, click the Add Programmer drop-down menu on the Program Devices visualizer toolbar. Select Test Monitor from the list.
Use the Name field to help you remember what the panel is for. After you’ve configured the tests (see below), you can press the:
- Reset button to clear the previous test results ready for a new test
- Run to clear the previous test result and send the begin test command
- Configure to configure the tests
The lock button disables the Run button. This helps effectively disables the test result for programming sequences.
Configuring a Test Monitor Panel
You have to configure the Test Monitor panel before it will show any test results. Start by clicking the Configure button to show this configuration dialog:
Select the source that the panel will monitor for test results and the maximum amount of time it will wait for all tests to complete.
If your Arduino program requires a special command to start tests and/or report test results, check the Send message to start test and enter the command in the box provided.
Add one or more tests using the buttons provided. Results will only be reported for tests that are in the list. You can report test results using either the name or id assigned when you create the test.
Sending data from an Arduino
We’ve created an Arduino library to send self-test results from your Arduino sketch to a test monitor panel. After you install the Arduino library,
- Add
#include "MegunoLink.h"
to the top of your Arduino program, - Create a
TestReport
varliable, then - Call
ReportResult
, for example, to send test-results to the test monitor panel.
The Test Monitor Arduino library reference has details of all the methods available.
Example
This simple example runs a test and reports the result whenever it receives the !Test\r\n
command. The test checks that the power supply voltage to the Arduino is between 4.9 and 5.1 V. The test passes if the supply voltage is within range and fails otherwise. The example Arduino code and MegunoLink project can be found in the Library Examples menu on the main MegunoLink toolbar.
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 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 |
/* ***************************************************************************** * Demonstrate MegunoLink Device Test Panel * Implements a Test command that checks the device voltage and reports pass if * it is within an acceptable range or fail if not. * Use the companion MegunoLink project file: TestDeviceVoltage.mlx (in the same * folder as this file) to view the result in MegunoLink. * Visit https://www.megunolink.com/documentation/program-device/test-monitor-panel/ * for more information. * *****************************************************************************/ #include "MegunoLink.h" #include "CommandHandler.h" CommandHandler<> Commands; // ----------------------------------------------------------------------------- // Self Test Implementation void TestVcc() { long BatteryVoltage = MeasureVcc(); const long MinAcceptableBatteryVoltage = 4900; // mV const long MaxAcceptableBatteryVoltage = 5100; // mV bool bPass = MinAcceptableBatteryVoltage <= BatteryVoltage && BatteryVoltage <= MaxAcceptableBatteryVoltage; TestReport Test; Test.ReportResult("Power Supply", bPass, BatteryVoltage); } // ----------------------------------------------------------------------------- // Serial command handlers void Cmd_Test(CommandParameter &p) { TestVcc(); } // ----------------------------------------------------------------------------- // Core Arduino implementation void setup() { Serial.begin(9600); Serial.println(F("Test Panel Demo")); Serial.println(F("===============")); Commands.AddCommand(F("Test"), Cmd_Test); } void loop() { // Receive and dispatch serial commands. Commands.Process(); } // ----------------------------------------------------------------------------- // Measures Vcc using the internal 1.1 V reference. See // https://provideyourown.com/2012/secret-arduino-voltmeter-measure-battery-voltage/ long MeasureVcc() { // Read 1.1V reference against AVcc // set the reference to Vcc and the measurement to the internal 1.1V reference #if defined(__AVR_ATmega32U4__) || defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__) ADMUX = _BV(REFS0) | _BV(MUX4) | _BV(MUX3) | _BV(MUX2) | _BV(MUX1); #elif defined (__AVR_ATtiny24__) || defined(__AVR_ATtiny44__) || defined(__AVR_ATtiny84__) ADMUX = _BV(MUX5) | _BV(MUX0); #elif defined (__AVR_ATtiny25__) || defined(__AVR_ATtiny45__) || defined(__AVR_ATtiny85__) ADMUX = _BV(MUX3) | _BV(MUX2); #else ADMUX = _BV(REFS0) | _BV(MUX3) | _BV(MUX2) | _BV(MUX1); #endif delay(2); // Wait for Vref to settle ADCSRA |= _BV(ADSC); // Start conversion while (bit_is_set(ADCSRA, ADSC)); // measuring uint8_t low = ADCL; // must read ADCL first - it then locks ADCH uint8_t high = ADCH; // unlocks both long result = (high << 8) | low; result = 1125300L / result; // Calculate Vcc (in mV); 1125300 = 1.1*1023*1000 return result; // Vcc in millivolts } |