Folks - here's a quick sketch I wrote that can be used to check that an arduino is basically ok without needing any circuitry other than your USB connection. It:
- uses the internal LED for "blink sketch" like behavior - basically a 50% duty cycle blink.
- avoids using delays and instead uses millis() to blink the LED.
- accepts a numerical input from the serial port to set the blink rate of the LED in Hz
That's all. Just thought some folks might find it helpful.
/* Arduino Sanity Test */ /* Uses the internal LED and serial port to ensure unit is basically ok */ /* Global Variables */ unsigned long PreviousMillis; unsigned char BuiltInLED = LOW; // LOW=off, HIGH=on int BlinkFrequency = 2; // LED blink frequency in Hz int ToggleRate = 500 / BlinkFrequency; // ms per half cycle toggle String SerialInput; // Any input from serial port void setup() { // Serial Port initialization Serial.begin(9600); // Setup the internal LED pin pinMode( LED_BUILTIN, OUTPUT ); /* Start counting millis until first toggle */ PreviousMillis = millis(); } void loop() { // Get input from serial port, convert to int, set as blink frequency if( Serial.available() ) { // Get input string SerialInput = Serial.readStringUntil('\n'); // Feedback to serial port Serial.print("Blink rate set to " ); Serial.print(SerialInput); Serial.println(" Hz."); // Set blink rates BlinkFrequency = SerialInput.toInt(); ToggleRate = 500 / BlinkFrequency; } // determine if sufficient time has elapsed and if so, toggle LED if( millis() - PreviousMillis >= ToggleRate ) { // Flip LED State and reset previous BuiltInLED = (BuiltInLED == HIGH) ? LOW : HIGH; digitalWrite( LED_BUILTIN, BuiltInLED ); PreviousMillis = millis(); } delay(1); // 1ms delay at loop bottom }
I edit my posts to fix typos, correct grammar, or improve clarity. On-screen keyboards are evil.
Thanks @binaryrhyme, I'll give it a try.Β
ZoolanderMicro, where small ideas are a big deal
@binaryrhyme
I don't know if you've seen this, but Terry King has also developed a method of testing the Arduino pins as well. I've built the rig and used it to test (and fail) a few Arduino. I mostly use NANOs, so I built mine to fit their footprint.
The only changes I needed to make were to adapt the hardware from the older model 6-pin A0-A5 to the more recent 8 pin A0-A7. I also tried to update the software, but note that A6 and A7 are read-only, so you can't test them by writing values to them anyway π
You can find more details, pictures and descriptions at ...
Anything seems possible when you don't know what you're talking about.
@will Yeh, I was thinking there could be a test harness that used one arduino to test another one. Use I2C to drive the board under test and monitor the outputs or something... there's lots this wee sketch doesn't test, lol. Will check out Terry's rig.
I edit my posts to fix typos, correct grammar, or improve clarity. On-screen keyboards are evil.
Hi @will, please edit the link. The closing brace ended up as part of the URL. Thanks
ZoolanderMicro, where small ideas are a big deal
Hi @will, please edit the link. The closing brace ended up as part of the URL. Thanks
Thanks for the notification. I've removed the angle brackets (long standing habit from email) and I hope it's working now.
Again ...
Anything seems possible when you don't know what you're talking about.