Introduction: Automatic Device Tester With Arduino
This might not look like much, but this is probably the most useful thing I have ever made with an Arduino. It is an automatic tester for product I sell called the Power Blough-R. Not only does it save me time (It has currently saved me at least 4 hours, and counting) but it also give me a much stronger confidence that the product is 100% functional before shipping out.
The Power Blough-R, pronounced "Power Blocker" (it's a play on my name which is surprisingly pronounced "lock"!), is for solving the backfeed power issue you can often experience when using octoprint with a 3d printer.
To use the tester, you just place a Power Blough-R into the USB headers and press the reset button on the Arduino Nano. The tester will run through a suite of tests and will indicate if the device passed or failed the tests using the Nano's built in LED (Solid for passed, flashing for failed).
When you have a lot of something to make, finding ways of reducing time per unit can have a massive impact, using this tester reduced the time it took me to test a unit from roughly 30 seconds to 5 seconds. While 25 seconds doesn't sound like alot, when you have 100s of these things to do it adds up!
I think the most impressive thing I can say about it is, with this tool it takes me shorter to test the Power Blough-R twice than it does to just open the anti-static bag that it ships in!
You are probably not going to need to build this exact device, but hopefully some of what I'm doing might be useful to you.
Step 1: Check Out the Video
Most of what I cover in this write up is available this video, so check it out if videos are your thing!
Step 2: The Power Blough-R
So what is the Power Blough-R and what does it do?
If you ever used Octoprint with your 3D printer, there is often an issue where your printer's screen is kept on by the USB power from the raspberry pi, even when the printer power is off. While this is isn't the end of the world, it can become quite annoying especially in a dark room.
The Power Blough-R is a just simple PCB with a Male and a Female USB connector on it, but it does not connect the 5V line.
There are other methods for solving for this problem, some people cut the 5V line of their USB cable or put some tape over the 5V connector, but I wanted to come up with a simple, robust way to achieve the same outcome, without harming any USB cables!
If you are interested in the Power BLough-R, they are available to buy:
- On my Tindie Store (Kit or Assembled)
- TH3dstudio.com (Assembled)
(Just as BTW, This post is not sponsored and I have no involvement with TH3D other than the supply of the Power Blough-Rs. I have not received anything extra for including links to TH3D it or was a write-up/video ever discussed as part of the original deal)
Step 3: Background: the Big Order
I sold the Power Blough-Rs on my Tindie store, mainly as kits. But for the ones I sold assembled, I would test them with the a multi-meter. In would test for a good connection between the input and the output of Ground, D- and D+ and that 5V was not connected and testing for bridges.
This would take about 30 seconds or so and was very prone to me making mistakes if I was not being very careful. But for the amount of assembled ones I was selling, it was not a huge time commitment.
But I posted a picture of the Power Blough-R on the 3d printing sub reddit, and Tim from TH3DStudio.com contacted me enquiring about ordering some to stock on his store as a trial. I said sure and asked how many was he looking for. I expected him to say 10 or 20, but he said let's start with 100....
It would be nearly impossible for me to confidently test 100 devices with the multimeter so I knew I had to do something about it!
Step 4: Hardware
I went for the absolute simplest way I could assemble this as I was a little pressed for time! It was also a really cheap build (less than ~$5 for everything).
- Arduino Nano (This one has a micro USB, but any will do)*
- Nano Screw Terminal Breakout*
- Male USB Breakout*
- Female USB Breakout*
- Some Wire
There isn't really a lot to the assembly of this. Solder the header pins to the nano if they are not already and slot into the screw terminal breakout.
5 wires should be soldered onto the Male and Female USB breakouts. Note for the shield wire, the female breakout did not have a pad for this so I soldered it to the side of the connector. These wires can be stripped on the other end and screwed into the screw terminals (Make sure to leave some slack so it's easier to plug in and out the devices)
For the male connector I used the following pins
- GND > 2
- D+ > 3
- D- > 4
- VCC > 5
- Shield > 10
For the female connector I used:
- GND > 6
- D+ > 7
- D- > 8
- VCC > 9
- Shield > 11
Step 5: Software
First off you will need to download the Arduino IDE and set it up if you don't already have it.
You can grab the sketch that I used off my Github and upload it to the board. Once thats done you are good to go!
On startup, the sketch runs through a suite of tests. If all the tests pass, it will set the built-in LED to on. If there are any failures, it will flash the built-in LED. The device will also output the failure reason to the serial monitor, but I don't actually use this feature.
The sketch runs through the following tests
This is to check the Female pins are reading as expected while ignoring the male pins. See the step on Tri-state logic for more info on this one.
This test checks that GND, D+, D- and Shield are connected while the 5V line blocked. This is to check the main functionality of the Power Blough-R, where it passes through everything other than the 5V line.
This checks that the none of the pins are bridged together. So it steps through each pin, setting its output and then checks all other pins are not effected by this.
In the next few steps I'll go through some of the features/concepts used in testing.
Step 6: INPUT_PULLUP
This is a really useful one where it can save you an additional resistor (per pin) in your project. It is especially useful when you are using buttons.
When a pin is set to INPUT_PULLUP, it basically connects the pin to VCC with a 10k resistor. Without a pull-up (or pull-down) resistor, the default state of the pin is considered floating and you will get inconsistent values when you read the pin. As it is quite a high value for a resistor, the state of the pin is easily changed by applying a different logic level to the pin (for example when the button is pressed, it connects the pin to ground and the pin will read LOW.
I set the pin mode of the FEMALE pins to be an INPUT_PULLUP so I have a reference point to what the pin should be (HIGH) as long as their are no external forces on it. Through out the tests, the MALE pins were set LOW and when these two should be connected we would expect the FEMALE pin to be LOW.
Step 7: Tri-state Logic
For the initial test, I wanted to check the logic level of the FEMALE pins while basically ignoring the MALE pins.
This may seem like a problem because the MALE pins would have to have some logic level that would impact right?
Well actually pins of most microcontrollers have what is known as Tri-state logic, meaning that have 3 states that they can be in: HIGH, LOW and HIGH-IMPEDENCE
HIGH-IMPEDENCE is achieved by setting the pin as an INPUT. It is the equivalent of putting a 100 Mega OHM resistor in front of the pin, which will effectively disconnect it from our circuit.
Tri-state logic is one of the main features in Charlie-plexing, which is a sort of a magic way of addressing individual LEDs using a lesser number of pins. Check out the video above if you are interested in leaning more about Charlie-plexing.
Step 8: Testing the Tester
This is actually a really important step, because if you don't test that the tester catches negative scenarios, than can you be confident that when the test passed that the device is working as intended.
If you are familiar with unit testing in software development, this is the equivalent of creating negative tests scenarios.
To test this, I created a couple of boards with mistakes on them:
- Soldered the USB headers on the wrong side of the board. The USB headers will fit fine, but the Ground line will not be connected and the 5V line will be. (unfortunately this one was not created on purpose, which proves the need for the tester!)
- Purposely bridged two pins to test the bridge testing code.
Step 9: Conclusion
As I mentioned at the start of this write-up, this is probable the most useful thing I've built with an Arudino.
Since the original order Tim ordered another 200 Power BLough-Rs and while the time savings is greatly appreciated, the confidence it gives that the product is in perfect working order is the main thing I enjoy from it.
In fact for the order of 200, my Wife basically did all of the testing of them. She really liked how quick it was to use and how simple the pass/fail indicator was.
Hopefully there is something useful to learn out of this guide, if you have any questions please feel free to ask below!
All the best,
Participated in the
Build a Tool Contest