Thursday, June 30, 2016
LittleArduinoProjects#207 Frequency Counter
Testing a CMOS frequency counter circuit with a 100Hz - 5MHz range.
I found this circuit published in Electronics magazine (Sep 16 1976). It's a classic demonstration of the CD4026 "bucket-brigade" and CD4047 astable oscillator.
The frequency counter is governed by a CD4047 oscillator. Since this offers a clean 50% duty cycle, it is ideal for flipping the circuit between two modes: sampling period; display period.
As always, all notes, schematics and code are in the Little Electronics & Arduino Projects repo on GitHub.
I found this circuit published in Electronics magazine (Sep 16 1976). It's a classic demonstration of the CD4026 "bucket-brigade" and CD4047 astable oscillator.
The frequency counter is governed by a CD4047 oscillator. Since this offers a clean 50% duty cycle, it is ideal for flipping the circuit between two modes: sampling period; display period.
As always, all notes, schematics and code are in the Little Electronics & Arduino Projects repo on GitHub.
(追記) (追記ここまで)
LittleArduinoProjects#206 CD4047 Astable Oscillator
The CD4047 is capable of running in astable or monostable configurations, with operating frequency configured by an external RC network. So in one sense, sounds like the 555 timer!
Unlike the 555, the CD4047 provides a fixed 50% duty cycle with good frequency stability (+/- 2% @ 100KHz).
As always, all notes, schematics and code are in the Little Electronics & Arduino Projects repo on GitHub.
Unlike the 555, the CD4047 provides a fixed 50% duty cycle with good frequency stability (+/- 2% @ 100KHz).
As always, all notes, schematics and code are in the Little Electronics & Arduino Projects repo on GitHub.
(追記) (追記ここまで)
Wednesday, June 29, 2016
LittleArduinoProjects#205 Triac Dimmer
A triac is a "bidirectional thyristor" because it conducts in both directions and is typically used in AC applications.
The basic behaviour of a triac can be summarised in two rules:
The basic behaviour of a triac can be summarised in two rules:
- Rule 1. To turn ON, a gate current ≥ IGT must be applied until the load current is ≥ IL (latching current).
- Rule 2. To turn OFF (commutate), the load current must be < IH (holding current) for long enough for the device to return to the blocking state.
(追記) (追記ここまで)
Sunday, June 26, 2016
LittleArduinoProjects now with fancy catalog!
I keep finding new uses for GitHub Pages - situations where in the past I would otherwise have spun up a web site on heroku or similar. But if the site can be static, and especially if you are already hosting the git repository at GitHub, Pages are perfect.
For a long time, I've maintained the LittleArduinoProjects project index as a simple table in the README. But it wasn't particularly nice or usable, so I decided to pimp it up and serve the catalog index with pages. Turned out to be a piece of cake (with a few scripts to convert the old index to JSON for the catalog page.
So here it is, Little Electronics & Arduino Projects at leap.tardate.com:
As always - and since the gh-pages code lives in the same repo - all notes and code for the catalog are available in the same Little Electronics & Arduino Projects repo on GitHub.
For a long time, I've maintained the LittleArduinoProjects project index as a simple table in the README. But it wasn't particularly nice or usable, so I decided to pimp it up and serve the catalog index with pages. Turned out to be a piece of cake (with a few scripts to convert the old index to JSON for the catalog page.
So here it is, Little Electronics & Arduino Projects at leap.tardate.com:
As always - and since the gh-pages code lives in the same repo - all notes and code for the catalog are available in the same Little Electronics & Arduino Projects repo on GitHub.
Saturday, June 25, 2016
On "random" CI failures
I closed a bug yesterday that's been kicking around for almost a year as a sometimes fails on CI but no-one can figure out why frustration.
Sooner or later you'll hear someone suspect it must be a problem with CI. Which is ironically funny in a shoot-the-messenger kind of way!
Thankfully our "CI issue" turned into a for-real bug. In short, the code involved many classes with near 100% test coverage. It had been read and re-read and everyone would swear there's no way this could fail.
No, of course we were wrong. The bug was basically a conspiracy of two bits of code in two very different places:
And you can see where this leads: our problem was filtered data ending up by obscure and circuitous means in field1 and field2 ... with a 1 in 7 chance of the record validation failing (never happens on our machines of course). After that it was an easy fix.
So once again we learn the lesson:
I've seen this scenario play out a dozen times in as many years, and CI was always right;-) Since it keeps cropping up, it made me think about how to best knock these on the head. Five things:
It's too easy to give up, find scape-goats or "magic" explanations otherwise.
Take heart in the fact that if you assume CI is right, the odds are on your side.
When we first encountered this issue and failed to find the root cause, we added code to catch the "this is about to fail in that unexpected way" situation and log/report appropriately.
So while the ticket got iced, it's been that "canary" that keeps dying in order to keep the issue alive! So when it died again yesterday, it was a painful reminder to get to the bottom of the issue once and for all.
Always found in the last place to look. So when you've honed in on the code you think is failing, studied it upside down, left to right, and still can't find the issue .. maybe it's time to consider you might be right. Throw out that hypothesis, pull back and fan out instead.
If errors happen infrequently, reproducing them is like trying to win the lottery. The more entries, the better your chances.
So don't run tests a few times, run them millions of times if you have to. Computers are good at this. That's how I diagnosed this latest issue while tweaking logging and the test itself. Bash away:
This sounds so simple that it's easy to overlook.
If things fail randomly .. it only takes a few moments to search the code to see if anything is using something similar to a random function.
Could it be possible that random failures and the use of rand() might be related?!
May be not, but if they are, that's a cheap win!
Sooner or later you'll hear someone suspect it must be a problem with CI. Which is ironically funny in a shoot-the-messenger kind of way!
Thankfully our "CI issue" turned into a for-real bug. In short, the code involved many classes with near 100% test coverage. It had been read and re-read and everyone would swear there's no way this could fail.
No, of course we were wrong. The bug was basically a conspiracy of two bits of code in two very different places:
- a record validation that ensured field1 was not the same as field2
- a data collection routine that could be configured to filter/replace sensitive values with a random ** string: ["*" * rand(4..10)]
And you can see where this leads: our problem was filtered data ending up by obscure and circuitous means in field1 and field2 ... with a 1 in 7 chance of the record validation failing (never happens on our machines of course). After that it was an easy fix.
So once again we learn the lesson:
If CI say red but we can't figure out why, "must be a problem with CI" is 99.999% the wrong answer. It just means we haven't found the bug yet.
I've seen this scenario play out a dozen times in as many years, and CI was always right;-) Since it keeps cropping up, it made me think about how to best knock these on the head. Five things:
start by assuming there is a bug until proven otherwise
It's too easy to give up, find scape-goats or "magic" explanations otherwise.
Take heart in the fact that if you assume CI is right, the odds are on your side.
put a canary in a coalmine
When we first encountered this issue and failed to find the root cause, we added code to catch the "this is about to fail in that unexpected way" situation and log/report appropriately.
So while the ticket got iced, it's been that "canary" that keeps dying in order to keep the issue alive! So when it died again yesterday, it was a painful reminder to get to the bottom of the issue once and for all.
finding bugs .. is like looking for your keys
Always found in the last place to look. So when you've honed in on the code you think is failing, studied it upside down, left to right, and still can't find the issue .. maybe it's time to consider you might be right. Throw out that hypothesis, pull back and fan out instead.
treat random errors like a lottery
If errors happen infrequently, reproducing them is like trying to win the lottery. The more entries, the better your chances.
So don't run tests a few times, run them millions of times if you have to. Computers are good at this. That's how I diagnosed this latest issue while tweaking logging and the test itself. Bash away:
for (( ; ; )) ; do rspec spec/that_wierd_spec.rb if [ $? == 1 ] then echo "JACKPOT!" break fi done
random failures ... might really be random
This sounds so simple that it's easy to overlook.
If things fail randomly .. it only takes a few moments to search the code to see if anything is using something similar to a random function.
Could it be possible that random failures and the use of rand() might be related?!
May be not, but if they are, that's a cheap win!
Wednesday, June 15, 2016
LittleArduinoProjects#204 Type K Temperature Logger
I'm working on an idea where I need to measure temperatures to around 500°C - above those typically supported with semiconductor sensors or thermistors.
This project demonstrates the basic approach using an Arduino as the "temperature logger". I'm using a K Type thermocouple that's rated up to 700°C. Since thermocouples only measure a differential temperature, I'm also using an LM35 to provide the cold-junction baseline. The temperature measurement is displayed on a 5110 LCD.
As always, all notes, schematics and code are in the Little Electronics & Arduino Projects repo on GitHub.
This project demonstrates the basic approach using an Arduino as the "temperature logger". I'm using a K Type thermocouple that's rated up to 700°C. Since thermocouples only measure a differential temperature, I'm also using an LM35 to provide the cold-junction baseline. The temperature measurement is displayed on a 5110 LCD.
As always, all notes, schematics and code are in the Little Electronics & Arduino Projects repo on GitHub.
Labels:
Arduino,
Electronics,
LittleArduinoProjects,
Sensors,
Thermocouple
Tuesday, May 31, 2016
阿部真央 Don't let me down
One of the best finds in the racks at Tower Records Fukuoka福岡市. It's been years since I last got to browse a record store in Japan; I'm glad they still exist, with stacks of CD players queued up to sample. And a huge relief to see the indie rock scene is just as vibrant as I remember!
[フレーム]
[フレーム]
Friday, May 20, 2016
LittleArduinoProjects#203 Homopolar Motor
What happens when electric fields cut across magnetic fields? A force is generated, and the homopolor motor is the classic demonstration.
As always, all notes, schematics and code are in the Little Electronics & Arduino Projects repo on GitHub.
[フレーム]
As always, all notes, schematics and code are in the Little Electronics & Arduino Projects repo on GitHub.
[フレーム]
Wednesday, May 18, 2016
LittleArduinoProjects#202 LM3915 Audio Level Kit
The LM3915 is a useful IC for simple audio level displays. This is a cheap kit build which largely follows the reference circuits in the datasheet.
As always, all notes, schematics and code are in the Little Electronics & Arduino Projects repo on GitHub.
As always, all notes, schematics and code are in the Little Electronics & Arduino Projects repo on GitHub.
Monday, May 02, 2016
LittleCodingKata: Hardware Excuse Generator with gRPC
gRPC is a very interesting lightweight middleware framework for language-neutral, cross-platform RPC.
When I heard about Natalie Silvanovich's Hardware Excuse Generator on Embedded.fm, I immediately recognised a better "Hello World" for testing out gRPC.
Introducing "The Explainer": my programming exercise to learn basic cross-language request/reply with gRPC.
I haven't completed the whole matrix of client-server possibilities yet, but here's a sampling...
Start up a server (e.g ruby version)
And then ask it questions. Pick a language!
All my notes and code are available in the LittleCodingKata GitHub repository.
When I heard about Natalie Silvanovich's Hardware Excuse Generator on Embedded.fm, I immediately recognised a better "Hello World" for testing out gRPC.
Introducing "The Explainer": my programming exercise to learn basic cross-language request/reply with gRPC.
I haven't completed the whole matrix of client-server possibilities yet, but here's a sampling...
Start up a server (e.g ruby version)
$ ./explainer.rb ShiFu is waiting to explain all of your problems...
And then ask it questions. Pick a language!
# Ruby client $ ./explain.rb "Your phone is crashing because of REASON" Your phone is crashing because of the PCB not being manufactured to specification # C# client $ mono bin/Release/explain.exe "Your phone is crashing because of REASON" Your phone is probably crashing because of stray harmonics # C++ client $ ./explain "Your phone is crashing because of REASON" Your phone is crashing because of impedance in the coil # node.js client $ node ./explain.js "Your phone is crashing because of REASON" Your phone is crashing because of a lack of shielding against alpha radiation (cosmic rays) in antenna # Python client $ python explain.py "Your phone is crashing because of REASON" Your phone is crashing because of residual capacitance caused by the USB connector
All my notes and code are available in the LittleCodingKata GitHub repository.
Saturday, April 16, 2016
Embedded: Specialization is for insects
embedded.fm has fast become my favourite podcast of the moment (always excepting QOTD). Great ideas shared in an inclusive and warm-fuzzy way.
Elecia's end-of-show quote always makes it worth listening right to the end. Until I heard #146's,
I'd struggled to find words to express exactly this. It's a quote from Robert A. Heinlein:
Elecia's end-of-show quote always makes it worth listening right to the end. Until I heard #146's,
I'd struggled to find words to express exactly this. It's a quote from Robert A. Heinlein:
A human being should be able to change a diaper, plan an invasion, butcher a hog, conn a ship, design a building, write a sonnet, balance accounts, build a wall, set a bone, comfort the dying, take orders, give orders, cooperate, act alone, solve equations, analyze a new problem, pitch manure, program a computer, cook a tasty meal, fight efficiently, die gallantly. Specialization is for insects.
LittleArduinoProjects#201 Yet Another Doorbell
aka door-fart according to my better half ... 555 Timer-based oscillators are not exactly the most musical creatures.
#201 is a kit build. Ridiculously cheap on aliexpress, it even came with extra components, so a bit of a bargain impulse-buy.
The kit turned out to be a simplified version of a circuit I've built before. It lacks the power control circuit, and draws about 4mA when idle - so if you actually use it, expect to be replacing batteries on a regular basis.
As always, all notes, schematics and code are in the Little Arduino Projects repo on GitHub.
Here's the start of the "ding.." on a 'scope..
#201 is a kit build. Ridiculously cheap on aliexpress, it even came with extra components, so a bit of a bargain impulse-buy.
The kit turned out to be a simplified version of a circuit I've built before. It lacks the power control circuit, and draws about 4mA when idle - so if you actually use it, expect to be replacing batteries on a regular basis.
As always, all notes, schematics and code are in the Little Arduino Projects repo on GitHub.
Here's the start of the "ding.." on a 'scope..
Tuesday, April 05, 2016
LittleArduinoProjects#200 Mini Solenoid Engine
Solenoid engines? They definitely fall into the the category of because you can.
Some people take it to a whole other level (like this V8 model).
What I have here is much more modest - a single-cylinder engine powering an impromptu-wire-art drive train. The mini-solenoid used here has a very small effective stroke - about 8mm - which necessarily constrains the gearing. I was inspired by 30GB's similar model for the layout.
As always, all notes, schematics and code are in the Little Arduino Projects repo on GitHub.
[フレーム]
Some people take it to a whole other level (like this V8 model).
What I have here is much more modest - a single-cylinder engine powering an impromptu-wire-art drive train. The mini-solenoid used here has a very small effective stroke - about 8mm - which necessarily constrains the gearing. I was inspired by 30GB's similar model for the layout.
As always, all notes, schematics and code are in the Little Arduino Projects repo on GitHub.
[フレーム]
Monday, April 04, 2016
LittleArduinoProjects#199 CD4026 Bucket-brigade LED driver
This is an extension if the ideas in #196, demonstrating how it's possible to build a "bucket-brigade" of CD4026 chips to drive an arbitrary number of 7-segment LEDs with a single data line.
It just requires the carry-out from the first CD4026 to be chained as the clock input for the second and so on.
As always, all notes, schematics and code are in the Little Arduino Projects repo on GitHub.
It just requires the carry-out from the first CD4026 to be chained as the clock input for the second and so on.
As always, all notes, schematics and code are in the Little Arduino Projects repo on GitHub.
Sunday, April 03, 2016
LittleArduinoProjects#198 Hall Effect Switch
Hall-effect sensors generally support one of three modes:
The chip is rated for continuous output current of 25mA, so that is sufficient to drive an LED (as demonstrated here). For other switching applications, the output can be used to switch a transistor or pull a microcontroller output low.
Testing with some neodymium magnets, I get a strong full-on when the south pole of the magnets are within 23mm directly to the front of the chip. The output remains on until I pull back to over 40mm.
A common use for Hall-effect sensors is to detect and measure rotation. A good demonstration of this is to sequence a PoV display as demonstrated in Great Scott's latest video - HACKED!: Old Fan becomes a POV Display
As always, all notes, schematics and code are in the Little Arduino Projects repo on GitHub.
- switch - turn on in the presence of a magnetic field of a specified polarity
- latch - turn on in the presence of a magnetic field, and stay on until exposed to the reverse polarity
- linear sensor - output is proportional to the magnetic field strength
The chip is rated for continuous output current of 25mA, so that is sufficient to drive an LED (as demonstrated here). For other switching applications, the output can be used to switch a transistor or pull a microcontroller output low.
Testing with some neodymium magnets, I get a strong full-on when the south pole of the magnets are within 23mm directly to the front of the chip. The output remains on until I pull back to over 40mm.
A common use for Hall-effect sensors is to detect and measure rotation. A good demonstration of this is to sequence a PoV display as demonstrated in Great Scott's latest video - HACKED!: Old Fan becomes a POV Display
As always, all notes, schematics and code are in the Little Arduino Projects repo on GitHub.
Tuesday, March 22, 2016
LittleArduinoProjects#197 Wien Bridge Audio Tone Generator
A Wien bridge oscillator is essentially an RC Band Pass Filter with a high Q factor at the resonant frequency, and generates a nice sine wave. I wanted a simple audio-frequency test signal generator, and a Wien Bridge turned out to be perfect for the job.
As always, all notes, schematics and code are in the Little Arduino Projects repo on GitHub.
A good old LM324 does triple duty in the circuit:
The result is a pretty decent sine wave at ~1.574kHz, very close to the theoretical resonant frequency of 1.592kHz.
As always, all notes, schematics and code are in the Little Arduino Projects repo on GitHub.
A good old LM324 does triple duty in the circuit:
- a non-inverting amplifier with a gain of ~3 provides the feedback required to sustain the oscillator
- one unit buffers a half-supply voltage to provide a "virtual ground" for the non-inverting amplifier
- a third unit buffers the output signal to avoid load interference with the oscillator
The result is a pretty decent sine wave at ~1.574kHz, very close to the theoretical resonant frequency of 1.592kHz.
Sunday, March 20, 2016
LittleArduinoProjects#196 Driving a 7-segment display with CD4026 Counter
Here's yet another way to drive a 7-segment single-digit display unit - using a CD4026.
The CD4026 is a 5-stage Johnson decade counter with decoded 7-segment display outputs and display enable. With RESET and CLOCK INHIBIT low, and DISPLAY ENABLE IN high, the 7-segment display outputs progress through the 0-9 sequence on the rising edge of the CLOCK pulse.
It's an interesting alternative to a shift register for driving a 7-segment LED (as in the ShiftDrive project). While a latched shift register provides random addressing and clean transitions to any digit, it requires the 7-segment display outputs to be decoded externally (like in code). On the other hand, the CD4026 takes care of the decoding, and external circuits just need to send a counter pulse.
As always, all notes, schematics and code are in the Little Arduino Projects repo on GitHub.
The CD4026 is a 5-stage Johnson decade counter with decoded 7-segment display outputs and display enable. With RESET and CLOCK INHIBIT low, and DISPLAY ENABLE IN high, the 7-segment display outputs progress through the 0-9 sequence on the rising edge of the CLOCK pulse.
It's an interesting alternative to a shift register for driving a 7-segment LED (as in the ShiftDrive project). While a latched shift register provides random addressing and clean transitions to any digit, it requires the 7-segment display outputs to be decoded externally (like in code). On the other hand, the CD4026 takes care of the decoding, and external circuits just need to send a counter pulse.
As always, all notes, schematics and code are in the Little Arduino Projects repo on GitHub.
Thursday, March 10, 2016
LittleArduinoProjects#195 Coil Resonance and Inductor Testing
I've been trying to do some RF experiments, but instead being driven mad by hand-wound coils that never seem to behave as the standard coil inductance calculations would lead us to believe.
As always, it's w2aew to the rescue with a neat deconstruction and demo of a circuit for coil or inductor measurement.
I built the circuit out, and was easily measuring down to 10μH on a breadboard, and sub-1μH once I put the circuit on a hacked up copper board with islands. Using the LC circuit resonant frequency formula, it's possible to work backwards from known frequency and capacitance to determine the inductance (wolframalpha is great for this).
So now I hope to get back into some RF without the nagging doubt of not really knowing what my coils are doing!
As always, all notes, schematics and code are in the Little Arduino Projects repo on GitHub.
Here's a beautiful trace of a (nominally) 10μH choke with a 150pF capacitor. I measure the frequency at 4.26MHz, therefore an actual inductance of 9.3μH .. pretty close!
Even with a super-bodgy 4.5 turn coil whipped up on the spot and put in parallel with a 30pF capacitor, I'm still getting a decent oscillation at 34.09MHz for a calculated inductance of 0.73μH
And here's the board delivering the results:
As always, it's w2aew to the rescue with a neat deconstruction and demo of a circuit for coil or inductor measurement.
I built the circuit out, and was easily measuring down to 10μH on a breadboard, and sub-1μH once I put the circuit on a hacked up copper board with islands. Using the LC circuit resonant frequency formula, it's possible to work backwards from known frequency and capacitance to determine the inductance (wolframalpha is great for this).
So now I hope to get back into some RF without the nagging doubt of not really knowing what my coils are doing!
As always, all notes, schematics and code are in the Little Arduino Projects repo on GitHub.
Here's a beautiful trace of a (nominally) 10μH choke with a 150pF capacitor. I measure the frequency at 4.26MHz, therefore an actual inductance of 9.3μH .. pretty close!
Even with a super-bodgy 4.5 turn coil whipped up on the spot and put in parallel with a 30pF capacitor, I'm still getting a decent oscillation at 34.09MHz for a calculated inductance of 0.73μH
And here's the board delivering the results:
Tuesday, March 08, 2016
LittleArduinoProjects#194 DIY ESP8266 DevBoard
With the funding of the MicroPython on the ESP8266 campaign, my interest in the ESP8266 is rekindled!
I have an ESP-01 module lying around, but I'm a bit tired of wiring it up a breadboard again. So here is a little "devboard" I whipped up on a 4x6cm protoboard and hot-glued to a business card holder.
Now it's plug'n'play - add power and plug in a USB serial adapter and I'm good to go.
As always, all notes, schematics and code are in the Little Arduino Projects repo on GitHub.
I have an ESP-01 module lying around, but I'm a bit tired of wiring it up a breadboard again. So here is a little "devboard" I whipped up on a 4x6cm protoboard and hot-glued to a business card holder.
Now it's plug'n'play - add power and plug in a USB serial adapter and I'm good to go.
As always, all notes, schematics and code are in the Little Arduino Projects repo on GitHub.
Thursday, March 03, 2016
LittleArduinoProjects#193 PoV LED Shake Stick
This AT89S52-based "shake stick" kit pops up all over the place for a few dollars. I built it and hey, it works great!
But it's not packaged to be easily re-programmed for other messages or graphics. So started my sleuthing.. which turned into a fascinating story.
It seems the kit was originally designed and built as a uni project by Zheng Zhong Xing 兴向荣 (aka zhengzhongxing39) studying Control Technology and Instruments/Principles and Applications at a Chinese University. Reportedly "... soldering was troublesome, with lots of changes and no solid basic skills, so burned out the first board" ;-) But it seems persistence paid off, and ended up commercialising the kit and starting electronics business and taobao store where you can find this kit and many others.
As always, all notes, schematics and code are in the Little Arduino Projects repo on GitHub, including my annotation of the source code and schematic for the shake stick.
But it's not packaged to be easily re-programmed for other messages or graphics. So started my sleuthing.. which turned into a fascinating story.
It seems the kit was originally designed and built as a uni project by Zheng Zhong Xing 兴向荣 (aka zhengzhongxing39) studying Control Technology and Instruments/Principles and Applications at a Chinese University. Reportedly "... soldering was troublesome, with lots of changes and no solid basic skills, so burned out the first board" ;-) But it seems persistence paid off, and ended up commercialising the kit and starting electronics business and taobao store where you can find this kit and many others.
As always, all notes, schematics and code are in the Little Arduino Projects repo on GitHub, including my annotation of the source code and schematic for the shake stick.
Subscribe to:
Comments (Atom)