I made a pair of light up Kanye West glasses for New Years!

Firstly, I want to say that I completely ripped off this idea from my very talented friend Jordan.The electrical design is mine, but the fashion design is all hers.I highly recommend you pay her blog a visit to see what kind of other stuff she’s cooked up.

Electrical Design

This was my first time dealing with audio from scratch.I have designed a few filters in school, but never carried them all the way out in a real world application.You can see my schematic here (click to zoom):

The audio signal path has a few stages:

Gain

Right off the microphone, the signal is given a half-rail bias (provided by U1D) and sent through a gain stage.I used an inverting amplifier because it will provide an “infinite” input impedance to the extremely weak microphone audio signal.

Having never dealt with an electret microphone before (besides my ch00f-o-scope which hardly counts), I didn’t know how much gain I was going to need.Being lazy, I simply configured a single 10k pot so that the brush contact connected to the inverting input of U1A and it alone provided both resistors.This is a good lazy solution if you need a gain of 10 or 20.For a gain of 200 though, it proves difficult because you need to carefully turn the pot until the resistance on one side is 1/200th the resistance on the other.Basically, if you split the 270 degrees of turning motion of my pot into 200 segments, you need to turn it to just one segment before the end without touching the end.This is basically impossible, so I did a last minute re-work to make it as you see it in the schematic.

Low Pass Filter

This stage is pretty straight forward.The passive LPF’s cutoff frequency is determined by:

Freq = 1/(2*pi*R*C)

In this case, that’s around 50Hz. This way, the glasses will only “hear” the base.

Envelope detector

The goal of an envelope detector is to give a voltage output that is proportional to the amplitude of the waveform input.As you can see in this graph, the green waveform is the audio, and the blue waveform is the envelope:

Fun fact, AM (or Amplitude Modulation) radio uses an envelope detector to turn the amplitude of an EM wave into the audio waveform that you hear (the actual carrier frequency is much much higher than the audible band).

A passive envelope detector simply passes the audio through a diode and into a capacitor/resistor pair.The idea is that as the waveform voltage increases, it will charge the capacitor through the diode, but when it decreases, the capacitor will be unable to discharge through the diode, and must instead slowly discharge through the resistor.The time constant of this pair needs to be fairly long or you’ll end up with another waveform instead of an envelope.

Here I am using an active envelope detector.The only difference is that the diode is placed inside the feedback loop of the opamp.This prevents you from having to deal with the .7v drop across a standard diode.The opamp will compensate for that.

The output of the envelope detector is no longer an AC waveform, but rather a DC-ish voltage level that will be somewhere between 1/2 rail voltage (silent) or full rail voltage (really loud).

Comparators

The output of the envelope detector is passed to six comparators that compare it to a threshold value set by the tree of resistors.All of the resistors in this tree are 10k except the top one which is 100k.Because of the limited voltage swing of opamps, the envelope waveform (and the audio waveform for that matter) will never reach the top rail, so I wanted to drop the highest threshold down to a more manageable level.It didn’t really matter anyway because I could always change the gain on the gain stage to compensate.

The output of these comparators is open collector meaning that they are high impedance when off and a current sink when on.

TRIACS

As you’ll read later, EL wire operates on a high-voltage AC supply.TRIACs are switches used for switching (often high-voltage) AC signals on and off.They are switched on by a current passing into or out of their gate, and they switch off again once the current through the TRIAC is zero (this happens twice a cycle).In complicated applications, they can be used to attenuate AC signals (like PWM can attenuate DC signals), but in simpler applications, a continuous current out of the gate will keep the AC running, and no current will stop it.

Most TRIACs require some kind of opto-isolator part to prevent any high-voltage stuff from accidentally frying your more sensitive components (an opto-isolator is literally an LED and a photodiode in a single package.There is nothing conductive connecting the input and output).I found a part that claims that no isolation is needed.It’s a non-stock part on Digikey, but incredibly useful while they’re in stock.As long as current is flowing from the common node out of a gate, this TRIAC will allow AC current to conduct from the common node to the output node.They’re also three TRIACS to each chip, so that’s nice too.

It’s kind of hard to see what’s going on in the schematic because of how I split up each gate, but you can see on the right side that the outputs of the comparators connect to the gates of the TRIACs.On the left side of the schematic, you can see that the common node is connected to the positive voltage rail.This is to ensure that the comparators can exert a negative voltage on the gates and suck current out of them.

Power supply

Each strand of EL wire that I ordered came with a power supply.Rather than trying to build my own, I figured I’d keep the supply intact and simply use my circuit to switch it on and off.

I connected the live terminal of the supply to the “LIVEFROMPSU” terminal and the neutral end to the “LIGHTNEUTRAL” terminal (the VCC rail).Technically, I could have just connected the live terminal straight to the EL wire, but I wanted the opportunity to place a very large resistor between the terminals of the power supply.

I believe these supplies are resonant supplies, and without some kind of load, they will build up a charge somewhere and eventually break down (think of that video of the bridge resonating and exploding).This added resistor provides a dampening effect that will prevent damage.Expecting there to be times when my glasses are totally off (when it’s quiet), I wanted to provide some minimum load to protect the supply.

I’m not sure if this is entirely necessary, or if 470k is even the correct value, but so far, the supply still works.

Mechanical Design

Unlike most of my projects, the mechanical assembly of these glasses was more of a pain than the circuit itself.This is mostly due to the EL wire.

EL Wire

EL wire, or “ElectroLuminescent wire” is weird stuff.There are two conductors separated by some kind of fluorescent material.The two conductors act as a long capacitor, and passing a high frequency, high voltage through this capacitor causes the phosphorescent material to light up.Unlike most light-producing components, DC current doesn’t really pass from one terminal to the other.They stay isolated throughout the entire length.You can see a cross section here:

There are a limited number of colors for the phosphorescent layer, so some of the colors (like the red and pink) just have a blue inner layer with a colored outer layer that reacts with the blue to produce the desired color.Think of how some pigments react with UV light.

Let me just say that stripping EL wire is a pain in the ass. I developed a few techniques, but never really mastered it.The real issue is stripping the clear layer carefully enough to keep the outer conductors intact and not strip the coating off the inner conductor.I found that heating the wire with a flame could sometimes help loosen or soften the coating, but it still typically took me at least three tries every time.I recommend investing in WAY more EL wire than you plan on using.

Glasses

For mounting the EL wire, I simply drilled some holes in the glasses and slipped the stripped ends of the EL wire into those holes.A single dot of super glue keeps the wire from sliding around on the shade.

EL wire operates at around 100V or so.The current is low enough to prevent injury, but that high of a voltage can produce a rather painful shock.I had to be careful when designing the glasses to not allow both conductors to touch my skin.

If you recall from before, for each wire, one of the conductors is traveling straight to the power supply while the other is switched on and off by the TRIACS.Those going straight to the supply are all tied together, while the others are tied individually to my board.At first, I thought there was some importance to the polarization of the EL wire and tried to maintain the polarization used in the power supply I was provided.With this orientation, the inner conductors were all tied together while the outer conductors were connected to the power supply individually.

Mechanically, this was an issue because the inner conductors are extremely fragile, and any sort of tugging on the wires going to my circuit would break them.To fix this, I reversed their roles. I tied all of the outer conductors together, so that all of the strain was going to the stronger inner conductors:

The connections on the outer conductors were wrapped safely in electrical tape to prevent electrocution of my face.

Here’s a schematic doodle:

To bridge the nose, I simply connected the inner conductors of the wire on one side to the inner conductors on the other.All of the outer conductors were tied together for stability and redundancy.

All of this wiring is out of my field of view (as if you can see anything out of these glasses anyway), and above the nose piece, so I actually can’t feel it at all.I’m a little weary of folding the glasses though as the wiring on the right side is a little tight.

Conclusion

I was in a super big hurry to finish this project before New Years, so I was a little hasty with the design.There are numerous ugly reworks of my circuit, and as you can see in the image above, I wasn’t too concerned with aesthetics when cutting a hole out for the gain adjustment knob.The circuit will sometimes enter a mode where all of the lights turn on regardless of incoming audio which can only be fixed by power cycling.I’m not entirely sure why that is, but if I was planning on using these again, I would just redo the circuit entirely.After all as I said before, the glasses were the hard part.

The sound reactive effect of the glasses is really a sight to behold.I’m super impressed with myself.Enjoy!

[via: http://ch00ftech.com]

 

So my father is a cardiologist who is also a geek, so I thought I’d make him something special this year for Christmas.

An iPhone stethoscope!

So, this is actually a very simple project, but it did take me a surprisingly long time to figure out because of the way Apple maps the pins of their connectors.

Physical Design

The physical design of this thing basically consisted of a regular stethoscope and a microphone.

Apple devices like 2.2kOhm, -44dBV microphones.

Here’s the top part of the stethoscope.There was a soft rubbery outer shell filled with a slightly more rigid semi-translucent inner material.The inner material is presumably just to keep the earpieces rigidly held together as it ended right as the stethoscope hose began.Cutting the hose right at this point let me squeeze the microphone into the hose at the point where it was widening and secure it with silicone sealant:

I wanted this thing to look professional (if it had any chance of being used in an actual doctor’s office), so I gave it the special ch00ftech seal.

Alright, so it didn’t come out perfect, but I still think it’s cool.

Electrical Design

The Apple headphone jack has four connections: two for left and right audio, one for microphone, and one for ground.The connector is called a Tip-Ring-Ring-Sleeve connector (TRRS) as opposed to the typical TRS you see in a normal pair of headphones. The idea is that if you plug a normal TRS connector into a TRRS jack, the sleeve of your plug shorts the sleeve and second ring together basically turning it back into a TRS jack. I had to buy one special from Digikey.

Now, typically with TRS connectors, the tip is left audio, the ring is right audio, and the sleeve is ground.This makes sense because the sleeve will run outside of the other wires and is usually connected to some kind of mesh that shields the other conductors from unwanted electrical interference.Because of this, I assumed that the sleeve was also the ground here.I connected the tip and first ring to the left and right channels of a TRS jack (for the user’s headphones) and the second ring to ground.Ground was also connected to the ground of the microphone.The sleeve was connected to the microphone’s positive output.

When I tried this out, the microphone wasn’t working.I figured I had the mic backwards and rotated it around, and it worked!

Now here’s the really funny bit.I couldn’t find my headphones during testing, so I was just trying it out with the headphones disconnected and playing the audio back on my PC speakers.When I finally found my headphones, I noticed that regardless of whether or not the iPod was recording, I could hear audio from the microphone coming through my headphones.This is when I figured out what I was doing wrong.

So I was using the microphone as the headphone ground.With the headphone ground bouncing around, I was picking it up as audio in my headphones.Well, anywho, with all of that fixed, I was done.

Performance

The stethoscope works surprisingly well!You just have to find the right app.Apple’s voice recorder app is meant for just that and does a terrible job.I believe it adds some kind of filtering that is meant to cut out all frequencies outside of the typical speech band.

I got pretty good performance using the iStethoscope app which is really meant to use the iPhone 4′s internal microphone, but can also accept audio from external sources.Here’s a video showing it off:

www.youtube.com/watch?v=bMGmIxnyAzY&feature=youtu.be

There is an odd popping that you hear from time to time, and I’m not certain what’s causing that.I think it might have something to do with the audio processing going on in the app, but it’s still very very useable.

So there it is.I wonder how many other cool microphone-based devices you can make for iPhone…

[via: http://ch00ftech.com]

 

I’m actually seeing some results from my Light Programmer. I’m reading a photoresistor using the analog comparator on an ATmega168. Check out my previous post about the hardware, then join me after the break to see what I changed to get things working, and to see the demo video.

The good news is that it works. In the video I successfully decode a message twice in a row. The bad news is that this is rare. I figure the sync between the JavaScript app and the microcontroller is lost during transmission about 60% of the time.

Input Capture

The last time I posted about this I was using the analog comparator edge interrupt to monitor the photoresistor. This worked but I was detecting multiple edges for each transition. I’ve moved to using the Input Capture circuit which is part of TIMER1.

The input capture can be triggered by the analog comparator. The only real difference with input monitoring is that there is no toggle mode. Because you need to detect both rising and falling edges to use Manchester Encoding, the edge detect will need to be toggled during every interrupt in order to capture both rising and falling edges.

Decoding the Message

Describing how Manchester encoding is a full post in itself. I followed Atmel’s application note (PDF) on the top and you should give it a good read.

Basically, the clock and data signal are rolled into one. Each ‘bit frame’ has two equal parts (called T). The transition that happens between those two parts IS the bit itself. Transitions that happen between these frames are not data, but just used to maintain the timing.

The trick here is to get the sender and receiver to be synced up. The sender starts by sending a bunch of ones, the receiver watches those until 2T has passed between edges, which indicates the receiver has synced with the sender.

I’m also using a preamble of 0x0F to make sure I’m not syncing in the middle of a message.

What’s Not Working

This is a good question. I’m often loosing sync, as indicated by the “LOST” message on the image above. In that case, I lost sync because the sender stopped ending data.

I suspect that the sloppy timing of the in-browser sending program is the culprit. I’d love to keep this a browser-based solution, but I don’t know a way to get lower-level access needed for timing. In the interim, I will probably take another small microcontroller and write code that makes it a programmer by flashing an LED. If that setup is reliable, then it’s a problem with the JavaScript for sure.

The Code

I’ve posted code for the microcontroller, as well as the JavaScript/HTML sending package over at Github.

Follow Me

@szczys

[via: http://jumptuck.com/]

 

Today I decided to take on this bad boy:

Intro

If you’ve been reading my blog regularly, you’ve probably already seen this thing in my icebreaker post.The toy functions as a portable low-resolution scanner that can scan and save a number of images and then reproduce them using persistence of vision.

In the icebreaker, I ripped off how they handled measuring the oscillation-rate to produce the persistence of vision.I could do this without even opening the case.For a future project, I wanted to find out how they managed the scanning function.That’s a little more in depth.

My assumption was that they were scanning using the LED-as-a-sensor trick that I wrote about in this post.The only problem was that with my implementation, the trick requires twice as many micro-controller pins as LEDs.When you get up to 32 LEDs, this gets kind of ridiculous.I wanted to see how they did it.

A starting question

Before getting into the details of the circuit, something has always bothered me about this thing.It has 32 LEDs on its front, and can produce images with 32 pixels of height.As you scan, you can see LEDs illuminate in order.My assumption was always that one LED would turn into a sensor and one or two neighboring LEDs would illuminate and bounce light off the scanned page into the detector.This means that the micro just has to store the values picked up from each LED and then reproduce them when the device is in playback mode.

Using my SLR, I took a 1/1250s photo exposure of the scanning mode in action, and came up with this:

So that confirms that only one LED is lighting at a time.I guess the two neighboring ones are being used as sensors.

The only problem is that it seems like not every LED is being used as a sensor.Take a look at this video.

From here on out, the LEDs being used as sensors will be called “sensors” and the LEDs used as lights will be called “lights”.This only applies in the context of scanning.During reproduction, all LEDs are “lights”.

I figured there had to be some kind of algorithm running inside the micro that would interpolate the pixels between rows and turn a 16 pixel high image into a 32 pixel high image.To test this, I came up with a little experiment.

I used a marker to cover up three of the sensors and did a quick scan.I came up with this:

You can see the three sensors are lighting up (dimly) behind their black marker mask, and the lights around them are also lighting up.This means that the firmware picked up that three of the sensors in a row were coming back black, so the lights between them must also be black.

Now, it is still possible that the LEDs swap jobs for a very very short period of time (lights become sensors, sensors become lights).The results of this experiment could be explained by the fact that the sensors (now being used as lights) are covered up so that the lights (now being used as sensors) have no light to detect.To test this theory, I ran the experiment again supplying light from an external source to the group of covered sensors.I came up with the same results.

So, there is some algorithm that determines the values for the lights using the data from the neighboring sensors.

The circuit

The circuit is split into two boards.

In this image, the bottom board deals mostly with power regulation and the oscillation sensing unit.The top board is where all the brains are.There are four ICs on the top board:

  • 74LV4051 – A standard 8 port analog multiplexer.A multiplexer means that the device has no means to illuminate two LEDs simultaneously.They must be pulsed in turn very quickly.
  • 24LC16 – A 16K EEPROM that is likely used to store the images after they are scanned (the device can store up to six different images and retains them through power loss).
  • “1AP G0K1″ – I was unable to find out what kind of IC this was, but I think it’s safe to assume that it’s some kind of micro controller.

So.The LEDs are multiplexed.Interesting.This is a little worrying for my future endeavors because blinking LEDs that quickly requires a pretty hefty micro controller or an FPGA.The former is expensive, and the latter I’ve never worked with.

Either way, I took another photo of the back, and loaded them up in Photoshop as two separate layers.After mirroring the back and inverting its colors to add contrast, I was able to line them like this:

Playback

My first task was to figure out how images are being displayed on the LEDs.I started by using the paint brush tool in Photoshop to color code exactly which LED is connected to what.It looked like half of the LEDs were connected to the first multiplexer and half to the second.Here are the connections for the first one:

It’s hard to make out, but there are little dots on the pins of the leftmost IC which are color coded to the LEDs. And here’s the second:

As you can see, each pin from a multiplexer connects to two LED anodes.This makes sense; there are 16 ports available between the two multiplexers and 32 LEDs in total.This likely means that control for the LED cathodes is split so that only one of those two LEDs can be illuminated at a time.

Looking at the cathodes, I noticed a pattern where it seemed that every other anode was connected together.You can see that in this image stenciled in white and gray (I only bothered to do half of the LEDs, the other half follow a similar pattern but on two different lines).

The anode lines converge on two transistor circuits shown here:

I had to figure out what the transistors were.They were labeled with just “24″ and “54″ which turned up nothing on Google.Assuming that they were BJTs and used the common pin ordering for BJTs in a SOT-23 package:

I was able to re-draw this part of the circuit as follows:

Now it was just a task of figuring out which transistors were PNP and which were NPN.I noticed that during normal operation (with an LED lit), the emitter and collector of Q4 were high with the base pulled low.That would seem to imply that Q4 was a PNP transistor: Pulling current from the emitter to the base caused current to flow from the emitter to the collector.Similarly, the emitter and collector of Q5 were low as the base was high.This would imply that Q5 is an NPN.Q4 was marked with “54″ and Q5 with “24″ so I guess all the 54s are PNP and all the 24s are NPN.Adding the appropriate markings to my schematic produces this:

It’s worth noting that R1 and R5 are 90 ohm resistors which means that these LEDs are probably being run a little above spec.Assuming a Vf of 2v (typical for red LEDs), that gives you a current of 33mA!This is acceptable though considering how the LEDs are all being driven at a very low duty cycle.

It’s not quite clear what the connections through R2 and R6 do.My first guess was that that’s how the micro controller reads the voltage off the high side of the LEDs as it drops (assuming they’re using the same method I used for the LDDs article), but as I found out later, that’s not the case.They aren’t unique connections either.The line coming from R2 also connects to R4 which serves a similar purpose in one of the other low-side drivers.

So, one issue I noticed is that all four of the low side drive circuits (these two and the two driving the rest of the LEDs) are all controlled by the same line coming from the micro controller.This really bothered me for quite a while because as I said earlier, in order to have two LED anodes on the same multiplexer port, there needs to be some way to drive the cathodes independently.Well, it turns out that the other two circuits aren’t the same as the first two.They look like this:

Where one of them includes the resistor to 5v like before.So this solves that problem.When the signal line from the micro controller is low, the first two ports are off and the second two ports are on.When the signal is high, the opposite happens.This prevents the micro from being able to control two LEDs simultaneously.It interesting to note that this method isn’t perfect as there will be some crossover when both of the LED sinks are active.If you darken the room and look closely, you can often see a slight ghosting effect as the image from the top of the stick is repeated to the bottom very dimly.This isn’t noticeable though unless your image exists primarily in one half.

Scanning

Now scanning on these LEDs is a lot more complicated.The whole method depends on the touchy-feely process of running an LED in reverse bias.LEDs aren’t really meant to do this, so the LED manufacturers aren’t going to make it super easy.This requires some gentle massaging on the part of the engineer designing the circuit.Without access to their test data and data sheets, it makes it very difficult to tell exactly what is going on.

As I said before, the high side of each LED bank is an an analog multiplexer.The common pin of this mux has a PNP transistor dropping current into it and by extension into the LEDs.One of the muxes also has an additional three terminal transistor device seen here as Q9.

Also indicated here is the “PR” trace.This trace runs straight to the micro and also on to the second board.I’m not certain what the “PR” stands for, but I’m pretty sure that this is an analog line that feeds into an onboard ADC on the micro.This would explain why it’s connected to the other board; it’s used to measure the voltage off the proximity sensor that the device is using as a cheap accelerometer as I did in the icebreaker.

Here’s a simplified doodle of this part of the circuit:

During scanning operation, BJT’s base is pulled high, turning it off.

Now back to that Q9 device.It’s not marked 54 or 24 like the other BJTs and my guess is that it’s some kind of FET.This would make sense because the gate of a FET would provide a very high impedance allowing the small amount of current coming from the LEDs to charge the capacitor and raise the cap voltage.The rising voltage on the gate of the FET would turn it on or off appropriately and allow a nice buffered signal to go the the ADC of the micro along the “PR” line.Here’s a trace of the PR line during scanning operation:

This is the device scanning a number of LEDs.The FET device appears to work as an inverter (pulling down the 33k resistor) so the sloping voltage drop you’re seeing here is actually the voltage rising on the capacitor.Two things are interesting about this picture:

  1. The micro appears to spend an equal amount of time measuring each LED.This is how I realized that it had to have an ADC (as opposed to measuring the varying amount of time it would take the cap to charge to a fixed voltage like I did in my LDD).
  2. Some LEDs charge the cap more than others.This makes sense because for this trace I was scanning a drawing that I did in Sharpie on white paper.

I marked the Source, Drain, and Gate in the above schematic following the standard SOT-23 ordering:

Now, unlike the BJTs, searching for a SOT-23 device marked with “KN” did turn up a result.I found the 2SJ305 which is a P-type FET.This was troubling to hear.Typically for a P-FET, the source is tied to the high voltage rail.With the source tied to ground, it would be impossible get a negative Vgs to even turn the FET on!

Well, I really worked on this problem for a while.It’s possible, that because the source is tied to ground through the 2k resistor that the source could float up a bit and allow a negative Vgs, and it was that much more believable because I figured that the designers would have been pulling some serious black magic to get this gadget to work anyway.

Well, I got frustrated and decided to ask the minds on the /r/ECE subreddit.I got some pretty awesome responses.They pointed out that it’s completely plausible that the device is actually an N-type MOSFET as often times multiple components will share the same labels (and even be mis-labeled entirely!).

Just to be sure, I ran a little experiment with this circuit:

The gate was attached to a free piece of wire that I could connect to various parts of the circuit. I soldered the circuit right on to the mystery FET straight on the board.This was easier than desoldering it, and assuming power was disconnected to the board, it would likely be no different.

Here are my results:

This is it with the gate floating (I noticed the same results when I tied it to ground, so the analog mux must be grounding it).The LED is on, but only slightly.

BOOM! When I attached the gate to the positive rail, the LED got super bright.This means that my suspicions were correct.It’s not a P-FET at all, but rather an N-FET with the source tied to the low rail like it’s supposed to be.

 Putting it all together

All together, my circuit now looks like this:

And here’s a timing diagram doodle to help out:

For scanning, the LEDs are arranged in such a way that when the current sink is active to turn on the necessary light, the current sink for the adjacent sensor must also be activated.B and C appear to fight that current sink and pull the LED cathodes high but only to about .5V.I’m not too sure what the purpose of this is because there’s nothing stopping the circuit from having the adjacent lights and sensors on two different current sinks.Perhaps if they were able to pull it up to 5V, the LEDs would conduct too much current too quickly or something?

I think in the context of displaying on the LEDs, B and C just tag along with A to help pull down the LED cathodes that much more.

Remaining questions (and answers)

My biggest remaining question was exactly what purpose R9 and R10 serve. They appeared to be some kind of pull up resistors, but they seemed to be doing a lot more than that.This is a scope trace of A (yellow) and the PR line (green) (different voltage scales):

So you can see that the cap is being charged and discharged both as A is high and low.Here’s the same trace with R10 removed:

Obviously, it’s totally screwed up.Here’s the really weird part.When I removed R10, I noticed that this seemed to break the scanning functionality of the LEDs labeled as “Right” on my schematic.Also, you can see that the PR line doesn’t oscillate when A is high.That means that as C is oscillating, the PR line does nothing.

The weird part is that R10 isn’t even close to C or the “Right” LEDs!

Well, it wasn’t until I had it all drawn out that I realized exactly what was going on.I had forgotten that this gadget is multiplexing the LEDs so that while one LED is begin used as a sensor, there is another one joined at the anode:

If that 10k resistor wasn’t there, the second LED would suck all of the reverse current out of the mux and prevent the capacitor from charging!In effect, when the mux is measuring an LED, it’s also measuring its twin, but the assumption is that the twin isn’t very well illuminated, so the reverse current will be negligible.

Now the only thing I’m left wondering about is what R4 and R6 do.They lightly attach the C and B lines to the LED light sinks.My guess is that the designer just wanted to keep the cathodes of the LEDs from floating when the source was turned off, and added that in there.Removing R6 didn’t have any appreciable effect on device function.

Conclusion

So, I still don’t know exactly what’s going on inside the micro controller, but it’s pretty easy to guess that it’s taking analog readings from all of the LEDs, using their values to determine some black vs. white threshold, and storing the values in its EEPROM to be displayed on the LEDs.

There is still more to the circuit (power stages, etc), but I covered all of the real magic in this review.I’m planning on implementing a similar technique in a product I will be developing, so this definitely provides an awesome head start.

This is my first time every trying to reverse engineer a product, and I’m really impressed with myself.I certainly wasn’t expecting to get such a complete picture with so little information at my disposal.If I find another product that is similarly cool, I’ll be sure to do another one of these write-ups!

I hope you enjoyed it!

[via: http://ch00ftech.com]

 

#split vcf files

working_dir=‘/home/mike/compile/’

input_file=‘final.vcf’

output_seed=‘contacts-part-’

vcards_per_file=75

withopen(working_dir+input_file,‘r’)asf:

count=0

output_count=1

results=[]

forlineinf:

if(“BEGIN:VCARD”inline):

count+=1

if(count<=vcards_per_file):

results.append(line)

else:

#output file with stored values

withopen(working_dir+output_seed+str(output_count)+‘.vcf’,‘w’)asoFile:

foriteminresults:

oFile.write(item)

#increment outputfile count

output_count+=1

#clear results list and append last read line

delresults[:]

results.append(line)

#set counter back to 1

count=1

#write the last set of results to a file

withopen(working_dir+output_seed+str(output_count)+‘.vcf’,‘w’)asoFile:

foriteminresults:

oFile.write(item)

[via: http://jumptuck.com/]

 

I’ve been working on a way to push data into a microcontroller using a computer monitor (or smart phone) which flashes black and white. I’ve done some preliminary tests using one photoresistor read by an ATmega168 analog comparator circuit. The results have been mixed.

Analog Inputs

Here are the two circuits responsible for voltages being measured by the analog comparator. The circuit on the left should produce 2.5 volts on the AIN0 pin. Strictly speaking the 330 Ohm resistors (R1 and R3) are unnecessary, but I’ve included them to protect the microcontroller from unrestricted current if the trimpot is turned all the way to one side.

On the right is the circuit with the photoresistor. When it is held up to a white screen, the voltage is around 1.5 volts. A black screen produces about 3.5 volts. This is distinctly different from the 2.5V reference and easy for the analog comparator to differentiate.

The Results

So far the results are not entirely good. I have no problem detecting edges with the comparator running in toggle mode. But when I have the microcontroller count those edges I find it’s registering multiple (sometimes dozens) of edges for each transition. I have experimented with little success to filter these out in software by checking a running timer before registering the next reading. I also tried only detecting rising edges, or switching between rising and falling detection after each interrupt. I’m not entirely certain if timing is part of the problem. I’m testing with a JavaScript application that flashes a sync signal, preamble, and data packet using Manchester encoding with 100ms bit frames. It could be that the timing for that is very unreliable, and outside of the +/- 10ms window I’m allowing for in each half-bit frame. (Give it a try if you wish)

It seems the best I can do with this method is to almost reliably count rising edges (within maybe 10%). However, I know that the ATmega168 has input capture capabilities built into Timer1 which include a hardware noise filter. I’m still studying the datasheet on how this works, but you can bank on seeing a post about that functionality soon.

This would be a lot easier to resolve if I owned an oscilloscope. I would be able to toggle a pin on the uC with each interrupt, using that output to measure the timing with the scope. Oh well… I don’t think I’ll have that tool in hand any time soon, if ever.

[via: http://jumptuck.com/]

 

I’m working on a new clock design. I’m not ready to talk much about it yet, but I did order a couple of different LEDs for it. I need blue LEDs and red/blue bicolor LEDs where the blues match each other. I wanted 5mm diffused parts and was able to find them, but not both types from the same vendor. The parts just arrived and above you can see me testing them out.

They’re incredibly bright! In fact, I have to run them at a pretty low duty cycle for them not to burn your eyes out:

  • Blue LEDs at 1/16 duty cycle
  • Red LEDs at 1/4 duty cycle

I’m driving them all at 10ma. You can see that the bi-color produces a nice magenta color. One unexpected phenomenon is that there is a blue halo around the bicolor LED. It must have something to do with the wavelength and the curved dome of the case. Oh well, this will only happen a few times per day so it doesn’t worry me.

More on this clock as I get further into the development process.

[via: http://jumptuck.com/]

 

After I posted the menorah yesterday where I said in passing that you’re not supposed to have circuit traces bend at right angles, I got a few questions from readers asking exactly why this is.The explanation is kind of complicated and involves some of Maxwell’s equations as well as multivariable calculus, but I’ll do my best to explain it in a way that doesn’t require any special knowledge of either of these topics.This is going to be a doozy, so read on if you dare.

Terminology

Flux

Flux (Φ) is a term that is used when dealing with vector fields.In this article’s context, it sort of describes the amount of electric field that is passing through a surface.Think of it this way: let’s say you have a river flowing by you and you dip a tennis racket into it.If you were to multiply the area of the tennis racket by the rate of water flow, that would be the flux of the water through the surface described by the rim of the racket.Increasing the size of the racket would increase the flux as would increasing the flow rate of the water.

If you were to turn the racket sideways so that the water runs along either side without passing through, the flux would be zero.Basically, flux is only concerned with the component of the water’s motion that is perpendicular to the area of the racket.If the water runs parallel to its surface, there is no flux.

Electric Field

Electric fields are vector fields that originate in positive charges and end in negative charges (we’re using conventional charge here by the way).A positively charged particle, when placed in an electric field, will feel a force in the direction of the field proportional the the strength of the field and the charge of the particle.

This is why electric fields must be zero inside conductors.If there was ever a non-zero electric field inside a conductor, the charges would be able to move along that field.Given enough time, all of the charges would find their final resting places and there would be no electric fields remaining.This all happens at roughly the speed of light, so it’s pretty safe to say that there is never an electric field inside a conductor.

Electric fields are typically represented as curved lines with arrows pointing towards negative charges.The spacing between the lines represents field strength with closer lines representing stronger fields.

Electric fields can take on a number of shapes given the geometry of the charges.A single charge’s electric field might look like this:

When placed near a negative charge, it might look like this:

One configuration that is actually quite common (though it might not seem like it should be) is an infinitely large charged conducting plane.The following is a cross-section of such an arrangement.Notice that the charges line up on the surface.This is because they’re trying to get as far away from each other as possible (like charges repel).

Note that the fields are parallel to each other.This can only really be true in an infinite sheet.Think about it this way: if the plane goes on forever in every direction, what reason would the field lines have to arbitrarily go in any particular direction?That’s a pretty weak proof, but it’s easy, and it happens to lead you to the right conclusion.

In reality of course, there are no infinite planes of charge, but on a small enough scale, you can think of any plane as an infinite plane and get fairly accurate results.

Electric potential

Electric potential describes the energy that charges store when they are placed into an electric field.Remember what I said earlier about charges moving along an electric field?The movement of charge in such a manner is the conversion of potential energy to kinetic energy.Potential is usually thought of as a difference in potential between two points and is measured as the energy that would be released if a charge were allowed to travel between these two points:

Note that it is only concerned with the distance travelled parallel to the electric field.If you were standing on an infinite plane of charge and moved a free charge to the left a foot, you would not be changing its potential at all because its motion was not in the direction of electric field.

An easy way to think of this is to draw “equipotential” lines which represent….well…points that are at equal potential.When we moved that hypothetical charge to the left a foot, we were moving it along an equipotential line.

If you want to measure the potential between two points, you just need to count how many equipotential lines you cross when going from point A to point B.

Measuring potential would be rather confusing if you had to constantly specify where your starting point was every time.Because of this, engineers typically use “ground” as a reference point.Although the ground potential in my wristwatch’s circuit is not the same as the ground point in your laptop, for all the components in a single circuit, the ground is the same.

So that’s enough for vocabulary.On to the nitty gritty.

Gauss’s Law

Gauss’s Law is one of Maxwell’s equations.It describes the relationship between the electric flux through the surfaces of a 3d shape and the charges contained within that shape.All you need to know is that the more flux you have, the more charge you have.Here’s an example:

This is a single charge inside an imaginary sphere that we will consider out “Gaussian Surface”.To measure the flux, think of the surface of that sphere as being made up of tons of tiny little tennis rackets from our metaphor, then measure the electric field passing through each of them.

Note that A-perpendicular is just A in this case because the geometry dictates that the electric field lines will always be perpendicular to the sphere’s surface.This is why we don’t use a cube in this example.

The sum of all of these little fluxes will equal the total flux generated by this charge and will be proportional to the charge.

You might be wondering how this can be.What prevents us from changing the size of the sphere without altering the charge at all.After all, it’s an imaginary sphere, we can do whatever we want to it without touching the charge. Wouldn’t changing the Gaussian surface change the flux?

The answer is: No.

Notice that the electric field lines spread out as they get farther away from the charge.As I said before, the density of the electric field lines represents the field’s strength.As it turns out, the farther away you get from a charge, the weaker the electric field.

So, let’s say you use tennis rackets of the same size to make a larger Gaussian surface.You would probably need a lot more tennis rackets.Each of these rackets would have a weaker electric field passing through it, and after adding them all together, you would end up with exactly the same amount of total electric flux and therefore the same amount of charge.

Gauss’s Law on an Infinite Conducting Plane

Let’s return to our concept of an infinite conducting plane.Does Gauss’s law work here? Yes!

Here is a drawing of a Gaussian cube measuring the charge on the surface of an infinite plane:

That’s a little confusing to deal with, so let’s drop down to a two-dimensional cross section.Once you understand it in 2d, it should be pretty easy to jump back to 3d.

Applying Gauss’s law is quite easy.All of the cube’s surface that exists inside the conductor can be ignored because the electric field inside a conductor is zero.Likewise, all of the sides of the cube can be ignored because their tennis rackets run parallel to the electric field.That means that the area of the top of the cube is proportional to the charge inside it.

This makes sense when you think about it.The only way to increase the flux is to increase the area of the top.Making the cube taller or shorter will have no bearing on the flux.The perpendicular area and electric field strength are unchanged.

So how does this all relate to bent traces?

On a small enough scale, you can think of a trace in your circuit as its own little infinite plane (it’s a stretch, I know, but it works, trust me).

Let’s try applying this Gauss’s law technique to a slightly bent infinite plane:

For the Gaussian shapes on the right and left, nothing has changed, but for the one in the middle, a lot has.Remember how we could make the cube as tall or short as we wanted before without changing anything?With the geometry of the bent edge, making it taller will increase the area of the top surface.Because the charge inside the surface isn’t changing, this means that the electric field must be getting weaker so that the flux remains the same.

This is kind of like our sphere problem from before.More tennis rackets means weaker electric field.You could also have figured this out by just looking at how the electric field lines in the drawing get farther apart as you move away from the plane, but who wants to trust a doodle?

So what’s the big deal?Why can’t you let your electric fields get weaker?The real issue is not them getting weaker, but them getting stronger.With the case of the infinite plane, you could get infinitely close to the conducting plane without altering the electric field at all.Now, as you get closer, your relevant Gaussian surface shrinks in size.Because the surface is shrinking, the electric field must be growing the compensate.Take a look at what this does to your equipotential lines.

As you can see, the equipotential lines are packed closer together because the electric field strength is higher, closer to the plane.

Now eventually, with this configuration, you’ll reach some kind of maximum potential when your Gaussian surface crashes into the surface of your conducting plane.What about in the case of an infinitely pointy plane?

No matter how close you zoom in, you can still draw the same gaussian surface that encompasses the same charge.That means that as your tennis racket gets infinitely small, your electric fields must be getting infinitely large!Of course, this doesn’t happen in real life, but it gives you an idea of the trend you can observe when your conductor gets pointier and pointier.

Okay, so we’ve got a lot of equipotential lines crammed together and a lot of electric field. Who cares?

If you remember from before, the strength of the electric field dictates the amount of force experienced by charge placed within that field.If you have a sharply pointed charged conductor, you will have a strong electric field around that conductor. So smooth it out a bit.45 degrees is as sharp as you should get.

Basically, when you boil it down, having a pointy trace will increase the likelihood of your circuit acting strangely.For example, high frequency signals passing over these traces will generate large, rapidly fluctuating electric fields which could cause your circuit to give off some unwanted EM radiation.

Also, pointy traces can also be prime targets for electrostatic discharge as the large electric field will suck charges out of charged bodies that get near them.In fact, a lot of circuit builders will often intentionally place a pointy ground trace and a pointy signal trace very close to each other to draw any ESD on that signal trace (say, if it goes to an external port that the user might touch) safely to ground and away from any sensitive components.

In fact, a lot of people have been using this technique on a larger scale.Lightning rods are usually made to be very pointy so that will literally suck charge out of the sky and direct it safely to the ground out of the way of any sensitive structures or people.

Conclusion

I hope that sums it up for you.I actually had to do a little review from an old textbook to write all of this, so it was definitely a worthwhile refresher.I hope you enjoyed reading it as much as I enjoyed writing!

[via: http://ch00ftech.com]

 

You know, the Jews got 1 day’s worth of oil to last 8 days.That’s what I call engineering!

Background

A very good friend of mine is Jewish, and I thought it would be fun to make her something for the holidays.I’ve had an idea for a while to make a birthday card that sings and lights up printed on a single PCB with the copper as the text as well as the circuit.Somehow, that idea evolved into this project, which is certainly cooler and more practical than a birthday card, and it actually called for some pretty cool design constraints.

Design Constraints

  • It had to look good.Something you might sit on your desk or even use as your ceremonial menorah if your living arrangements have a “no open fires” policy.
  • It must use as few components as possible.This goal sort of evolved into me getting rid of the need for a power switch and interface button by using what I call “poor-man’s cap sense”.It didn’t work super well, but more on that later.
  • It must actually last eight days of operation.This would require some cool tricks to extend the battery life.

The Look

When laying this board out, I had to throw all PCB layout rules out the window.There are a lot of right-angle traces, but given how simple the application is, it’s hardly a problem (still, don’t get into the habit of using right-angle traces!).

The circuit is a single-layer PCB with the battery mounted on the back.The battery enclosure is actually a surface mount part, but by looping some wire through to the back of the board, I was able to provide enough “surface” to solder to.Note that there is no power switch.This means that I had to be careful while building to circuit to take the battery out before making any modifications.

I didn’t want a programming header muddling up my design, so while I was working on the firmware, I made a temporary programming header and soldered it lightly to the relevant lines.

Power is provided by the copper plane surrounding the candles.This helps maintain the illusion that the candles have tips rather than being part of a circuit.Also, I soldered the current-limiting resistors on upside down because I think their white bottom looks more like a candle than their black tops.

The flickering was achieved using PWM with a random value lookup table.There are seven different brightness values (eight if you include “off” which I didn’t), and each byte on the lookup table provides data for two LEDs at a time (I just threw away half of the 5th byte).By making my lookup table non divisible by 5 and looping it, I could greatly extend the time it takes before the pattern repeats, simulating the flickering of a real candle.

Poor Man’s Cap Sense

Some of you probably know a lot about capacitive touch sensing electronics.Everything from the classic iPod click wheel to the touch pad in your laptop use this technology.Capacitive touch sensing technology uses oscillators that charge and discharge a capacitor.When you touch, or get near that capacitor, you alter its capacitance slightly and change the time it takes to charge or discharge.Measuring this frequency can determine whether or not you are touching the device.

Poor Man’s Cap Sense does not do this at all.It does use a capacitor though!

I discovered poor man’s cap sense while I was working on the LED sensor a while back.I noticed that often times, touching the LED had the same effect as shining a bright light at it.This is because the LED was at the time acting like a capacitor, and my finger was acting like a very high impedance resistor (but less high than air).By replacing the LED with a very very small capacitor, I was able to harness this effect.

Here’s the basic rundown of how my implementation worked.

  1. Charge the capacitor using the micro controller.
  2. Disconnect the internal voltage rail from the output pin (i.e. turn it into a high-impedance input).
  3. Read the voltage on the capacitor pin and wait for it to drop (which would mean that a finger has shorted it to ground).

The only flaw with this plan is that the capacitor will discharge on its own given enough time.Usually within 5-10 seconds, the charge leaks out either through the air or through the not-quite-infinite impedance of the micro controller input pin.To cope with this, I treated it just like the LED sensor and timed how long it took to discharge.If it discharged quickly, that would mean that a finger was touching it.If it took something like 5 seconds, that means that it’s discharging freely through air.

Now, my implementation was incredibly simple.I just had two thresholds (determined empirically) that set up a hysteresis for the time readings.Here’s a graphic explaining it.
Every time the capacitor’s voltage reaches the low input voltage for the micro controller (and it therefore reads the pin as being low), it takes a time measurement, charges the cap, and starts the timer again.This time measurement is compared against the threshold values (in green) to determine if anything needs to be done.If the measurement is below the lower threshold, it registers as a touch.The second measurement in this region is ignored.The values must first rise above the upper threshold before a second touch can be registered.This prevents the device from going nuts with repeated touches if you hold your finger down for an extended period of time (where “extended” = more than a few milliseconds).

Now, when this method works, it works beautifully (see video below).The only problem is that it doesn’t work in all conditions.I found that there is a lot that can mess with the measurements and needs to be taken into account.If your fingers are particularly moist, they will leave a residue on the surface of the button that will provide a conduit for the charge and prevent the time measurements from rising above the upper threshold like they might in the presence of a better insulator.Also, after taking a shower, I noticed that the humidity in the room was enough to register a touch.

Long story short, if you plan on making this thing in any sort of serious application, be prepared to spend a lot of time coming up with a clever algorithm that has self-calibrating thresholds that can adapt to different conditions.I didn’t post a video of my algorithm failing, but let’s just say that the success rate is about 75%.I consider this acceptable mostly because it typically misses hits rather than registering false-positives.I expect the user to leave the menorah alone after it is set to the correct day, and I’d rather the user have to touch the pad a few extra times than having it skip ahead in the calendar when unprovoked.

Eight Days of Efficiency

Not having a power switch requires a few neat tricks if you want to make your battery last more than a few days.The cap sense actually helped me achieve this.

AVR micro controllers have a low-power shutdown mode that you can place them into wherein they draw a minimal amount of current (2 microamps) while still holding all of your values in ram.They also have a few options for how to wake them from this state.You can either have them wake on a timer interrupt (if you have an external oscillator) or on a pin change interrupt.I opted for the latter option and made sure to have my capacitor pin tied to INT0.

When my device is “off”, it’s actually sleeping until the capacitor discharges.As I said before, it will discharge in about 5 seconds or so when left alone.At this point, it wakes up, charges the cap, waits a few milliseconds for it to discharge, gives up, tops it off again, then goes back to sleep.The idea is that if the cap takes longer than a few milliseconds to discharge, it’s probably not being touched, and the micro can better spend its time sleeping than waiting for the cap to discharge all the way.

This means that it’s only operating at full power for a few ms out of every 5000 greatly extending the battery life.

As a last note, I did use fairly efficient LEDs (these are the same ones from the low battery indicator of the bullet counter), so I can afford to crank the LED current down pretty low.The current limiting resistors I used were 470 ohm.It also helps that it’s meant to emulate candles, so the LEDs shouldn’t be super bright.

Conclusion

All in all, I’m very satisfied with the final product.I probably spent way more time than I should have trying to think up a better algorithm for handling the cap-sense, but I had to give up due to time constraints (I’m not much of a CS guy anyway).I leave it as a challenge to the reader to come up with a cleverer solution.If I really needed it to work 100% of the time, I would just replace the cap sense with a cheap tactile switch.The code would barely even have to change.

I’ll be packing this thing up soon and mailing it off.I hope she likes it!Happy Hanukkah everyone!

[via: http://ch00ftech.com]

 

/*

AVR ATmega168 Analog Comparator Demonstration

by Mike Szczys

I’m using a voltage divider with a photoresistor on

PC6 and a voltage divider with equal values on PC7

to yield a 2.5V reference signal.

The analog comparator is set to throw an interrupt

whenever there is a zero crossing. I then check the

ACO bit to see if I should turn on LEDs on Port B or

not.

jumptuck.com

*/

#include <avr/io.h>

#include <avr/interrupt.h>

voidinitComparator(void){

cli();

ACSR|=(1<<ACIE);//Enable analog comparator interrupt

sei();

}

voidinitIO(void){

DDRB=0xFF;//PortB as Outputs

PORTB=0xFF;//All outputs high

}

intmain(void){

initIO();//Initialize I/O

initComparator();//Initialize the analog comparator

while(1){}

}

ISR(ANALOG_COMP_vect){

//Check for rising or falling edge

if(ACSR&(1<<ACO))PORTB=0×00;

elsePORTB=0xFF;

}

[via: http://jumptuck.com/]

© 2011 Geko Geek This is a news aggregator website. Articles and images are copyrighted to their original source authors. Gekogeek takes no responsibility about the articles content Suffusion theme by Sayontan Sinha