Hi everyone, been a while since my last post, but I have been a busy new daddy. 🙂 I wanted to demonstrate what PWM output was and how to use it nicely in a sketch. I’m really big on ramping lights on and off (my entire house is set up that way) and would like to share how do accomplish that. I also wanted to use a video to show PWM outputs on a scope to help me explain the process.
Pulse Width Modulation (PWM, but also sometimes referred to as Pulse-Duration Modulation -PDM) is the manipulating (modulating) of the width of a fixed pulse. The pulses are sent at the same voltage and frequency, so just the width of the pulse is changed. In the screen shot above the fixed voltage is 3.2V and the Frequency is 490Hz.
You can grab the serial controlled Arduino code here, or the shorter fading sketch here.
This is just a quick post about a board I made to program a whole bunch of ATmega 328’s for some kits I’m making. I am ordering the 328’s in bulk, so they are brand new and do not have an Arduino bootloader on them. One of the ways you can get an Arduino bootloader on a factory fresh 328 is use an Arduino Uno and a USBTiny. Sure, I could pop about 100 of these into an Uno, but that would be a lot of work as well as wear and tear on the 28 DIP socket on my Uno.
The answer? A ZIF socket! These are fantastic! Anyone who has installed/upgraded a CPU in a computer knows what these are. ZIF stands for Zero Insertion Force. That means you drop the chip in the socket very easy, then pull a lever down to secure the contacts and prevent the chip from bouncing out of there. Making swapping out a bunch of chips to program them a lot easier, faster, and less prone to damage to the pins or chips!
I needed to charge an iPad, but I couldn’t do it the “normal” way because it was stuck in a wall! I had mounted 2 iPads in walls at a customers house. I did this by cutting a big iPad sized hole in the wall, and then building a custom mounting dock for it. I also embedded an arduino bootloaded ATmega 328 in there along with a MAX3232 (RS232 to TTL) chip for controlling the iPad via RS232. Now all I had to do was keep it charged. I found Ladyada’s mintyboost resources a huge help. She even has a video on Reverse engineering Apple’s secret charging methods. With her video and mintyboost page, I was able to build a working charging circuit that has worked perfect since December of 2010.
On a side note, you may ask yourself why would anyone put an iPad in a wall? Well, it serves as a lot of cool things, but the main one is to control the home automation systems I install. And an iPad is about the same price (with my dock) as a touchscreen the automation company sells. The automation system controls HVAC, lighting, security, audio (multi room/source), video, intercom, and also have close contact output as well as 5 RS232/485 ports, Ethernet, and telco connectivity. I’ll have to show off my automation system one day, it’s really an amazingly flexible system.
Why not just use the stock iPad charger? Because I don’t do cheesy. Apple chargers are cheesy? No, of course not. I will not tolerate any wires in plain sight at a customer installation. Ever. And I have seen a number of on wall (not in wall) iPad docks that have a wire going down to an outlet. Let’s just say, that’s not my style. NEC code does not allow for exposed high voltage inside a wall, like an outlet with an Apple charger sticking out. So the answer was to build my own solution with low voltage only. For power, I used 2 5v 2A power supplies from Adafruit.
Keep in mind that an iPad charger will charge an iPhone, but an iPhone charger will not charge an iPad. At least this is what Apple tells you. The truth be told, an iPhone charger will charge an iPad when it’s asleep, but that’s at a trickle rate that is painfully slow. I say all that to say this: I’m not clamming this is the only way to charge iDevices, it’s just the way I did it. This method will charge any device currently out right now including the iPad 2.
Here is a shot of the end result. The wow factor is there with authority.
A while ago I posted about my bench lights, and have gotten a number of request for schematics and code. I’ll gladly put the code up, but I also wanted to explain what I did so that others can create their own, or at least change my design up as they wish. The transistors I’m using are TIP122’s. You can find the data sheet here. They will switch a lot of power, but keep in mind, they need to have adequate cooling if you are going to push them hard. Always remember, fire = bad.
I covered the basic schematic for a few LED’s in the video above, but if you have any questions, feel free to post them in the comments and I will answer as quickly as I can.
You can download the original (controller with LCD and hard buttons) code here.
You can also download the newer (serial controlled – adjustable level) code here.
Just a note, I will be using Vimeo from now on, but I will still put all my videos on YouTube as well.