Author Archives: admin

Arduino driving a latching relay

I bought some AXICOM latching relays on Ebay for cheap.  They are 3V relays.  Latching relays are nice because there is no holding current required to keep in one state or the other.  All you have to do is drive them differentially and pulse them +/- to put it in one state and then pulse it -/+ to put it in the other state.

To use these with an Arduino Uno whose outputs I/O are 5 volt, level translation is required.  There are chips that do level translation but when I wanted to set one of these up, I did not have any level-translator ICs in my lab.  I have plenty of bipolar transistors, however.  Using 2n3904 and 2n3906 transistors, I constructed this simple circuit.  I derive the 3.3V power from the Arduino Uno board.

Latching relay driver

Arduino Light follower

This is a simple light follower application using two CDS photocells.  I included a calibration feature to account for the difference between the photocells and the resistors.  Photocells are mounted as shown using hot glue.  The servo is the standard one that comes with the Sparkfun Arduino inventors kit.
 top view side view
/* Sweep
by BARRAGAN <http://barraganstudio.com>
This example code is in the public domain.modified 8 Nov 2013
by Scott Fitzgerald
http://www.arduino.cc/en/Tutorial/Sweep
This coded modified by Wimberleytech LLC and placed into the public domain 31 May 2016
*/
#include <Servo.h>Servo myservo;  // create servo object to control a servo
// twelve servo objects can be created on most boardsint pos = 90;    // variable to store the servo position
int sensorPin0 = A0;    // input from first photosensor
int sensorPin1 = A1;    // input from second photosensor
const int buttonPin = 2;     // the number of the pushbutton pin
int valPin0 = 0;  // variable to store the value coming from the sensor Pin0
int valPin1 = 0;  // variable to store the value coming from the sensor Pin1
int offset = 100;
int buttonState = 1;
int hysteresis = 5;

void setup() {
myservo.attach(9);  // attaches the servo on pin 9 to the servo object
pinMode(buttonPin, INPUT_PULLUP);
Serial.begin(9600);
}

void loop() {
Serial.println(“start loop”);
buttonState = digitalRead(buttonPin);
while(buttonState == LOW)
{
valPin0 = analogRead(sensorPin0);
valPin1 = analogRead(sensorPin1);
if(valPin1 > valPin0)
{
offset = valPin1 – valPin0;  // want to subtract offset from Pin1
}
else if(valPin1 < valPin0)
{
offset = valPin1 – valPin0;  // want to add offset to Pin1
}
Serial.print(“Calibrate: “);
Serial.print(offset);
Serial.println(“buttonState”);
buttonState = digitalRead(buttonPin);
delay(1000);
}

if (analogRead(sensorPin0) < analogRead(sensorPin1)-offset-hysteresis)
{
Serial.println(analogRead(sensorPin0));
Serial.println(analogRead(sensorPin1));
pos +=1;
myservo.write(pos);              // tell servo to go to position in variable ‘pos’
if(pos > 160)
{
pos = 160;
}
delay(50);
}
else if (analogRead(sensorPin0) > analogRead(sensorPin1)-offset+hysteresis)
{
pos-=1;;
myservo.write(pos);              // tell servo to go to position in variable ‘-pos’
if(pos < 10)
{
pos = 10;
}
delay(50);
}

}

BluetoothLE Temperature Sensor

This system measures temperature and sends the measurement to an Android phone via Bluetooth Low Energy (BTLE).  The microcontroller is a Silicon Labs C8051F931, the Bluetooth breakout board is a Nordic nrf8001, and the temperature sensor breakout board is a TI TMP102.

The micro talks to the nrf8001 using SPI and to the TMP102 using I2C.  The system was debugged using Saleae Logic 8 Analyzer.

The microcontroller code was ported from the Adafruit Bluefruit project which was authored by Kevin Townsend and running on an Arduino Uno.  KT did a great job.  Porting the code from the Arduino to the Silabs 8051 was a nightmare but I made it work.  Hey!  I am an analog guy mostly, so give me a break!

I am using UART Services for this project, so I was able to test the interface using Nordic’s NRF UART app on the Android.  Later, I had my son take the Nordic code and modify it to interface with the temp sensor.

The C8051F931 is implemented here on one of the Silabs Toolstick target boards.  Power can be provided external to the board or use an on-board LR44 battery that is boosted up using a SMPS boost converter built into the F931.  To make things simple for this demo, I used a separate 2032 coin cell to power the radio and the temp sensor.

FFT of a Sampled Sine Wave (Revisited)

Excel is nice…but…

A better solution comes from the open-source tool Octave.  Here is the simple code to generate a sampled sine wave and perform an FFT.

myfile = fopen (“dat.txt”, “w”);
fprintf(myfile,”%f  %f\n”,0.0,0.0);
Samples = 1024;
OSR = 16;
length = 0;
z=0; v=0; vlp=0; zlp=0;
delt= 1; # delta time for RC calcultion
c=20; # capacitor for RC filter
r=1;  # resistor for RC filter
steps = Samples/OSR;
for i= 1:Samples+length
arg(i) = i – mod(i,steps);
arg(i) = 2*pi*arg(i)/Samples;
v(i) = sin(arg(i));
# smoothing function using digital averaging filter
#vlp(i)=0.0;
#if(i>length)
# for j=i-length:i
# vlp(i)=vlp(i)+v(j);
# endfor
# vlp(i) = vlp(i)/(length+1);
# endif
# end of smoothing filter
#RC filter function (Euler integration)
if(i>1)
ir(i)=(v(i)-vlp(i-1))/r;
vlp(i)=(delt*ir(i))/c + vlp(i-1);
endif
#end of RC filter function
# generate PWL data
if(mod(i,steps)==0)  #generates an output file for excel as needed
fprintf(myfile,”%fu  %f\n”,i-1,v(i-1));
fprintf(myfile,”%fu  %f\n”,i,v(i));
endif
endfor
plot(v);
pause(2)
plot(vlp);
pause(2)
y = fft(v);
z = 2*abs(y)/Samples;  #magnitude calculation
plot(z);
axis([0 100]);
pause(2)
ylp = fft(vlp);
zlp = 2*abs(ylp)/Samples;  #magnitude calculation
pause(2)
plot(zlp);
axis([0 100]);
fclose(myfile);

Picking a lock

I found this lock recently.  Had no idea what combination I had set, so I decided to figure out how to “unlock” the secret code!  It turned out to be quite easy.

20160220_164803-1

All you need is a good magnifying glass and enough light to illuminate the slot between the dials.

2016-02-20 16_56_26-lock.vsd - Microsoft Visio

FFT of a Sampled Sine Wave

I needed some graphics illustrating the frequency spurs of the output of a DAC when converting a sine wave.  The calculations of the spur frequencies is a function of the oversampling of the sinusoid and is trivial.  But, I needed graphics.  I thought about just drawing them in MSVisio but then decided that it would be fun to let Excel do the work for me.

So, I wrote a Visual Basic routine in Excel that first generated a sampled-data sinusoid, then calculated the FFT of that waveform and plots both the waveform and the FFT.  The parametric inputs for the calculations are the number of data points (must be power of 2), and the over sample ratio.  Again pretty simple stuff.

Here is an example output of a sampled sinusoid:

SampleSine

Here is the FFT output:

SampleFFT

Here is the VB code to do this:

Sub FFTDAC()
Application.Calculation = xlCalculationAutomatic
Application.EnableEvents = True
Columns(“C:C”).Select
Selection.ClearContents
Pi = 3.1415926
Range(“H1”).Offset(0, 0).Select
samples = Selection.Offset(0, 0).Value
OSR = Selection.Offset(1, 0).Value
inc = samples / OSR
Range(“A1”).Offset(0, 0).Select
For i = 1 To samples
arg = i – i Mod inc
arg = arg * 2 * Pi / samples
Value = Sin(arg)
Selection.Offset(0, 0).Value = Value
Selection.Offset(1, 0).Select
Next i
Range(“D1”).Offset(0, 0).Select
For i = 1 To samples
cellname = “C” & i
fcn = “=ImAbs(” + cellname + “)”
Selection.Offset(0, 0).Value = fcn
Selection.Offset(1, 0).Select
Next i

Application.Run “ATPVBAEN.XLAM!Fourier”, ActiveSheet.Range(“$A$1:$A$128”), _
ActiveSheet.Range(“$C$1”), False, False
End Sub

In order for this macro to work, you have to install/enable the Analysis ToolPak and Analysis ToolPak VBA

VBA setup

 

Hack of an iRig Pre XLR preamp with phantom power

Recently I wanted to do some recording onto a camcorder using a high-end microphone.  The camcorder had an line-in 3.5mm jack so I needed to get from the microphone having the XLR connector requiring phantom power to the 3.5mm female connector at the proper signal levels.  I tried using my Tascam 8-channel digital studio (mic in, headphone out to the camera).  Never could make it work and my patience was such that I opted for a different solution with a mic of lesser quality.  I made the recording and am happy enough for now.

Now I have purchased a new camcorder and it is on its way. I am determined to figure out how to solve the XLR problem.  As it happens, I have owned this little iRig Pre Mic converter/preamp.  It was designed to interface with Apple devices using a TSSR 3.5mm jack.  Never was happy with the performance on the Apple device, so it has been collecting dust.  So, I decided to see if there was some kind of mod I could do on it to make it useful for my intended purpose.

Thankfully, most of the work has been done for me.  I found some videos describing how to hack the 3.5mm cable so that it forces the preamp to operate and drive out to the headphone jack.  In the video hack, the guidance is to cut the cable and solder certain wires together and leave others untouched.  I really did not want to destroy the cable.  I preferred the idea of doing temporary shorts on the male TSSR jack.  To do this, I needed to figure out which wires went where.  Ohm meter to the rescue.  Here is what I resolved.

2016-01-05 14_29_37-iRig Pre Hack.pdf - Foxit ReaderSince I wanted to preserve the jack, I did not solder to it.  First I took some shrink tubing and covered the Green ring so that it is not exposed.  Then, I tightly wrapped a wire around the remaining exposed rings, spanning the length of the jack.  Then covered it with larger shrink tubing and voila!

I have since ordered two TSSR extensions.  I will cut one and short the appropriate wires.  When I want to use the hacked iRig, I just plug in the hacked extension.  Otherwise, the iRig is in default factory condition.

Wrap it up…

A long time ago, IC designers would breadboard their designs prior to committing to the fab.  This worked pretty well for small logic designs because MSI Logic was readily available (74xx series dominated) and the number of gates were generally manageable.  We used panels of wire-wrap sockets for the designs and they were wired using wire-wrap.  Wire-wrap was a 30-gauge wire with a thin Teflon coating.  When wrapped tightly on a square gold-plated pin, the sharp edges of the pin cut through the Teflon coating, making a connection.

Noting is perfect.  Sometimes the wrap was not tight enough to make a secure electrical contact.  Sometimes, a connection was simply missed.  Rather than installing the chips and troubleshooting with oscilloscopes and logic analyzers, the breadboard was first tested for continuity…every connection on the schematic was verified.  This was a tedious process.

A common tool for this job was a “buzz box” or continuity checker, as it were.  Rather than register a visual reading, an audible “buzz” indicated a good connection.

I had the idea for a “buzz box” back in 1981.  The idea was motivated by several things.  First, I did not want to have a power switch because invariably, the thing would be left on and the battery run down.  Second, I wanted the ability to buzz out circuits where chips were installed.  These were two interesting challenges.

The idea I am presenting here came to me one morning as I awoke–I had been pondering this day and night.  I immediately sketched out the idea on a piece of paper and when I got to the office, I set about proving the concept.  It worked…it was beautiful.  I thought it to be so clever that I submitted it to a publication “Electronics” for an article in their “Designer’s Notebook” section.  Sure enough the article was accepted and I got $50 for my trouble.

Here it is scanned from Nov 13, 1981 edition of Electronics.

Continuity Tester_schematic

Time flies like an arrow…

I was cleaning out my files last week and ran across this.  It is a kitchen timer I made for my mom a long time ago…I am guessing early 80s.  The thing that made me laugh was not the diode logic but that I labeled it “Timer for Mother.”  Why did I say “Mother” instead of “Mom?”  I call her “Mom” now and it feels like I have all ways called her that.  She is 97 and still mentally sharp.  She does not cook any longer so does not need the timer…I still have it though.

Kitchen Timer

Found when I wasn’t looking…

One of the things I do is read patents.  Few inventions jump out at me but now and then one leaps from the page.  Here is one that really caught my eye.  It is a circuit that performs a common function but in a different way.  I will let you figure it out!

2015-03-19 08_21_03-Current Mirror.vsd - Microsoft VisioIgnore body effect!