Voltage Divider: Power Supply Monitor

I had a power supply that was suspected as faulty at my office. I put together a voltage divider on an Arduino with an SD card data logger to keep track of the voltage coming out of the unit. See the caveats at the end to learn why this can’t be the only test you do.

It turned out, in this case, that the problem was the UPS the computer was plugged into. The battery was fully charged and had sufficient capacity. But the unit would randomly act like an electrical failure had occurred but would not make the switch to battery power. We experience frequent short power losses at our office (on average more than 1 a week). It is likely that the unit has been damaged by these regular power failures over the years that it has been in place. Fortunately, it is the unit that is shielding the computer from taking the hit on this.

This is one of those blog posts that I’m really writing for myself so that I can come back and find out how I did something if I need to do this again in the future. I’m just inviting the public to read over my shoulder.

Building a Power Supply Monitor

I had not previously worked with monitoring voltage with an Arduino, but I knew it was possible. I also knew that the answer was by using a voltage divider. However, I didn’t know how they worked, so I had a little studying to do. I understand the math behind it, but I still haven’t wrapped my head around what is actually happening electronically. Mostly it is because it works and I haven’t really tried to understand it.

Why Use a Voltage Divider

The need for a voltage divider is so that you can feed a higher voltage into an analog pin of the Arduino without destroying the Arduino. The analog pin can only take 5V in. Any more than that and you will destroy the unit (how much more makes it melt down is unknown by me, but I suspect it wouldn’t take much).

Since I wanted to measure the 12V output of the power supply, I needed to step down 12V to no more than 5V. But I didn’t want to use a voltage regulator that would give me a smooth 5V out. If I did that then I’m not actually monitoring the power supply output. I needed a way to vary the 5V going into the Arduino in relationship to how much the 12V fluctuates.

I could have measured the 5V or 3.3V outputs of the power supply, but I didn’t think those would have as much fluctuation as the 12V might if there was a problem with the supply. While those would have been simpler, and potentially not needed a voltage divider, if the 5V or 3.3V outputs spiked over 5V then it would have destroyed the Arduino. And, since I suspected there was a problem with the supply, I worked under the assumption that they might be spike over their intended voltage.

Voltage Divider Concept

The idea of the divider is that you can feed in 12V (or, in the way I set mine up, anything up to 48V) and it will proportionally divide the supply voltage down to less than 5V. Any fluctuation in the input voltage affects the output voltage. In this way you can monitor voltage drops or spikes safely with a 5V tolerant analog pin of an Arduino.

Vout = Vin * (R2 / (R1 + R2))
Image Credit: SparkFun

The math is fairly simple. As you can see from the image above the output voltage is equal to voltage in times the value of resistor2 divided by resistor1 and resistor2 added together. There are calculators online that can do the math for you based on resistors you have available. The key is that you never want your output voltage to go over 5V. Therefore you should add in a bit of a buffer in case the voltage at your supply spikes for some reason.

In my case I wanted my output voltage to never be greater than 5V. I had a handful of resistors that I measured with a continuity tester. What worked for me was a 33K (which measured out to 32.7K) and a 3.9K (measured at 3.8K) resistor which would give me a 48V input max. I would have liked my tolerance to be a bit lower (20V) so that I felt like I got more resolution on my final reading, but these were the resistors I had handy.

Code

Here’s the code that I used. The original author of the code is T.K.Hareendran that I got from the ElectroSchematics website. I have modified it to work for my project and therefore have taken his name off of it. But it might be beneficial to read his site on how it works or if you want to add an LCD display to the unit.

Caveat

This is not a perfect solution for several reasons, but it does (potentially) give enough information that can help me know for certain that the power supply is faulty. However, it can’t tell me that it is not faulty because this particular power supply has 3 independent 12V outputs. A whole section of the supply can die and not affect the other 2. If I’m testing a good section there still could be 2 others that are faulty.

The problem, in this case, ended up being a bad UPS. However, if I had monitored this power supply for a few days I may still not have caught a true power supply problem. This circuit can really only tell me if the supply is faulty. It can’t determine if it is definitively good. And, it may not present as faulty on the output I’m using during the test period. Therefore, there are plenty of ways that this circuit may not detect a faulty supply and it can never convince me that the supply is definitely not faulty. It only tests a small subset of potential power supply problems.

Conclusion

While, as mentioned, it cannot tell me if a supply is absolutely good, it does give me a chance to test the supply under load. That is one of the reasons I have not invested in a particular type of power supply tester—you can’t test under load.

This does, however, help explain how a voltage divider can be used and how to read a higher voltage using an Arduino that is limited to 5V input. And, maybe, in the future when I need to remember how to use a voltage divider I will remember that I wrote this down and I don’t have to go searching all over the Internet again for the solution.

Author Interviews: My Thoughts on Types of Interviewers

Recently I was at Digital Book World with my friend Len Edgerly from The Kindle Chronicles podcast. He and I have had an ongoing discussion about what makes a good interview. At Digital Book World (DBW) we talked specifically about interviews with authors.

This came up at DBW because Kathy Doyle from Macmillan Publishers was there and answered an audience question concerning suggestions for authors who who have been approached for an interview. I think she gave some good tips which included listening to other interviews that the interviewer has done to get a feel for what their style is.

Photo of Kathy Doyle, Len Edgerly and David Peach
Kathy Doyle, Len Edgerly, David Peach

 

That brings us back to types, or styles, of author interviews. I have identified three types that I like for different reasons. As an author looking to do an interview with a podcaster or radio station, I think you should try to figure out what the purpose the interviewer is trying to accomplish by having you on their program.

Tell Me About the Author

Sometimes I am less interested in the book than I am the author and their story. This is the type of interview I enjoy on shows like The Kindle Chronicles. I like hearing the story of how the author got to where they are and what types of books they have written.

This type of interview will certainly talk about the author’s latest book, but I don’t listen to these types of programs to learn about books. I listen for the human interest story of how an author ended up where they are.

Tell Me About the Book

Then there are times when I am much more interested in the book than I am the author. For example, The Art of Manliness podcast does many author interviews. I enjoy these, not because of who the author is, but because of what the book is about.

In this type of interview I am wanting to hear about the content of the book. I want to find out if this is a book that I would be interested in buying.

In this interview type the host of the podcast, or other media outlet, has selected the author and book because it fits with their theme. Therefore, the theme of the book is the greater focus in this type of interview.

Tell Me What the Host Wants Me to Know

The third type of author interview that I enjoy is one where the host directs the questions to get the information out of the author that the host is interested in sharing. Todd Henry at The Accidental Creative podcast is a master at this.

Todd is not asking the author to come on the show to talk generically about their work. Todd has a very targeted topic and he interviews authors for the purpose of getting them to share targeted content for the listeners. He is brilliant at asking questions that pull out the few specific points that he wants to share with his audience.

In this type of interview the author may not have a chance to talk about the book as a whole, but may only cover a few select themes covered in the book. That is perfectly fine since the host has an agenda and a reason for sharing the author with his listeners.

Which Format is Best

There is no single best type of author interview. Each of these three interview types has a specific purpose. It would behoove an author to take the time to listen to a few interviews by the host and find out what the host wants to share with the audience. If you don’t hit the target, or especially if you don’t try, then your time may be wasted and the interview may never be played. I have done my share of interviewing and there are times when an interview never makes it out of the recorder because the guest never really understood what the purpose of the interview was.

If you are an author, take the time to learn why the host wants to talk with you. In the process, you may find new readers because they heard what they were listening for in that show.

Comments on KnowHow’s TinkerCAD Tutorial

Allow me to first say that, while I am disagreeing on a couple of points and correcting some of the comments made in this video, I did learn from it and I understand that @padresj is trying to keep this simple. There were a couple of things I did not know about TinkerCAD that I learned from the video.

The purpose of this post is to just make a few comments and answer some of the questions that came up with an alternative way of doing things.

Chromebook

At 3:53 Padre says that a Chromebook might not be the best choice for running TinkerCAD. However, my run-of-the-mill, average Chromebook from 2014 does fine for most stuff. I have rarely felt like my local computer was the cause of any problems. It is usually related to the quality of the internet connection. When starting out, you probably won’t overtax a Chromebook’s ability. My point is, don’t be afraid to try if all you have is a Chromebook.

You definitely want a regular mouse connected to your machine. One with a scroll wheel and middle-click button are best. (Is there such a thing as a scroll wheel mouse that doesn’t have middle click anymore?)

Moving Around the Build Plane

At 21:53 Jason asks about moving around the build plane. Padre said that it is not possible to do what Jason wanted. But it is possible by using the middle-click button on the mouse. You can use the mouse’s middle button to control the point of focus. However, using the F key on the keyboard to lock focus on an object is pretty slick and easy (one of those features I did not know existed).

Stacking Shapes

At 25:35 Jason wants to drop one shape onto another. This is an advanced technique, but Padre seemed to not know this. At first I thought it was that he did not want to explain the technique because it is more complicated. But, based on what else he said, I’m not sure he actually knows this ability exists.

You can stack shapes by adding another build plane (the software calls it a workplane) to the face you want to stack an object on. Use the Workplane icon to drag a new orange (temporary) workplane onto an object face. Then click the object you want to stack and hit the letter D.

The face that the new workplane goes on does not have to be a top or bottom face. It can be a side face. You can also choose a new workplane before bringing a new object onto the modeling area. Doing that will let you place text or other objects  onto the workplane in the correct orientation.

To delete the temporary workplane and get back to the standard one select Workplane again and click anywhere outside the current temporary one.

Copy VS Duplicate

At 42:28 Padre says to use CTRL-C and CTRL-D to make a duplicate in the same place. You don’t need the CTRL-C step. By itself, CTRL-D makes a duplicate of the selected object.

If you want to paste an object, not in the same place, then you need to use CTRL-C and then CTRL-V. I can’t think of any time when doing this is better than just making a duplicate in place.

There are some interesting duplication rules in TinkerCAD that you may want to explore, but they are more advanced than this video is trying to be.

Aligning Objects

Starting at 47:30 Padre goes into a convoluted explanation of how to make a box smaller by subtracting 2 mm off of each side of the duplicate box so that you can keep them both centered. There is a much easier way to align 2 (or more) objects than trying to subtract a certain amount from each side of an object

Select the objects you want to align and choose the alignment tool. Alternately, after choosing the objects you can press the letter L on the keyboard. Once the tool is active, use the control dots to align the objects to each other in various ways. You can align left/right/center, front/back/center, or top/bottom/center. To accomplish center alignment, like in the video, you would choose the two center alignment dots on the build plane.

Micrometer

I agree that a good set of calipers/micrometer is better than the cheap ones. And sometimes it makes sense to spend money on better tools at the beginning. But this is one where I disagree with Father Robert. Buying a cheap set (sub $20) may be all you ever need. If you decide that 3D modeling is not for you, then there is no reason to have a $40 tool lying around that you will never use again.

I’ve had my $15 Harbor Freight calipers for over a year and have never had to replace the batteries (a complaint he has shared previously), nor had them fail in any way. I understand that better tools are likely to perform better and last longer, but this is one where I think I would recommend something inexpensive to get you into the field as opposed to scaring you off by suggesting a more expensive tool.

Thanks for the great video. I did learn a few things along the way. I just hope that some of the extra tips help make using TinkerCAD a bit more enjoyable.

Wanhao Duplicator i3 Plus Conversion: Firmware

For my Wanhao i3 Plus clone conversion to a RAMPS setup, I chose Marlin as my firmware. This is for practical reasons more than because I have a strong opinion one way or another. I have read much more about Marlin than any other firmware and I have a friend who runs a Marlin variant for his printer; therefore, I know I can lean on him for configuration help.

I will not go into every small step of setting up and configuring Marlin. There are plenty of guides online that can do a much better job. What I do want to cover are the configuration options that you need to know specifically for the Wanhao Duplicator i3 Plus and its various rebranded counterparts.

Basic Parameters

  • 200, 200, 180 mm build volume (X, Y and Z respectively)
  • Extruder steps per mm: 96
  • X steps per mm: 80.15
  • Y steps per mm: 80.15
  • Z steps per mm: 399.5

The steps per mm numbers above are what mine is currently set to. I am still doing some tuning to make things more precise, but this should get you started. I would assume that your numbers would be identical to mine assuming you still have the stock motors, belts and drive screws. However, other settings inside of Marlin could affect these numbers.

Configuration Changes

I will paste my full configuration.h file below, but here are the lines that I have changed. I will put the line number as it appears in the original Marlin 1.1.x configuration.h file. Listed below are what they were changed to for getting my printer working, but not necessarily perfect. I don’t anticipate that I will update this document with every little change I make in the future.

  • Line 275: #define TEMP_SENSOR_BED 1
  • Line 326: #define PID_AUTOTUNE_MENU
  • Line 339: #define DEFAULT_Kp 25.83
  • Line 340: #define DEFAULT_Ki 1.49
  • Line 341: #define DEFAULT_Kd 112.15
  • Line 475: #define X_MIN_ENDSTOP_INVERTING true
  • Line 476: #define Y_MIN_ENDSTOP_INVERTING true
  • Line 477: #define Z_MIN_ENDSTOP_INVERTING true
  • Line 512: #define DEFAULT_AXIS_STEPS_PER_UNIT { 80.15, 80.15, 399.5, 96 }
  • Line 527: #define DEFAULT_MAX_ACCELERATION { 3000, 2000, 100, 10000 }
  • Line 537: #define DEFAULT_ACCELERATION 1500
  • Line 764: #define Z_MAX_POS 180
  • Line 1231: #define ENCODER_PULSES_PER_STEP 2
  • Line 1237: #define ENCODER_STEPS_PER_MENU_ITEM 2
  • Line 1254: #define REVERSE_ENCODER_DIRECTION
  • Line 1262: #define REVERSE_MENU_DIRECTION
  • Line 1364: #define REPRAP_DISCOUNT_FULL_GRAPHIC_SMART_CONTROLLER

Configuration Details

Lines 1231 and down have to do with the particular LCD display that came with my RAMPS board. You will have to look around for the settings for the display you are using. Mine says “RepRapDiscount Full Graphic Smart Controller” below the LCD.

Line 275 sets the type of thermistor for the heated bed. I uncommented line 326. This was to turn on a PID autotune feature on the control unit. PID is set with lines 339-341. The endstops have to be switched to true because on the Wanhao printer they are wired NO (normally open) as opposed to NC (normally closed).

The DEFAULT_AXIS_STEPS_PER_UNIT on line 512 is to set the motor driver steps. This is a line that you will adjust to dial in how far each step on the motor actually is. You can read the long and detailed version of axis calibration at the RepRap Wiki or check out this Instructable about calibration to get you started.

527 and 537 were changes I made because I was getting a drastic y-axis shift. It turned out the shift was due to the motor driver overheating. With a fan blowing on my RAMPS board I no longer have that problem. I may change lines 527 and 537 back to the default numbers to get more speed out of the printer.

That should be enough information to get you up and running with Marlin. Then you can spend the next 3 years continuing to tweak these settings and many other parameters.

Wanhao Duplicator i3 Plus: Ribbon Cable Pinout

This is the pinout information for rebuilding a Wanhao Duplicator i3 Plus using a RAMPS control board. My printer is actually a Monoprice Maker Select Plus, but it is manufactured by Wanhao who seems to make printers for many brands. Therefore, I have decided to start referring to this printer as a Wanhao machine in hopes that others who have various rebranded printers will be able to get the help they need.

Communication from the control board underneath the printer to the small daughter board behind the actual print head is done through a 16-pin ribbon cable. I had to figure out which of the sensors and actuators in the daughter (or breakout) board corresponded with the ribbon cable pins.

In the end I eliminated the ribbon cable because I did not trust the breakout board behind the print head. This is the part that visibly failed when the motherboard on my printer died. Even though I did an attempt to fix it, I am not certain that all the wiring works as expected. I will explain at the end how I did my own wiring.

Following is an explanation of my original plan, which is probably what you want to do, even though it is more complicated. Then at the end I will tell you how I actually did my wiring. Much simpler. Much more logical. More work. Much uglier.

The Original Plan

This is the best way I could figure out how to explain the ribbon cable that made sense to me. If you discover that any of this information is incorrect, I would greatly appreciate you letting me know. This all seemed to work for me until the voltage regulator in my Arduino burned out. It was at that point I started doubting the breakout board and ended up replacing all the wiring from the print head down to the new RAMPS control board which I explain in the lower part of this post.

Ribbon Cable PinoutGraphical layout of ribbon cable.

Above is a drawing of the output of the cable underneath the print bed. You need to patch into this cable and connect the various pins to the RAMPS control module.

Here is what I have figured out each of these pins do.

  • Pins 1-4: Heater Ground
  • Pins 5-8: Heater Voltage, Hotend Fan Voltage, PWM Fan Voltage
  • Pins 9, 11, 13, 15: Extruder Motor
  • Pin 10: PWM Fan Ground
  • Pin 12: Thermistor Voltage
  • Pin 14: X-axis Limit Switch
  • Pin 16: Signal for Hotend Fan, X-axis Switch and Thermistor

Pin 16


Photo of the ribbon cable connector
I used DuPont cables to plug into the ribbon cable and then out to the RAMPS module. I made them into blocks of cables (1X2 and 1X4) as much as was possible. This keeps you from accidentally switching around the wiring.

The complicated one was the wire coming out of pin 16. It needed to split three ways into the RAMPS board. One wire needed to go into 1 of the 2 inputs of the x-axis limit switch. Another wire for the hotend fan. Finally a wire for the hotend thermistor. You can see in the picture below how I split that out.Photo of a 3-way split on the cable.

What I don’t show in the picture above is how those are all connected together. The black wire is coming out of pin 16 of the ribbon cable (using a male DuPont connector). I then cut that wire and soldered 3 wires with female connectors onto it. This gives me the three outputs needed for the x-axis switch, thermistor and fan.

Blocks of 1-4 and 5-8

I used wires (18 AWG) from a computer power supply for the next part. These were to form the blocks of wires that are needed to plug into multiple pins but go out to a single wires.

For pins 1-4 strip back between 1/4″ and 1/2″ of insulation of one of the 18 gauge wires. I used black since this was ground. Then split the bundle of stranded wire in half. Crimp a male DuPont connector onto half the wires and another one onto the other half so that you use up all the strands split evenly between the two DuPont connectors. These two connectors can plug into pins 1 and 2 or 1 and 3 on the ribbon cable. It does not matter which way you do it.

Do the same thing with another (black) wire. This one will plug into the other two pins in the ribbon cable you have not used out of pins 1-4. My package of DuPont connectors did not come with any 2X2 blocks. So I made them into two 1X2 blocks for this. But you can do a single block for both wires.

Pins 5-8 are done exactly the same. This time I used a yellow wire. You can see the blocks of wires I made for these 8 pins in the pictures above.

The two black wires (pins 1-4) can be soldered together and plugged into the negative terminal of D10 on RAMPS. The two yellow wires go into the positive terminal of D10. It actually does not matter for the purpose of the heater which wires go to the positive and negative power blocks, but it is important for the fan inputs which are also tied to that 5-8 block

Other Pins

A single 1X4 block can be made with pins 9, 11, 13, and 15. Keep them in order and connect them to the E0 four-pin set on the RAMPS board.

For pins 10, 12 and 14 I used 3 individual DuPont jumpers to go to the appropriate pins on the RAMPS board (the other thermistor pin, and the other x-axis switch pin into set 1 of the limit switch pins).

Untested: Proceed With Caution

This is where I ended up deciding to go a different route on the wiring. What you are missing in my instructions above is the wiring for the print cooling fan. Pin 10 on the ribbon cable is the print cooling fan (called PWM fan on the breakout board up top). That fan would normally plug into the D09 connector of the RAMPS board. It is polarity sensitive.

The problem is that the wiring on the ribbon cable takes half of the fan wiring through pin 10 and the other half through pins 5-8. I think what this means is that you plug pin 10 into the negative side of D09 on RAMPS. Then you don’t do anything with the positive side of D09 since the fan is already being fed with pins 5-8 on the ribbon cable and is already connected.

It won’t hurt anything to give this a try. Logic tells me this should be the way the print cooling fan works. And if it doesn’t, you’ve not hooked up anything that is dangerous.

Wiring: Not Part of the Ribbon Cable

The non-ribbon cable wiring will be hooked up logically. This is all the stuff that hooked up to the original board directly. The heated bed goes to D08. The 4 motors plug into the X, Y and Z1 and Z2 of RAMPS. The bed thermistor will go into its place next to the hotend thermistor. The y-and z-axis switches plug into the 3rd and 5th set of limit switch pins.

What I Actually Did

After watching a video (below) of Tom Sanladerer talking about printer wiring, I decided to go with 2 stranded network cables. That gave me 16 wires to cover 14 inputs from RAMPS to the sensors and actuators up top.

I simply crimped on male DuPont pins at top and female ones at the bottom. Some of the ones at the bottom I plugged directly into RAMPS, some I used other DuPont jumpers to give me a little more length to reach other parts of RAMPS.

It should not matter which wires you use for each connection, but watch the video and see the tips Tom gives. Keep the twisted pairs together for the various connections. I did put the 4 heater connections on one LAN cable and the motor on another. I figured these were the biggest power users and it might help to separate them.

My setup isn’t elegant and I may find a better way to clean up the wiring. The network cables I choose (based on availability in my junk drawer) are not the most flexible. But this setup works well and is much simpler to figure out than using the ribbon cable with the original breakout board.

If I do make a change to this in any way, here are the two ways I would consider doing it:

  1. Just use the original ribbon cable. My concern is that the breakout board used extra wires for the heater. Is this really necessary? Is the ribbon cable stout enough for that? Probably so and it would look much better than what I have.
  2. Use 3 flexible USB cables. That only gives me 12 wires (instead of the needed 14). But currently I’m not actually using all 14. I replaced my thermistor with one that had a wire long enough to go all the way to the control board underneath. So I just left it that way. Concern: the same as for the ribbon cable, are the wire rated for the amperage needed.