The personal website of Scott W Harden
December 6th, 2012

Single Wavelength Pulse Oximeter

⚠️ Check out my newer ECG designs:

I want to create a microcontroller application which will utilize information obtained from a home-brew pulse oximeter. Everybody and their cousin seems to have their own slant how to make DIY pulse detectors, but I might as well share my experience. Traditionally, pulse oximeters calculate blood oxygen saturation by comparing absorbance of blood to different wavelengths of light. In the graph below (from Dildy et al., 1996 that deoxygenated blood (dark line) absorbs light differently than oxygenated blood (thin line), especially at 660nm (red) and 920nm (infrared). Therefore, the ratio of the difference of absorption at 660nm vs 920nm is an indication of blood oxygenation. Fancy (or at least well-designed) pulse oximeters continuously look at the ratio of these two wavelengths. Analog devices has a nice pulse oximeter design using an ADuC7024 microconverter. A more hackerish version was made and described on this non-english forum. A fail-at-the-end page of a simpler project is also shown here, but not well documented IMO.

That's not how mine works. I only use a single illumination source (~660nm) and watch it change with respect to time. Variability is due to a recombination effect of blood volume changes and blood oxygen saturation changes as blood pulses through my finger. Although it's not quite as good, it's a bit simpler, and it definitely works. Embedded-lab has a similar project but the output is only a pulsing LED (not what I want) and a voltage output that only varies by a few mV (not what I want).

Here's what the device looks like assembled in a breadboard:

I made a sensor by drilling appropriately-sized holes in a clothespin for the emitter (LED) and sensor (phototransistor). I had to bend the metal spring to make it more comfortable to wear. Light pressure is better than firm pressure, not only because it doesn't hurt as much, but because a firm pinch restricts blood flow considerably.

An obvious next step is microcontroller + LCD (or computer) digitization, but for now all you can do is check it out on my old-school analog oscilloscope. Vertical squares represent 1V (nice!). You can see the pulse provides a solid 2V spike.

Here's some video of it in action:

I'm holding-back the circuit diagram until I work through it a little more. I don't want to mislead people by having them re-create ill-conceived ideas on how to create analog amplifiers. I'll post more as I develop it.

Markdown source code last modified on January 18th, 2021
---
title: Single Wavelength Pulse Oximeter
date: 2012-12-06 08:13:41
tags: circuit, diyECG, old
---

# Single Wavelength Pulse Oximeter

> **⚠️ Check out my newer ECG designs:** 
* [**Sound Card ECG with AD8232**](https://swharden.com/blog/2019-03-15-sound-card-ecg-with-ad8232/)
* [**Single op-amp ECG**](https://swharden.com/blog/2016-08-08-diy-ecg-with-1-op-amp/)

__I want to create a microcontroller application__ which will utilize information obtained from a home-brew pulse oximeter. Everybody and their cousin seems to have their own slant how to make DIY pulse detectors, but I might as well share my experience. Traditionally, pulse oximeters calculate blood oxygen saturation by comparing absorbance of blood to different wavelengths of light. In the graph below (from [Dildy et al., 1996](http://www.ncbi.nlm.nih.gov/pubmed/8694032) that deoxygenated blood (dark line) absorbs light differently than oxygenated blood (thin line), especially at 660nm (red) and 920nm (infrared). Therefore, the ratio of the difference of absorption at 660nm vs 920nm is an indication of blood oxygenation. Fancy (or at least well-designed) pulse oximeters continuously look at the ratio of these two wavelengths. Analog devices has a [nice pulse oximeter design using an ADuC7024 microconverter](http://www.analog.com/library/analogDialogue/archives/41-01/pulse_oximeter.html). A more hackerish version was made and described [on this non-english forum](http://www.elektroda.pl/rtvforum/viewtopic.php?p=8025042). A fail-at-the-end page of a simpler project is also shown [here](http://blog.energymicro.com/2012/11/21/create-a-simple-pulse-oximeter-with-tiny-gecko/), but not well documented IMO.

<div class="text-center">

![](pulse-oximeter-wavelength.jpg)

</div>

That's not how mine works. I only use a single illumination source (~660nm) and watch it change with respect to time. Variability is due to a recombination effect of blood volume changes and blood oxygen saturation changes as blood pulses through my finger. Although it's not quite as good, it's a bit simpler, and it definitely works. [Embedded-lab has a similar project](http://embedded-lab.com/blog/?p=5508) but the output is only a pulsing LED (not what I want) and a voltage output that only varies by a few mV (not what I want).

__Here's what the device looks like assembled in a breadboard:__


<div class="text-center img-border img-medium">

[![](IMG_5919_thumb.jpg)](IMG_5919.jpg)

</div>

__I made a sensor__ by drilling appropriately-sized holes in a clothespin for the emitter (LED) and sensor (phototransistor). I had to bend the metal spring to make it more comfortable to wear. Light pressure is better than firm pressure, not only because it doesn't hurt as much, but because a firm pinch restricts blood flow considerably.

<div class="text-center img-border img-small">

[![](IMG_5920_thumb.jpg)](IMG_5920.jpg)
[![](IMG_5924_thumb.jpg)](IMG_5924.jpg)

</div>

__An obvious next step__ is microcontroller + LCD (or computer) digitization, but for now all you can do is check it out on my old-school analog oscilloscope. Vertical squares represent 1V (nice!). You can see the pulse provides a solid 2V spike.

<div class="text-center img-border img-medium">

![](pulse-scope.jpg)

</div>

__Here's some video of it in action:__

![](https://www.youtube.com/embed/MwkR_Vv0wMA)

I'm holding-back the circuit diagram until I work through it a little more. I don't want to mislead people by having them re-create ill-conceived ideas on how to create analog amplifiers. I'll post more as I develop it.
August 18th, 2012

Geek Spin - ATTiny44 Project Prototype

Some days you feel like working on projects to benefit humanity. The day I made this clearly wasn't one of those days. A little over a year ago, I got into a troll war with my friend Mike Seese. The joke, similar to that of rick rolling, was to get each other to unexpectedly click a link to the Hatsune Miku version of the leekspin song. After several weeks of becoming beyond annoying, I decided to make an actual Hatsune Miku which would spin her leek and bobble her head to the techno version of the Levan Polka for his birthday.

The goal was to create a minature Miku which would perform perfectly in sync with audio coming from a portable music player (iPod or something) and NOT require a computer connection. I accomplished it by sending some creative control beeps out of the left channel of the stereo signal. Although I didn't finish the project, I got pretty far with the prototype, so I decided to dig it out of the archives and share it with the world because it's pretty entertaining!

(look how close I came to replicating the original:

How did I do it? First off, I used servos. If you're not familiar with them, I suggest you look up how servos work. Perhaps check out how to control servos with AVR microcontrollers. Basically, their position along a rotational axis is determined by the width of a pulse on a 20ms time window. Anyhow, if I only had 1 servo to control (i.e., leek only), I'd have controlled the servo directly with PWM signals in the left channel - no microcontroller needed, easy as pie, problem solved. However, since I needed to control two servos, I had to come up with something a bit more creative. Although I could have probably done this ten different ways, the way I chose to do it was using a series of pre-encoded leek spin and head bobble motions, triggered by control beeps in the left channel of the audio cable. (The right channel was patched through to the speakers.) Below is a diagram of what I believe I did, although I didn't thoroughly document it at the time, so you might have to use your imagination if you decide to re-create this project.

The idea is that by sending bursts of sine waves, the circuit can rectify them and smooth them out to have them look to a microcontroller like a brief "high" signal. Each signal would tell the microcontroller to proceed to the next pre-programmed (and carefully timed) routine. With enough practice listening, watching, and tweaking the code, I was able to make a final version which worked pretty darn well!

LISTEN to the music with control beeps (it's a surprisingly fun listen)

A few technical details are that I used an ATTiny44a microcontroller (it may have been an ATTiny2313, I can't remember for sure, but they're so similar it's virtually negligable). The servos I used were cheap (maybe $4?) from eBay. They looked like the one pictured below. The servo position was controlled by PWM, but I manually sent the pulses and didn't actually use the integrated PWM in the microcontroller. I can't remember why I did it this way - perhaps because it was so simple to use the _delay_us() and _delay_ms() functions? I also used an operational amplifier (if I remember, it was a LM741) to boost the left channel control signals rather than rectifying/assessing the left channel directly.

This is the video which I mimiced to create my prototype (note how the leek in her arm and her head move exactly the same as the prototype I made - score!)

And how did I find out about this song? I actually saw it on the video below which was hosted on wimp.com. I thought the song was catchy, looked it up, and the rest was history. It's worth noting that (perhaps to avoid copyright issues?) the key was shifted two half-steps up. I get a kick out of the way the girl waves her arm in the beginning, mimicking the leek :)

Here are some of the images I made which I printed, glued to foam board, and cut out with a razor blade. I'm not sure how useful they are, but they're provided just in case.

... but sometimes Japan takes it a bit too far and things get awkward ...

Below is the code I used. Note that PWM that controls the servos isn't the integrated PWM, but rather a couple pins I manually pulse on and off to control the arm and head positions. Also notice how, in the main routine, I wait for the control beeps before continuing the next sequences.


// leek spin code - designed for ATTiny
// by Scott Harden, www.SWHarden.com

#include <avr/io.h>
#include <avr/delay.h>

void go_high(){
    // sets the arm to the highest position
    for (char i=0;i<5;i++){
        PORTA|=(1<<PA0);
        _delay_us(1400);
        PORTA&=~(1<<PA0);
        _delay_us(20000-1200);
        }
    }

void go_low(){
    // sets the leek to the middle position
    for (char i=0;i<5;i++){
        PORTA|=(1<<PA0);
        _delay_us(1900);
        PORTA&=~(1<<PA0);
        _delay_us(20000-1900);
        }
    }

void go_lowest(){
    // sets the leek to the lowest position
    for (char i=0;i<5;i++){ // takes 100ms total
        PORTA|=(1<<PA0);
        _delay_us(2300);
        PORTA&=~(1<<PA0);
        _delay_us(20000-2500);
        }
    }

void go_slow(char times){
    // does one slow leek down/up
    // beat is 500ms
    for (char i=0;i<times;i++){
        go_low();
        _delay_ms(10);
        go_high();
        _delay_ms(290);
        PORTA^=(1<<PA2);
        PORTA^=(1<<PA3);
    }
}

void go_fast(char times){
    // does one fast leek down/up
    // beat is 250ms
    for (char i=0;i<times;i++){
        go_low();
        _delay_ms(10);
        go_high();
        _delay_ms(15);
        PORTA^=(1<<PA2);
        PORTA^=(1<<PA3);
    }
}
void head_left(){
    // tilts the head to the left
    for (char i=0;i<5;i++){
        PORTA|=(1<<PA1);
        _delay_us(1330);
        PORTA&=~(1<<PA1);
        _delay_us(20000-1200);
        }
    }

void head_right(){
    // tilts the head to the right
    for (char i=0;i<5;i++){
        PORTA|=(1<<PA1);
        _delay_us(1500);
        PORTA&=~(1<<PA1);
        _delay_us(20000-1200);
        }
    }

void head_center(){
    // centers the head
    for (char i=0;i<5;i++){
        PORTA|=(1<<PA1);
        _delay_us(1400);
        PORTA&=~(1<<PA1);
        _delay_us(20000-1200);
        }
    }

void head_go(char times){
    // rocks the head back and forth once
    for (char i=0;i<(times-1);i++){
        head_left();
        _delay_ms(400);
        PORTA^=(1<<PA2);
        PORTA^=(1<<PA3);
        head_right();
        _delay_ms(400);
        PORTA^=(1<<PA2);
        PORTA^=(1<<PA3);
    }
    head_center(); // returns head to center when done
    _delay_ms(400);
    PORTA^=(1<<PA2);
    PORTA^=(1<<PA3);
}

int main(void) {
    while (1){
        DDRA=255; // set port A (servos) as outputs
        DDRB=0; // set port B (listening pins) as inputs

        go_lowest();head_center();// set starting positions

        while ((PINB & _BV(PB0))){} // wait for beep que
        PORTA=(1<<PA3);
        go_high();_delay_ms(1000);
        while ((PINB & _BV(PB0))){} // wait for beep que
        go_slow(31); // tilt leek slowly 31 times
        while ((PINB & _BV(PB0))){} // wait for beep que
        go_slow(31); // tilt leek slowly 31 times

        while ((PINB & _BV(PB0))){} // wait for beep que
        _delay_ms(200);
        head_go(16); // rock head 16 times
        while ((PINB & _BV(PB0))){} // wait for beep que
        go_fast(68); // tilt leek rapidly 68 times
        while ((PINB & _BV(PB0))){} // wait for beep que
        go_slow(24); // tilt leek slowly 24 times
        while ((PINB & _BV(PB0))){} // wait for beep que
        go_fast(17); // tilt leek rapidly 17 times
        while ((PINB & _BV(PB0))){} // wait for beep que
        go_slow(31); // tilt leek slowly 31 times
        while ((PINB & _BV(PB0))){} // wait for beep que
        go_slow(31); // tilt leek slowly 31 times

        while ((PINB & _BV(PB0))){} // wait for beep que
        _delay_ms(200);
        head_go(16); // rock head 16 times
        go_lowest(); // reset position
        PORTA=0;
    }
  return 0;
}

Finally, I'd like to take a moment to indicate one of the reasons this project is special to me. My wife, Angelina Harden, died one year ago today. This project was the last one she worked on with me. She died a few days after the video was taken, and in the process of moving out of our apartment I threw away almost everything (including this project). Although I never finished it, I remember working on it with Angelina - we went to wal-mart together to buy the foam board I used to make it, and she told me that I should make her head rock back and forth rather than just move her arm. I remember that, once it was all done, I let her sit in the chair in front of it and played it through, and she laughed nearly the whole time :) I'll always miss her.

Markdown source code last modified on January 18th, 2021
---
title: Geek Spin - ATTiny44 Project Prototype
date: 2012-08-18 15:28:38
tags: microcontroller, old
---

# Geek Spin - ATTiny44 Project Prototype

__Some days you feel like working on projects to benefit humanity. The day I made this clearly wasn't one of those days.__ A little over a year ago, I got into a troll war with my friend [Mike Seese](http://www.mikeseese.com/). The joke, similar to that of [rick rolling](http://www.youtube.com/watch?v=oHg5SJYRHA0), was to get each other to unexpectedly click a link to the [Hatsune Miku version of the leekspin song](http://www.youtube.com/watch?v=kbbA9BhCTko&feature=player_embedded). After several weeks of becoming beyond annoying, I decided to make an _actual_ Hatsune Miku which would spin her leek and bobble her head to the techno version of the [Levan Polka](http://www.youtube.com/watch?v=1ygdAiDxKfI) for his birthday.

<div class="text-center img-border">

![](leek-spin.gif)

</div>

__The goal was to create a minature Miku which would perform perfectly in sync with audio coming from a portable music player (iPod or something) and _NOT_ require a computer connection.__ I accomplished it by sending some creative control beeps out of the left channel of the stereo signal. Although I didn't finish the project, I got pretty far with the prototype, so I decided to dig it out of the archives and share it with the world because it's pretty entertaining!

![](https://www.youtube.com/embed/RzqdL5gqaHM)

(look how close I came to replicating the original:

![](https://www.youtube.com/embed/6ZWwqTnqxdk)

__How did I do it?__ First off, I used servos. If you're not familiar with them, I suggest you look up [how servos work](http://www.servocity.com/html/how_do_servos_work_.html). Perhaps check out [how to control servos with AVR microcontrollers](http://www.engineersgarage.com/embedded/avr-microcontroller-projects/atmega16-servo-motor-circuit). Basically, their position along a rotational axis is determined by the width of a pulse on a 20ms time window. Anyhow, if I only had 1 servo to control (i.e., leek only), I'd have controlled the servo directly with PWM signals in the left channel - no microcontroller needed, easy as pie, problem solved. However, since I needed to control two servos, I had to come up with something a bit more creative. Although I could have probably done this ten different ways, the way I chose to do it was using a series of pre-encoded leek spin and head bobble motions, triggered by control beeps in the left channel of the audio cable. (The right channel was patched through to the speakers.)  Below is a diagram of what I believe I did, although I didn't thoroughly document it at the time, so you might have to use your imagination if you decide to re-create this project.

<div class="text-center img-border">

![](2012-08-18-15.21.34-525x289.jpg)

</div>

__The idea is that by sending bursts of sine waves,__ the circuit can rectify them and smooth them out to have them look to a microcontroller like a brief "high" signal. Each signal would tell the microcontroller to proceed to the next pre-programmed (and carefully timed) routine.  With enough practice listening, watching, and tweaking the code, I was able to make a final version which worked pretty darn well!


<div class="text-center img-border">

![](geek_spin.gif)

</div>

__LISTEN__ to the [music with control beeps](http://www.SWHarden.com/blog/images/2012/08/GOLEEKGO.mp3) (it's a surprisingly fun listen)

__A few technical details__ are that I used an ATTiny44a microcontroller (it may have been an ATTiny2313, I can't remember for sure, but they're so similar it's virtually negligable).  The servos I used were cheap (maybe $4?) from eBay. They looked like the one pictured below. The servo position was controlled by PWM, but I manually sent the pulses and didn't actually use the integrated PWM in the microcontroller.  I can't remember why I did it this way - perhaps because it was so simple to use the _delay_us() and _delay_ms() functions? I also used an operational amplifier (if I remember, it was a LM741) to boost the left channel control signals rather than rectifying/assessing the left channel directly.

<div class="text-center img-border img-micro">

[![](01_findpic_thumb.jpg)](01_findpic.png)
[![](02_dropbg_thumb.jpg)](02_dropbg.jpg)
[![](08_hairtop_thumb.jpg)](08_hairtop.jpg)
[![](06_blockskirt_thumb.jpg)](06_blockskirt.jpg)
[![](body_thumb.jpg)](body.png)
[![](hairtop_thumb.jpg)](hairtop.png)

</div>

[This is the video](https://www.youtube.com/embed/kbbA9BhCTko) which I mimiced to create my prototype (note how the leek in her arm and her head move exactly the same as the prototype I made - score!)

__And how did I find out about this song?__ I actually saw it on the video below which was hosted on wimp.com. I thought the song was catchy, looked it up, and the rest was history. It's worth noting that (perhaps to avoid copyright issues?) the key was shifted two half-steps up. I get a kick out of the way the girl waves her arm in the beginning, mimicking the leek :)

![](https://www.youtube.com/embed/Pk1CTYszDFU)

__Here are some of the images I made__ which I printed, glued to foam board, and cut out with a razor blade. I'm not sure how useful they are, but they're provided just in case.

... but sometimes Japan takes it a bit too far and things get awkward ...

__Below is the code I used.__ Note that PWM that controls the servos isn't the integrated PWM, but rather a couple pins I manually pulse on and off to control the arm and head positions. Also notice how, in the main routine, I wait for the control beeps before continuing the next sequences.

```c

// leek spin code - designed for ATTiny
// by Scott Harden, www.SWHarden.com

#include <avr/io.h>
#include <avr/delay.h>

void go_high(){
    // sets the arm to the highest position
    for (char i=0;i<5;i++){
        PORTA|=(1<<PA0);
        _delay_us(1400);
        PORTA&=~(1<<PA0);
        _delay_us(20000-1200);
        }
    }

void go_low(){
    // sets the leek to the middle position
    for (char i=0;i<5;i++){
        PORTA|=(1<<PA0);
        _delay_us(1900);
        PORTA&=~(1<<PA0);
        _delay_us(20000-1900);
        }
    }

void go_lowest(){
    // sets the leek to the lowest position
    for (char i=0;i<5;i++){ // takes 100ms total
        PORTA|=(1<<PA0);
        _delay_us(2300);
        PORTA&=~(1<<PA0);
        _delay_us(20000-2500);
        }
    }

void go_slow(char times){
    // does one slow leek down/up
    // beat is 500ms
    for (char i=0;i<times;i++){
        go_low();
        _delay_ms(10);
        go_high();
        _delay_ms(290);
        PORTA^=(1<<PA2);
        PORTA^=(1<<PA3);
    }
}

void go_fast(char times){
    // does one fast leek down/up
    // beat is 250ms
    for (char i=0;i<times;i++){
        go_low();
        _delay_ms(10);
        go_high();
        _delay_ms(15);
        PORTA^=(1<<PA2);
        PORTA^=(1<<PA3);
    }
}
void head_left(){
    // tilts the head to the left
    for (char i=0;i<5;i++){
        PORTA|=(1<<PA1);
        _delay_us(1330);
        PORTA&=~(1<<PA1);
        _delay_us(20000-1200);
        }
    }

void head_right(){
    // tilts the head to the right
    for (char i=0;i<5;i++){
        PORTA|=(1<<PA1);
        _delay_us(1500);
        PORTA&=~(1<<PA1);
        _delay_us(20000-1200);
        }
    }

void head_center(){
    // centers the head
    for (char i=0;i<5;i++){
        PORTA|=(1<<PA1);
        _delay_us(1400);
        PORTA&=~(1<<PA1);
        _delay_us(20000-1200);
        }
    }

void head_go(char times){
    // rocks the head back and forth once
    for (char i=0;i<(times-1);i++){
        head_left();
        _delay_ms(400);
        PORTA^=(1<<PA2);
        PORTA^=(1<<PA3);
        head_right();
        _delay_ms(400);
        PORTA^=(1<<PA2);
        PORTA^=(1<<PA3);
    }
    head_center(); // returns head to center when done
    _delay_ms(400);
    PORTA^=(1<<PA2);
    PORTA^=(1<<PA3);
}

int main(void) {
    while (1){
        DDRA=255; // set port A (servos) as outputs
        DDRB=0; // set port B (listening pins) as inputs

        go_lowest();head_center();// set starting positions

        while ((PINB & _BV(PB0))){} // wait for beep que
        PORTA=(1<<PA3);
        go_high();_delay_ms(1000);
        while ((PINB & _BV(PB0))){} // wait for beep que
        go_slow(31); // tilt leek slowly 31 times
        while ((PINB & _BV(PB0))){} // wait for beep que
        go_slow(31); // tilt leek slowly 31 times

        while ((PINB & _BV(PB0))){} // wait for beep que
        _delay_ms(200);
        head_go(16); // rock head 16 times
        while ((PINB & _BV(PB0))){} // wait for beep que
        go_fast(68); // tilt leek rapidly 68 times
        while ((PINB & _BV(PB0))){} // wait for beep que
        go_slow(24); // tilt leek slowly 24 times
        while ((PINB & _BV(PB0))){} // wait for beep que
        go_fast(17); // tilt leek rapidly 17 times
        while ((PINB & _BV(PB0))){} // wait for beep que
        go_slow(31); // tilt leek slowly 31 times
        while ((PINB & _BV(PB0))){} // wait for beep que
        go_slow(31); // tilt leek slowly 31 times

        while ((PINB & _BV(PB0))){} // wait for beep que
        _delay_ms(200);
        head_go(16); // rock head 16 times
        go_lowest(); // reset position
        PORTA=0;
    }
  return 0;
}

```

__Finally, I'd like to take a moment to indicate one of the reasons this project is special to me.__ My wife, Angelina Harden, died one year ago today. This project was the last one she worked on with me. She died a few days after the video was taken, and in the process of moving out of our apartment I threw away almost everything (including this project). Although I never finished it, I remember working on it with Angelina - we went to wal-mart together to buy the foam board I used to make it, and she told me that I should make her head rock back and forth rather than just move her arm. I remember that, once it was all done, I let her sit in the chair in front of it and played it through, and she laughed nearly the whole time :) I'll always miss her.
June 24th, 2012

Introduction to PIC Programming for AVR users

I'm not ashamed to say it: I'm a bit of an ATMEL guy. AVR microcontrollers are virtually exclusively what I utilize when creating hobby-level projects. Wile I'd like to claim to be an expert in the field since I live and breathe ATMEL datasheets and have used many intricate features of these microchips, the reality is that I have little experience with other platforms, and have likely been leaning on AVR out of habit and personal convention rather than a tangible reason.

Although I was initially drawn to the AVR line of microcontrollers because of its open-source nature (The primary compiler is the free AVR-GCC) and longstanding ability to be programmed from non-Windows operating systems (like Linux), Microchip's PIC has caught my eye over the years because it's often a few cents cheaper, has considerably large professional documentation, and offers advanced integrated peripherals (such as native USB functionality in a DIP package) more so than the current line of ATTiny and ATMega microcontrollers. From a hobby standpoint, I know that ATMEL is popular (think Arduino), but from a professional standpoint I usually hear about commercial products utilizing PIC microcontrollers. One potential drawback to PIC (and the primary reason I stayed away from it) is that full-featured C compilers are often not free, and as a student in the medical field learning electrical engineering as a hobby, I'm simply not willing to pay for software at this stage in my life.

I decided to take the plunge and start gaining some experience with the PIC platform. I ordered some PIC chips (a couple bucks a piece), a PIC programmer (a Chinese knock-off clone of the Pic Kit 2 which is <$20 shipped on eBay), and shelved it for over a year before I got around to figuring it out today. My ultimate goal is to utilize its native USB functionality (something at ATMEL doesn't currently offer in DIP packages). I've previously used bit-banging libraries like V-USB to hack together a USB interface on AVR microcontrollers, but it felt unnecessarily complex. PIC is commonly used and a bit of an industry standard, so I'm doing myself a disservice by not exploring it. My goal is USB functionality, but I have to start somewhere: blinking a LED.

Here's my blinking LED. It's a bit anticlimactic, but it represents a successful program design from circuit to writing the code to programming the microchip.

Based on my limited experience, it seems you need 4 things to program a PIC microcontroller with C:

The first thing I did was familiarize myself with the pin diagram of my PIC from its datasheet. I'm playing with an 18F2450 and the datasheet is quite complete. If you look at the pin diagram, you can find pins labeled MCLR (reset), VDD (+5V), VSS (GND), PGC (clock), and PGD (data). These pins should be connected to their respective counterparts on the programmer. To test connectivity, install and run the PICkit2 installer software and it will let you read/verify the firmware on the chip, letting you know connectivity is solid. Once you're there, you're ready to start coding!

I wish I were friends with someone who programmed PIC, such that in 5 minutes I could be shown what took a couple hours to figure out. There are quite a few tutorials out there - borderline too many, and they all seem to be a bit different. To quickly get acquainted with the PIC programming environment, I followed the "Hello World" Program in C tutorial on PIC18F.com. Unfortunately, it didn't work as posted, likely because their example code was based on a PIC 18F4550 and mine is an 18F2450, but I still don't understand why such a small difference caused such a big problem. The problem was in their use of LATDbits and TRISDbits (which I tried to replace with LATBbits and TRISBbits). I got around it by manually addressing TRISB and LATB. Anyway, this is what I came up with:

#include <p18f2450.h> // load pin names
#include <delays.h>   // load delay library

#pragma config WDT = OFF // disable watchdog timer
#pragma config FOSC = INTOSCIO_EC // use internal clock

void main() // this is the main program
{
    TRISB=0B00000000; // set all pins on port B as output
    while(1) // execute the following code block forever
    {
        LATB = 0b11111111; // turn all port B pins ON
        Delay10KTCYx(1);   // pause 1 second
        LATB = 0b00000000; // turn all port B pins OFF
        Delay10KTCYx(1);   // pause 1 second
    }
}

A couple notes about the code: the WDT=OFF disables the watchdog timer, which if left unchecked would continuously reboot the microcontroller. The FOSC=INTOSCIO_EC section tells the microcontroller to use its internal oscillator, allowing it to execute code without necessitating an external crystal or other clock source. As to what TRIS and LAT do, I'll refer you to basic I/O operations with PIC.

Here is what the MPLAB IDE looked like after I successfully loaded the code onto the microcontroller. At this time, the LED began blinking about once per second. I guess that about wraps it up! This afternoon I pulled a PIC out of my junk box and, having never programmed a PIC before, successfully loaded the software, got my programmer up and running, and have a little functioning circuit. I know it isn't that big of a deal, but it's a step in the right direction, and I'm glad I've taken it.

Markdown source code last modified on January 18th, 2021
---
title: Introduction to PIC Programming for AVR users
date: 2012-06-24 20:29:03
tags: microcontroller, old
---

# Introduction to PIC Programming for AVR users

__I'm not ashamed to say it: I'm a bit of an ATMEL guy.__ [AVR microcontrollers](http://en.wikipedia.org/wiki/Atmel_AVR) are virtually exclusively what I utilize when creating hobby-level projects. Wile I'd like to claim to be an expert in the field since I live and breathe ATMEL datasheets and have used many intricate features of these microchips, the reality is that I have little experience with other platforms, and have likely been leaning on AVR out of habit and personal convention rather than a tangible reason.

<div class="text-center">

![](150-28-DIP1-200x128.jpg)

</div>

**Although I was initially drawn to the AVR line of microcontrollers** because of its open-source nature (The primary compiler is the free AVR-GCC) and longstanding ability to be programmed from non-Windows operating systems (like Linux), [Microchip's PIC](http://en.wikipedia.org/wiki/PIC_microcontroller) has caught my eye over the years because it's often a few cents cheaper, has considerably large professional documentation, and offers advanced integrated peripherals (such as native USB functionality in a DIP package) more so than the current line of ATTiny and ATMega microcontrollers. From a hobby standpoint, I know that ATMEL is popular (think [Arduino](http://en.wikipedia.org/wiki/Arduino)), but from a professional standpoint I usually hear about commercial products utilizing PIC microcontrollers. One potential drawback to PIC (and the primary reason I stayed away from it) is that full-featured C compilers are often not free, and as a student in the medical field learning electrical engineering as a hobby, I'm simply not willing to pay for software at this stage in my life.

__I decided to take the plunge and start gaining some experience with the PIC platform.__ I ordered some PIC chips (a couple bucks a piece), a PIC programmer (a Chinese knock-off clone of the [Pic Kit 2](http://en.wikipedia.org/wiki/PICKit) which is <$20 shipped on eBay), and shelved it for over a year before I got around to figuring it out today. My ultimate goal is to utilize its native USB functionality (something at ATMEL doesn't currently offer in DIP packages). I've previously used bit-banging libraries like [V-USB](http://www.obdev.at/products/vusb/index.html) to hack together a USB interface on AVR microcontrollers, but it felt unnecessarily complex. PIC is commonly used and a bit of an industry standard, so I'm doing myself a disservice by not exploring it. My goal is USB functionality, but I have to start somewhere: blinking a LED.

<div class="text-center">

![](2012-06-24-15.57.56-525x393.jpg)

</div>

__Here's my blinking LED__. It's a bit anticlimactic, but it represents a successful program design from circuit to writing the code to programming the microchip.
>  _Based on my limited experience, it seems you need 4 things to program a PIC microcontroller with C:_
>
> *   __[PIC microcontroller](http://en.wikipedia.org/wiki/PIC_microcontroller)__ compatible with your programmer and your software (I'm using [18F2450](http://ww1.microchip.com/downloads/en/DeviceDoc/39760d.pdf))
> *   __PIC programmer__ (I'm using a clone [PicKit 2](http://en.wikipedia.org/wiki/PICKit), [$19.99 shipped on eBay](http://www.ebay.com/sch/i.html?_trksid=p5197.m570.l1313&_nkw=pic+kit+2&_sacat=0)) - get the PICkit2 installer [here](http://www.microchip.com/stellent/idcplg?IdcService=SS_GET_PAGE&nodeId=1406&dDocName=en023805)
> *   Install __[MPLAB IDE](http://www.microchip.com/stellent/idcplg?IdcService=SS_GET_PAGE&nodeId=1406&dDocName=en019469&part=SW007002)__ (programming environment for PIC) - has a free version
> *   Install a __C compiler__: I'm using [PIC18 C Compiler for MPLAB](http://www.microchip.com/stellent/idcplg?IdcService=SS_GET_PAGE&nodeId=1406&dDocName=en010014) Lite - has a free version
>
>
__The first thing I did was familiarize myself with the pin diagram of my PIC from its datasheet__. I'm playing with an [18F2450](http://ww1.microchip.com/downloads/en/DeviceDoc/39760d.pdf) and the [datasheet is quite complete](http://ww1.microchip.com/downloads/en/DeviceDoc/39760d.pdf). If you look at the pin diagram, you can find pins labeled __MCLR__ (reset), __VDD__ (+5V), __VSS__ (GND), __PGC__ (clock), and __PGD__ (data). These pins should be connected to their respective counterparts on the programmer. To test connectivity, install and run the [PICkit2 installer software](http://www.microchip.com/stellent/idcplg?IdcService=SS_GET_PAGE&nodeId=1406&dDocName=en023805) and it will let you read/verify the firmware on the chip, letting you know connectivity is solid. Once you're there, you're ready to start coding!

__I wish I were friends with someone who programmed PIC, such that in 5 minutes I could be shown what took a couple hours to figure out.__ There are quite a few tutorials out there - borderline too many, and they all seem to be a bit different. To quickly get acquainted with the PIC programming environment, I followed the ["Hello World" Program in C tutorial](http://www.pic18f.com/18f4550-c-tutorial/2009/11/16/tutorial-4-hello-world-program-in-c/) on [PIC18F.com](http://www.pic18f.com/). Unfortunately, it didn't work as posted, likely because their example code was based on a PIC 18F4550 and mine is an 18F2450, but I still don't understand why such a small difference caused such a big problem. The problem was in their use of LATDbits and TRISDbits (which I tried to replace with LATBbits and TRISBbits). I got around it by manually addressing TRISB and LATB. Anyway, this is what I came up with:

```c
#include <p18f2450.h> // load pin names
#include <delays.h>   // load delay library

#pragma config WDT = OFF // disable watchdog timer
#pragma config FOSC = INTOSCIO_EC // use internal clock

void main() // this is the main program
{
    TRISB=0B00000000; // set all pins on port B as output
    while(1) // execute the following code block forever
    {
        LATB = 0b11111111; // turn all port B pins ON
        Delay10KTCYx(1);   // pause 1 second
        LATB = 0b00000000; // turn all port B pins OFF
        Delay10KTCYx(1);   // pause 1 second
    }
}
```

__A couple notes about the code:__ the WDT=OFF disables the [watchdog timer](http://en.wikipedia.org/wiki/Watchdog_timer), which if left unchecked would continuously reboot the microcontroller. The FOSC=INTOSCIO_EC section tells the microcontroller to use its internal oscillator, allowing it to execute code without necessitating an external crystal or other clock source. As to what TRIS and LAT do, I'll refer you to [basic I/O operations with PIC](http://www.mikroe.com/eng/chapters/view/4/chapter-3-i-o-ports/).

<div class="text-center img-medium">

[![](pic-ledblink_thumb.jpg)](pic-ledblink.png)

</div>

__Here is what the MPLAB IDE looked like after I successfully loaded the code onto the microcontroller.__ At this time, the LED began blinking about once per second. I guess that about wraps it up! This afternoon I pulled a PIC out of my junk box and, having never programmed a PIC before, successfully loaded the software, got my programmer up and running, and have a little functioning circuit. I know it isn't _that_ big of a deal, but it's a step in the right direction, and I'm glad I've taken it.
June 14th, 2012

Multichannel USB Analog Sensor with ATMega48

Sometimes it's tempting to re-invent the wheel to make a device function exactly the way you want. I am re-visiting the field of homemade electrophysiology equipment, and although I've already published a home made electocardiograph (ECG), I wish to revisit that project and make it much more elegant, while also planning for a pulse oximeter, an electroencephalograph (EEG), and an electrogastrogram (EGG). This project is divided into 3 major components: the low-noise microvoltage amplifier, a digital analog to digital converter with PC connectivity, and software to display and analyze the traces. My first challenge is to create that middle step, a device to read voltage (from 0-5V) and send this data to a computer.

This project demonstrates a simple solution for the frustrating problem of sending data from a microcontroller to a PC with a USB connection. My solution utilizes a USB FTDI serial-to-usb cable, allowing me to simply put header pins on my device which I can plug into providing the microcontroller-computer link. This avoids the need for soldering surface-mount FTDI chips (which gets expensive if you put one in every project). FTDI cables are inexpensive (about $11 shipped on eBay) and I've gotten a lot of mileage out of mine and know I will continue to use it for future projects. If you are interested in MCU/PC communication, consider one of these cables as a rapid development prototyping tool. I'm certainly enjoying mine!

It is important to me that my design is minimalistic, inexpensive, and functions natively on Linux and Windows without installing special driver-related software, and can be visualized in real-time using native Python libraries, such that the same code can be executed identically on all operating systems with minimal computer-side configuration. I'd say I succeeded in this effort, and while the project could use some small touches to polish it up, it's already solid and proven in its usefulness and functionality.

This is my final device. It's reading voltage on a single pin, sending this data to a computer through a USB connection, and custom software (written entirely in Python, designed to be a cross-platform solution) displays the signal in real time. Although it's capable of recording and displaying 5 channels at the same time, it's demonstrated displaying only one. Let's check-out a video of it in action:

This 5-channel realtime USB analog sensor, coupled with custom cross-platform open-source software, will serve as the foundation for a slew of electrophysiological experiments, but can also be easily expanded to serve as an inexpensive multichannel digital oscilloscope. While more advanced solutions exist, this has the advantage of being minimally complex (consisting of a single microchip), inexpensive, and easy to build.

Below is a simplified description of the circuit that is employed in this project. Note that there are 6 ADC (analog to digital converter) inputs on the ATMega48 IC, but for whatever reason I ended-up only hard-coding 5 into the software. Eventually I'll go back and re-declare this project a 6-channel sensor, but since I don't have six things to measure at the moment I'm fine keeping it the way it is. RST, SCK, MISO, and MOSI are used to program the microcontroller and do not need to be connected to anything for operation. The max232 was initially used as a level converter to allow the micro-controller to communicate with a PC via the serial port. However, shortly after this project was devised an upgrade was used to allow it to connect via USB.

Below you can see the circuit breadboarded. The potentiometer (small blue box) simulated an analog input signal.

The lower board is my AVR programmer, and is connected to RST, SCK, MISO, MOSI, and GND to allow me to write code on my laptop and program the board. It's a Fun4DIY.com AVR programmer which can be yours for $11 shipped! I'm not affiliated with their company, but I love that little board. It's a clone of the AVR ISP MK-II.

As you can see, the USB AVR programmer I'm using is supported in Linux. I did all of my development in Ubuntu Linux, writing AVR-GCC (C) code in my favorite Linux code editor Geany, then loaded the code onto the chip with AVRDude.

I found a simple way to add USB functionality in a standard, reproducible way that works without requiring the soldering of a SMT FTDI chip, and avoids custom libraries like V-USB which don't easily have drivers that are supported by major operating systems (Windows) without special software. I understand that the simplest long-term and commercially-logical solution would be to use that SMT chip, but I didn't feel like dealing with it. Instead, I added header pins which allow me to snap-on a pre-made FTDI USB cable. They're a bit expensive ($12 on ebay) but all I need is 1 and I can use it in all my projects since it's a sinch to connect and disconnect. Beside, it supplies power to the target board! It's supported in Linux and in Windows with established drivers that are shipped with the operating system. It's a bit of a shortcut, but I like this solution. It also eliminates the need for the max232 chip, since it can sense the voltages outputted by the microcontroller directly.

The system works by individually reading the 10-bit ADC pins on the microcontroller (providing values from 0-1024 to represent voltage from 0-5V or 0-1.1V depending on how the code is written), converting these values to text, and sending them as a string via the serial protocol. The FTDI cable reads these values and transmits them to the PC through a USB connection, which looks like "COM5" on my Windows computer. Values can be seen in any serial terminal program (i.e., hyperterminal), or accessed through Python with the PySerial module.

As you can see, I'm getting quite good at home-brewn PCBs. While it would be fantastic to design a board and have it made professionally, this is expensive and takes some time. In my case, I only have a few hours here or there to work on projects. If I have time to design a board, I want it made immediately! I can make this start to finish in about an hour. I use a classic toner transfer method with ferric chloride, and a dremel drill press to create the holes. I haven't attacked single-layer SMT designs yet, but I can see its convenience, and look forward to giving it a shot before too long.

Here's the final board ready for digitally reporting analog voltages. You can see 3 small headers on the far left and 2 at the top of the chip. These are for RST, SCK, MISO, MOSI, and GND for programming the chip. Once it's programmed, it doesn't need to be programmed again. Although I wrote the code for an ATMega48, it works fine on a pin-compatible ATMega8 which is pictured here. The connector at the top is that FTDI USB cable, and it supplies power and USB serial connectivity to the board.

If you look closely, you can see that modified code has been loaded on this board with a Linux laptop. This thing is an exciting little board, because it has so many possibilities. It could read voltages of a single channel in extremely high speed and send that data continuously, or it could read from many channels and send it at any rate, or even cooler would be to add some bidirectional serial communication capabilities to allow the computer to tell the microcontroller which channels to read and how often to report the values back. There is a lot of potential for this little design, and I'm glad I have it working.

Unfortunately I lost the schematics to this device because I formatted the computer that had the Eagle files on it. It should be simple and intuitive enough to be able to design again. The code for the microcontroller and code for the real-time visualization software will be posted below shortly. Below are some videos of this board in use in one form or another:

Here is the code that is loaded onto the microcontroller:


#define F_CPU 8000000UL
#include <avr/io.h>
#include <util/delay.h>

void readADC(char adcn){
        //ADMUX = 0b0100000+adcn; // AVCC ref on ADCn
        ADMUX = 0b1100000+adcn; // AVCC ref on ADCn
        ADCSRA |= (1<<ADSC); // reset value
        while (ADCSRA & (1<<ADSC)) {}; // wait for measurement
}

int main (void){
    DDRD=255;
    init_usart();
    ADCSRA = 0b10000111; //ADC Enable, Manual Trigger, Prescaler
    ADCSRB = 0;

    int adcs[8]={0,0,0,0,0,0,0,0};

    char i=0;
    for(;;){
        for (i=0;i<8;i++){readADC(i);adcs[i]=ADC>>6;}
        for (i=0;i<5;i++){sendNum(adcs[i]);send(44);}
        readADC(0);
        send(10);// LINE BREAK
        send(13); //return
        _delay_ms(3);_delay_ms(5);
    }
}

void sendNum(unsigned int num){
    char theIntAsString[7];
    int i;
    sprintf(theIntAsString, "%u", num);
    for (i=0; i < strlen(theIntAsString); i++){
        send(theIntAsString[i]);
    }
}

void send (unsigned char c){
    while((UCSR0A & (1<<UDRE0)) == 0) {}
    UDR0 = c;
}

void init_usart () {
    // ATMEGA48 SETTINGS
    int BAUD_PRESCALE = 12;
    UBRR0L = BAUD_PRESCALE; // Load lower 8-bits
    UBRR0H = (BAUD_PRESCALE >> 8); // Load upper 8-bits
    UCSR0A = 0;
    UCSR0B = (1<<RXEN0)|(1<<TXEN0); //rx and tx
    UCSR0C = (1<<UCSZ01) | (1<<UCSZ00); //We want 8 data bits
}

Here is the code that runs on the computer, allowing reading and real-time graphing of the serial data. It's written in Python and has been tested in both Linux and Windows. It requires NO non-standard python libraries, making it very easy to distribute. Graphs are drawn (somewhat inefficiently) using lines in TK. Subsequent development went into improving the visualization, and drastic improvements have been made since this code was written, and updated code will be shared shortly. This is functional, so it's worth sharing.

import Tkinter, random, time
import socket, sys, serial

class App:

    def white(self):
        self.lines=[]
        self.lastpos=0

        self.c.create_rectangle(0, 0, 800, 512, fill="black")
        for y in range(0,512,50):
            self.c.create_line(0, y, 800, y, fill="#333333",dash=(4, 4))
            self.c.create_text(5, y-10, fill="#999999", text=str(y*2), anchor="w")
        for x in range(100,800,100):
            self.c.create_line(x, 0, x, 512, fill="#333333",dash=(4, 4))
            self.c.create_text(x+3, 500-10, fill="#999999", text=str(x/100)+"s", anchor="w")

        self.lineRedraw=self.c.create_line(0, 800, 0, 0, fill="red")

        self.lines1text=self.c.create_text(800-3, 10, fill="#00FF00", text=str("TEST"), anchor="e")
        for x in range(800):
            self.lines.append(self.c.create_line(x, 0, x, 0, fill="#00FF00"))

    def addPoint(self,val):
        self.data[self.xpos]=val
        self.line1avg+=val
        if self.xpos%10==0:
            self.c.itemconfig(self.lines1text,text=str(self.line1avg/10.0))
            self.line1avg=0
        if self.xpos>0:self.c.coords(self.lines[self.xpos],(self.xpos-1,self.lastpos,self.xpos,val))
        if self.xpos<800:self.c.coords(self.lineRedraw,(self.xpos+1,0,self.xpos+1,800))
        self.lastpos=val
        self.xpos+=1
        if self.xpos==800:
            self.xpos=0
            self.totalPoints+=800
            print "FPS:",self.totalPoints/(time.time()-self.timeStart)
        t.update()

    def __init__(self, t):
        self.xpos=0
        self.line1avg=0
        self.data=[0]*800
        self.c = Tkinter.Canvas(t, width=800, height=512)
        self.c.pack()
        self.totalPoints=0
        self.white()
        self.timeStart=time.time()

t = Tkinter.Tk()
a = App(t)

#ser = serial.Serial('COM1', 19200, timeout=1)
ser = serial.Serial('/dev/ttyUSB0', 38400, timeout=1)
sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
sock.setsockopt(socket.SOL_SOCKET, socket.SO_BROADCAST, 1)

while True:
    while True: #try to get a reading
        #print "LISTENING"
        raw=str(ser.readline())
        #print raw
        raw=raw.replace("n","").replace("r","")
        raw=raw.split(",")
        #print raw
        try:
            point=(int(raw[0])-200)*2
            break
        except:
            print "FAIL"
            pass
    point=point/2
    a.addPoint(point)

If you re-create this device of a portion of it, let me know! I'd love to share it on my website. Good luck!

Markdown source code last modified on January 18th, 2021
---
title: Multichannel USB Analog Sensor with ATMega48
date: 2012-06-14 10:42:00
tags: microcontroller, circuit, old
---

# Multichannel USB Analog Sensor with ATMega48

__Sometimes it's tempting to re-invent the wheel to make a device function exactly the way you want.__ I am re-visiting the field of homemade electrophysiology equipment, and although I've [already published](http://www.swharden.com/blog/2009-08-14-diy-ecg-machine-on-the-cheap/) a home made [electocardiograph](http://en.wikipedia.org/wiki/Electrocardiography) (ECG), I wish to revisit that project and make it much more elegant, while also planning for a [pulse oximeter](http://en.wikipedia.org/wiki/Pulse_oximeter), an [electroencephalograph](http://en.wikipedia.org/wiki/Electroencephalography) (EEG), and an [electrogastrogram](http://en.wikipedia.org/wiki/Electrogastrogram) (EGG). This project is divided into 3 major components: the low-noise microvoltage amplifier, a digital analog to digital converter with PC connectivity, and software to display and analyze the traces. My first challenge is to create that middle step, a device to read voltage (from 0-5V) and send this data to a computer.

> This project demonstrates a simple solution for the frustrating problem of sending data from a microcontroller to a PC with a USB connection. My solution utilizes a [USB FTDI serial-to-usb cable](http://www.ftdichip.com/Products/Cables/USBTTLSerial.htm), allowing me to simply put header pins on my device which I can plug into providing the microcontroller-computer link. This avoids the need for soldering [surface-mount FTDI chips](http://en.wikipedia.org/wiki/File:Arduino_ftdi_chip-1.jpg) (which gets expensive if you put one in every project). [FTDI cables are inexpensive](http://www.ebay.com/sch/i.html?_trksid=p5197.m570.l1313&_nkw=ftdi+cable&_sacat=0) (about $11 shipped on eBay) and I've gotten a lot of mileage out of mine and know I will continue to use it for future projects. If you are interested in MCU/PC communication, consider one of these cables as a rapid development prototyping tool. I'm certainly enjoying mine!

__It is important to me that my design is minimalistic, inexpensive, and functions natively on Linux and Windows without installing special driver-related software__, and can be visualized in real-time using native Python libraries, such that the same code can be executed identically on all operating systems with minimal computer-side configuration. I'd say I succeeded in this effort, and while the project could use some small touches to polish it up, it's already solid and proven in its usefulness and functionality.

<div class="text-center img-border">

[![](011_thumb.jpg)](011.jpg)

</div>

__This is my final device.__ It's reading voltage on a single pin, sending this data to a computer through a USB connection, and custom software (written entirely in Python, designed to be a cross-platform solution) displays the signal in real time. Although it's capable of recording and displaying 5 channels at the same time, it's demonstrated displaying only one. Let's check-out a video of it in action:

![](https://www.youtube.com/embed/zPAx4JTCFAc)

>  This 5-channel realtime USB analog sensor, coupled with custom cross-platform open-source software, will serve as the foundation for a slew of electrophysiological experiments, but can also be easily expanded to serve as an inexpensive multichannel digital oscilloscope. While more advanced solutions exist, this has the advantage of being minimally complex (consisting of a single microchip), inexpensive, and easy to build.


__Below is a simplified description of the circuit__ that is employed in this project. Note that there are 6 ADC (analog to digital converter) inputs on the [ATMega48](http://www.atmel.com/devices/atmega48.aspx) IC, but for whatever reason I ended-up only hard-coding 5 into the software. Eventually I'll go back and re-declare this project a 6-channel sensor, but since I don't have six things to measure at the moment I'm fine keeping it the way it is. RST, SCK, MISO, and MOSI are used to program the microcontroller and do not need to be connected to anything for operation. The [max232](http://en.wikipedia.org/wiki/MAX232) was initially used as a level converter to allow the micro-controller to communicate with a PC via the serial port. However, shortly after this project was devised an upgrade was used to allow it to connect via USB. 


<div class="text-center img-border img-small">

[![](031_thumb.jpg)](031.jpg)

</div>

**Below you can see the circuit breadboarded.** The potentiometer (small blue box) simulated an analog input signal.

<div class="text-center img-border">

[![](041_thumb.jpg)](041.jpg)

</div>

**The lower board is my AVR programmer**, and is connected to RST, SCK, MISO, MOSI, and GND to allow me to write code on my laptop and program the board. It's a <a href="http://fun4diy.com/AVRISP_mkII.htm">Fun4DIY.com AVR programmer</a> which can be yours for $11 shipped! I'm not affiliated with their company, but I love that little board. It's a clone of the AVR ISP MK-II.

<div class="text-center img-border">

[![](051_thumb.jpg)](051.jpg)

</div>

<p style="text-align: left;"><strong>As you can see, the USB AVR programmer I'm using is supported in Linux.</strong> I did all of my development in Ubuntu Linux, writing AVR-GCC (C) code in my favorite Linux code editor <a href="http://www.geany.org/">Geany</a>, then loaded the code onto the chip with <a href="http://www.nongnu.org/avrdude/">AVRDude</a>.</p>

<p style="text-align: left;"><strong>I found a simple way to add USB functionality in a standard, reproducible way</strong> that works without requiring the soldering of a <a href="http://en.wikipedia.org/wiki/File:Arduino_ftdi_chip-1.jpg">SMT FTDI chip</a>, and avoids custom libraries like <a href="http://www.obdev.at/products/vusb/index.html">V-USB</a> which don't easily have drivers that are supported by major operating systems (Windows) without special software. I understand that the simplest long-term and commercially-logical solution would be to use that SMT chip, but I didn't feel like dealing with it. Instead, I added header pins which allow me to snap-on <a href="http://www.ftdichip.com/Products/Cables/USBTTLSerial.htm">a pre-made FTDI USB cable</a>. <em><strong>They're a bit expensive ($12 on ebay) but all I need is 1 and I can use it in all my projects since it's a sinch to connect and disconnect.</strong></em> Beside, it supplies power to the target board! It's supported in Linux and in Windows with established drivers that are shipped with the operating system. It's a bit of a shortcut, but I like this solution. It also eliminates the need for the max232 chip, since it can sense the voltages outputted by the microcontroller directly.</p>

<blockquote><p style="text-align: left;">The system works by individually reading the 10-bit <a href="http://en.wikipedia.org/wiki/Analog-to-digital_converter">ADC</a> pins on the microcontroller (providing values from 0-1024 to represent voltage from 0-5V or 0-1.1V depending on how the code is written), converting these values to text, and sending them as a string via the serial protocol. The <a href="http://www.ftdichip.com/Products/Cables/USBTTLSerial.htm">FTDI cable</a> reads these values and transmits them to the PC through a USB connection, which looks like "COM5" on my Windows computer. Values can be seen in any serial terminal program (i.e., hyperterminal), or accessed through Python with the <a href="http://pyserial.sourceforge.net/">PySerial</a> module.</p></blockquote>

**As you can see, I'm getting quite good at home-brewn PCBs.** While it would be fantastic to design a board and have it made professionally, this is expensive and takes some time. In my case, I only have a few hours here or there to work on projects. If I have time to design a board, I want it made immediately! I can make this start to finish in about an hour. I use a classic toner transfer method with ferric chloride, and a dremel drill press to create the holes. I haven't attacked single-layer SMT designs yet, but I can see its convenience, and look forward to giving it a shot before too long.</p>

<div class="text-center img-border">

[![](091_thumb.jpg)](091.jpg)

</div>

**Here's the final board ready for digitally reporting analog voltages.** You can see 3 small headers on the far left and 2 at the top of the chip. These are for RST, SCK, MISO, MOSI, and GND for programming the chip. Once it's programmed, it doesn't need to be programmed again. Although I wrote the code for an <a href="http://www.atmel.com/devices/atmega48.aspx">ATMega48</a>, it works fine on a pin-compatible <a href="http://www.atmel.com/devices/atmega8.aspx">ATMega8</a> which is pictured here. The connector at the top is that FTDI USB cable, and it supplies power and USB serial connectivity to the board.</p>

<div class="text-center img-border">

[![](101_thumb.jpg)](101.jpg)

</div>

<p style="text-align: left;"><strong>If you look closely, you can see that modified code has been loaded</strong> on this board with a Linux laptop. This thing is an exciting little board, because it has so many possibilities. It could read voltages of a single channel in extremely high speed and send that data continuously, or it could read from many channels and send it at any rate,<strong><em> or even cooler would be to add some bidirectional serial communication capabilities to allow the computer to tell the microcontroller which channels to read and how often to report the values back</em></strong>. There is a lot of potential for this little design, and I'm glad I have it working.</p>

<div class="text-center img-border">

[![](111_thumb.jpg)](111.jpg)

</div>

<p style="text-align: left;"><strong>Unfortunately I lost the schematics</strong> to this device because I formatted the computer that had the Eagle files on it. It should be simple and intuitive enough to be able to design again. The code for the microcontroller and code for the real-time visualization software will be posted below shortly. Below are some videos of this board in use in one form or another:</p>

![](https://www.youtube.com/embed/GJcrXoIC7Q8)
![](https://www.youtube.com/embed/HsV-LK3KO1U)
![](https://www.youtube.com/embed/tdf0wzS-H-8)
![](https://www.youtube.com/embed/VZkWUR-gAZk)

__Here is the code that is loaded onto the microcontroller:__

```c

#define F_CPU 8000000UL
#include <avr/io.h>
#include <util/delay.h>

void readADC(char adcn){
        //ADMUX = 0b0100000+adcn; // AVCC ref on ADCn
        ADMUX = 0b1100000+adcn; // AVCC ref on ADCn
        ADCSRA |= (1<<ADSC); // reset value
        while (ADCSRA & (1<<ADSC)) {}; // wait for measurement
}

int main (void){
    DDRD=255;
    init_usart();
    ADCSRA = 0b10000111; //ADC Enable, Manual Trigger, Prescaler
    ADCSRB = 0;

    int adcs[8]={0,0,0,0,0,0,0,0};

    char i=0;
    for(;;){
        for (i=0;i<8;i++){readADC(i);adcs[i]=ADC>>6;}
        for (i=0;i<5;i++){sendNum(adcs[i]);send(44);}
        readADC(0);
        send(10);// LINE BREAK
        send(13); //return
        _delay_ms(3);_delay_ms(5);
    }
}

void sendNum(unsigned int num){
    char theIntAsString[7];
    int i;
    sprintf(theIntAsString, "%u", num);
    for (i=0; i < strlen(theIntAsString); i++){
        send(theIntAsString[i]);
    }
}

void send (unsigned char c){
    while((UCSR0A & (1<<UDRE0)) == 0) {}
    UDR0 = c;
}

void init_usart () {
    // ATMEGA48 SETTINGS
    int BAUD_PRESCALE = 12;
    UBRR0L = BAUD_PRESCALE; // Load lower 8-bits
    UBRR0H = (BAUD_PRESCALE >> 8); // Load upper 8-bits
    UCSR0A = 0;
    UCSR0B = (1<<RXEN0)|(1<<TXEN0); //rx and tx
    UCSR0C = (1<<UCSZ01) | (1<<UCSZ00); //We want 8 data bits
}

```

__Here is the code that runs on the computer, allowing reading and real-time graphing of the serial data.__ It's written in Python and has been tested in both Linux and Windows. It requires *NO* non-standard python libraries, making it very easy to distribute. Graphs are drawn (somewhat inefficiently) using lines in TK. Subsequent development went into improving the visualization, and drastic improvements have been made since this code was written, and updated code will be shared shortly. This is functional, so it's worth sharing.

```python
import Tkinter, random, time
import socket, sys, serial

class App:

    def white(self):
        self.lines=[]
        self.lastpos=0

        self.c.create_rectangle(0, 0, 800, 512, fill="black")
        for y in range(0,512,50):
            self.c.create_line(0, y, 800, y, fill="#333333",dash=(4, 4))
            self.c.create_text(5, y-10, fill="#999999", text=str(y*2), anchor="w")
        for x in range(100,800,100):
            self.c.create_line(x, 0, x, 512, fill="#333333",dash=(4, 4))
            self.c.create_text(x+3, 500-10, fill="#999999", text=str(x/100)+"s", anchor="w")

        self.lineRedraw=self.c.create_line(0, 800, 0, 0, fill="red")

        self.lines1text=self.c.create_text(800-3, 10, fill="#00FF00", text=str("TEST"), anchor="e")
        for x in range(800):
            self.lines.append(self.c.create_line(x, 0, x, 0, fill="#00FF00"))

    def addPoint(self,val):
        self.data[self.xpos]=val
        self.line1avg+=val
        if self.xpos%10==0:
            self.c.itemconfig(self.lines1text,text=str(self.line1avg/10.0))
            self.line1avg=0
        if self.xpos>0:self.c.coords(self.lines[self.xpos],(self.xpos-1,self.lastpos,self.xpos,val))
        if self.xpos<800:self.c.coords(self.lineRedraw,(self.xpos+1,0,self.xpos+1,800))
        self.lastpos=val
        self.xpos+=1
        if self.xpos==800:
            self.xpos=0
            self.totalPoints+=800
            print "FPS:",self.totalPoints/(time.time()-self.timeStart)
        t.update()

    def __init__(self, t):
        self.xpos=0
        self.line1avg=0
        self.data=[0]*800
        self.c = Tkinter.Canvas(t, width=800, height=512)
        self.c.pack()
        self.totalPoints=0
        self.white()
        self.timeStart=time.time()

t = Tkinter.Tk()
a = App(t)

#ser = serial.Serial('COM1', 19200, timeout=1)
ser = serial.Serial('/dev/ttyUSB0', 38400, timeout=1)
sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
sock.setsockopt(socket.SOL_SOCKET, socket.SO_BROADCAST, 1)

while True:
    while True: #try to get a reading
        #print "LISTENING"
        raw=str(ser.readline())
        #print raw
        raw=raw.replace("n","").replace("r","")
        raw=raw.split(",")
        #print raw
        try:
            point=(int(raw[0])-200)*2
            break
        except:
            print "FAIL"
            pass
    point=point/2
    a.addPoint(point)
```

__If you re-create this device of a portion of it, let me know!__ I'd love to share it on my website. Good luck!
June 13th, 2012

Resuming Life

I'm staring deeply into a large, ominous, empty white text box on my screen as a small vertical text cursor blinks, staring back at me. I faintly remember writing my first blog entry eleven years ago (to the week), as a 15 year old kid typing on a keyboard in the middle of the night. Every time I log-in to write on my website, I see the same cursor, monotonous in its dependable, unvarying appearance. What does the cursor see in me? Definitely not the same person it saw the last time I logged-in. What collection of words can even begin to describe the jumble that's in my head? My name is Scott Harden, my future is changing before my eyes, and I've chosen to use this website to continue to document my life as it unfolds.

It's been 298 days since I've last written. For anyone who's been through a hard time, part of getting better is acting like ones self again. For me, that's doing the things that I used to do: designing circuits, writing code, building radios, and documenting my projects on my website. Me, starting to write again - forcing myself to write again - is a step in a positive direction, and an indication that I am starting to be okay. My intention is to resume building and sharing projects on this website like I used to.

I feel it is important to address some of the recent changes in my life in a clear manner. I don't want to just resume posting code and pictures of circuits all the sudden without acknowledging the serious issues that I've dealt with and am continuing to deal with. It's important that it's obvious that (a) these things happened, (b) I'm working to be okay with them, and (c) I'm not ignoring them. I have noticed that ignoring serious issues by pretending that they do not exist is one of the most dangerous and destructive coping mechanisms a person can exhibit. People behave this way around me often, but I, in an effort to improve my situation, refuse to ignore my challenges. I will attempt to describe a few of the highlights of the last several months of my life. It's certainly not an exhaustive list, but it touches on a few of the significant experiences I have gone through, changes which have affected me, and a few of the events that made me happy since I last wrote here.

I began a new Ph.D. program in Neuroscience through the Interdisciplinary Program in Biomedical Science through the College of Medicine at the University of Florida. I am currently in my 4th year of dental school (in my 10th year of college currently), and I'm considering starting a new program from scratch. Rather than throw-away my dental degree (which I've been working on for several years and spent quite a lot of money to pursue), I am seeking a combined D.M.D/Ph.D. degree. This will allow me to graduate with a degree in dental medicine (D.M.D.) through the UF College of Dentistry about the same time I get my Ph.D. in Neuroscience through the UF College of Medicine. I begin this August, and I couldn't be more excited. As my Google Scholar author page reports, I've had excellent research experience in the past, and I'm eager to begin life again as a biomolecular graduate student. I have yet to decide the specific direction of my research, but if I could do anything in the world, I would try to find a project which lets me dip into bioinformatics.

It looks like I'm kind of sick. To make a long story short, I'm in a strange diagnostic limbo where it's looking like I may have a pretty serious, rare, and somewhat difficult to diagnose form of cancer (stage 4 peripheral T-cell lymphoma), but at the same time it seems there is a chance it could be a weird, rare ailment that's not as serious (an obscure autoimmune condition or abnormal presentation of chronic infection). The type of cancer it is currently proposed to be is pretty bad, and people usually don't live too long after their diagnosis. Intriguingly, my symptoms and clinical presentation don't reflect the rapidly destructive nature commonly associated with this disease, leaving open the possibility that it might not be that form of cancer after all. I have hard, enlarged lymph nodes (with abnormal histology demonstrated by 1 needle biopsy and 2 separate surgeries) in all quadrants of my body, and have a lot of fatigue (which I combat with large volumes of coffee). Other than that, I'm relatively normal (physically, at least). The picture to the right is me on the first visit to the oncologist. I didn't take it too seriously. I kept thinking (and still do to some degree) there's no way it could be that bad. I mean, who my age gets sick like this? And right on the heels of losing my wife? It's too coincidental, it can't be that serious! Realistically we still don't know for sure exactly what it is, and it's too early to tell how this will affect my life. It's a strange experience grappling with the idea that I might only live a few more years, knowing at the same time that my cancer might not be that bad and I may have a long, relatively normal life. I will know more a few months from now. In the mean time, I'm content planning my life as if I will be completely fine (which is certainly may be the case), and if I get sick along the way I'll re-evaluate my situation if the need arises. For now, I'm quite positive. If anyone were to get a one in a million disease and get through it unscathed, it would be me!

I've had some interesting medical experiences over the last few months. The left image is my PET CT, which depicts active metabolism. I was injected with radioactive glucose, and the tissues that work hard absorb it and appear as "hot" on the image. I was lying down (for about 30 minutes), so the only active organs should be my heart and brain. The kidneys/bladder are illuminated because it filtered some of the material from the blood. Actively growing tumors also uptake glucose, and are labeled on this image. While the majority of my tumors are benign and slow growing, this image shows a few rapidly growing tumors: one on my upper right leg (which was removed with surgery #1, second picture), one small one at the base of my neck (which was removed with surgery #2, third picture), and a few scattered ones under each of my arms. The active ones were removed to aid in diagnosis, and it's not feasible to remove all of the affected lymph nodes. The last picture shows me after my most recent surgery coming out of anesthesia. I don't even remember it being taken - I was pretty out of it at the time, as you can infer from the photo :)

Many people have asked how I have been doing since Angelina died. Unexpectedly losing a spouse at any age is difficult, but at such a young age (I was 25, she was 24, we were married for 4 years) it's even harder to rationalize sometimes. No words I write can even begin to describe the complex array of emotions I carry. Although I wish things had turned-out differently, I still feel fortunate to have had Angelina in my life, and I know unquestionably that I am a better person for having known her, and am thankful we got to share as much as we did. The picture on the right is the last one I have of us together. (I'm in the blue shirt, she's in the black shirt). It was taken about two weekends before she died. We went with a group of my dental school classmates to Islands of Adventure (part of Universal Studios) in Orlando. If you had told me then that I would be a widower in a couple weeks, I couldn't have even begun to comprehend it. I will always miss her, but I know that she would not want me to destroy my life because she is gone. In a note she wrote for me the day she died, she said "I love you, Scott, more than you will ever know." It's a phrase I remember and repeat in my mind every day, and it's given me comfort over the last several months. I know that I will always carry part of her with me.

Several people have e-mailed me in concern due to the fact that I had stopped posting over the last few months. Again, I was surprised and honored the unexpected support I've been getting over the internet from people I don't really even know. The following quote is one that came in this morning, "It has been a while since I have last visited and I really hope you’re doing OK since your last post. I can’t pretend to remotely know how you feel, even with the time that has passed since then. Just wanted to say I wish you well and miss your posts. All I can say is that I know that there have been periods of time in my life where I put down the soldering iron due to life… even for a couple of years. But, I always come back around because its part of who I am… and I hope it will be for you as well. --Jeremy"

The truth is, when Angelina died, life stopped. I stopped answering email, I stopped adding to my website, I stopped making phone calls, I even distanced myself from my own family for a while. Slowly, one by one, I'm resuming these activities. A few months ago, I unpacked my electronics workstation in my new apartment. It was a little premature, as I only worked at my station 1 day and took a few more months before I came back to it, but now it's a weekly process. For a long time I felt guilty even thinking about picking-up my silly projects again. I felt that, after everything she and I had gone through, it seemed fickle. With a little time and some self-reflection, I realized that Angelina encouraged me to do these things throughout our marriage. I remember her telling me that she went to college and bragged "my husband is on Hackaday". I told her that my academic publications on PubMed are more impressive, and I'll always remember her response: "Yeah, but you get more excited every time you make it on hack-a-day". I remember this and remind myself that, if she were here, I think she'd still continue to encourage me to do what I enjoy. While silly little projects might not seem significant, they do make me happy, and I think she would be proud of me for working on them.

Angelina left a few special reminders on my workbench. A few months after she died, and as I would unpacking my workstation again, I noticed a carving she made in my workbench. I almost threw away this table when I moved, and I'm so glad I didn't. I think Angelina carved it with a car key, probably on the day this post was made, when I left her unattended for a while soldering at my station. I also found a message she wrote on my roll of solder. I didn't remember seeing it before, so I imagine it was something she wrote the last few days she was alive. It is really special to me.

One of the things I've done that's really helped me a lot is to get out of my comfort zone a little bit and go places and do things I've never done before, often on a whim. This has led me to have a lot of a lot of fantastic experiences, and give me some new things to occupy myself with and remind me that there's still a lot of life out there left to live. Over the last several months, I tried to minimize the amount of time I spent doing things I'd done before. I noticed that the more time I spent doing the same old things, the more I felt like a part of me was missing, and the worse I felt. Changing scenery and being in new places, it felt less like something was missing, and began letting me establish the feeling of being okay on my own. I stayed away from Gainesville as much as I could, stayed away from family as much as I could (sorry mom and dad if you read this one day), and kept the amount of time I spent interacting with my old friends from dental school to a minimum. For some reason, nothing made me feel worse inside than being around my old environment, and avoiding it for a while was my way of trying to heal. For several months, this behavior was the only thing that made me feel better. Luckily, within the last few weeks, things have started to settle down, and I'm a little more comfortable settling-back into some of my old environments. I'm going to toss-in a collection of random photos from the last several months. I'm not going to describe them in detail - it's more an indication that yes, I'm alive, and yes, I'm getting out there a little. A few days after my wife died, I got a new apartment and moved in with a dental school classmate. His name is Ray, and he's a pretty cool guy. I'm very lucky to have him. He moved out of his old apartment and into my apartment in less than a week's notice.

I marched in the UF homecoming parade with the University of Florida Gator Amateur Radio Club.

I participated in the "out of the darkness" walk for suicide awareness sponsored by the Suicide Survivors of Northeast Florida group.

I operated as net control for Gator Amateur Radio Society during the 5 points of life "relay for life" marathon (official site).

I practiced advanced suturing techniques utilizing a pig jaw. I actually messed it up pretty badly... oops? Next time I'll do it on a person. Scary, right?

Here's a picture with me beside my friend Bill, W4HBK. He and his wife were wonderfully kind in offering me a place to stay over a portion of the Christmas break. Bill is a fellow QRSS'er (who mans the Pensacola Snapper) and we had a great time working with antennas, looking at QRP equipment, and testing 160M WSPR. It seemed like a random thing for me to do (drive 6 hours to spend several days with a family I hadn't met before), but was a wonderful experience and I am thankful to both of them.

I started getting into electronics again a couple months ago. I learned how to etch PCBs at home (using the toner transfer method with hot ferric chloride) and am making digital QRSS transmitter designs. My signal is the one that looks drunk, swerving all over the QRSS road. The picture of me by a fence was in Ocala at a gokart racetrack. It was the week I found out I was sick. Also pictured is my QRSS transmitter, a somewhat novel design using no potentiometers. The oscillator is a 74HC240 with a varactor diode, allowing frequency adjustment via a potentiometer, and a lowpass-filtered PWM line from the microcontroller to provide modulation. The degree of modulation is adjustable via the second potentiometer.

I get my hair cut in my friend's kitchen. His name is Don and he is a dental student too. My hair cuts are $5.

I operated the W4DFU radio station during the CQWW contest.

I also visited a museum. Can you believe I went my entire life without ever actually seeing a dinosaur skeleton in person?

The photo from space is the result of a a successful retrieval of a camera that was launched back in August. It was placed on a high altitude balloon launched the same day Angelina and I drove to Orlando for the weekend (the next day the photo of us above was taken). It took photos as it ascended, then landed, and it was lost for several months. Some boys playing in the woods found it and gave it to their mom, who contacted us. The photos are pretty impressive, and I'll post details in a future entry.

This picture of me sitting on the couch is from Christmas at a big family get-together. That was an experience. Like I mentioned above, my wife's death hurts the most when I'm in a place where I feel she should be. When I do "old things", and go to the places we used to go together, and be in situations where we always were together, her absence is unignorably overwhelming and painful. I imagine holidays will continue to hurt for a while. I don't know how I got this photo, did my sister take it? Anyhow, that's how that goes.

Transitioning back into internet productivity, I will share some code which I utilized to create today's entry. I wanted to rapidly browse through numerous high resolution images to choose which ones to share, but pressing the left and right arrows was too slow (some of the large images took 5+ seconds to load). I therefore copied all of the images (*.jpg) created within the last 6 months and copied them into a single folder. I whipped-up a script to use ImageMagick's convert feature (which is available for linux and windows) to create 300px wide thumbnails and place them on a static HTML page for viewing in a browser. Each thumbnail was clickable, revealing the original, large image. Below is the script I used to do this.

import os
out="<html><body>"
fnames=os.listdir("./")
fnames.sort() # alphabetize them
for fname in fnames:
if ".jpg" in fname or ".JPG" in fname:
if "sml_" in fname: continue
cmd="convert -resize 300 %s sml_%s"%(fname,fname)
print cmd #note that this requires ImageMagik installed
os.system(cmd)
out+='<a href="%s">'%(fname)
out+='<img src="sml_%s"></a><br>'%(fname)
out+='%s<br><br><br>n'%(os.path.split(fname)[1])
out+="</body></html>"
f=open("pics.html",'w')
f.write(out)
f.close()
print "DONE"

What do I plan to do from here? I'm starting my PhD program in August, and I plan to hit it hard. I feel lucky that I have the opportunity to study biomedical science again. I'm holding my breath for it to start, and am looking forward to having something academically and intellectually challenging to devote myself to. I plan to continue making my electronics and programming projects, and publishing them here on my website. If my health changes, it all might change, but I'm holding out that I'll be okay. All in all, I've lived through an unbelievably rough year, but I look forward to getting back into the game.

Markdown source code last modified on January 18th, 2021
---
title: Resuming Life
date: 2012-06-13 10:41:33
---

# Resuming Life

__I'm staring deeply into a large, ominous, empty white text box on my screen as a small vertical text cursor blinks, staring back at me.__ I faintly remember writing my first blog entry eleven years ago (to the week), as a 15 year old kid typing on a keyboard in the middle of the night. Every time I log-in to write on my website, I see the same cursor, monotonous in its dependable, unvarying appearance.  What does the cursor see in me? Definitely not the same person it saw the last time I logged-in. What collection of words can even begin to describe the jumble that's in my head? My name is Scott Harden, my future is changing before my eyes, and I've chosen to use this website to continue to document my life as it unfolds.

__It's been 298 days since I've last written.__ For anyone who's been through a hard time, part of getting better is acting like ones self again. For me, that's doing the things that I used to do: designing circuits, writing code, building radios, and documenting my projects on my website. Me, starting to write again - forcing myself to write again - is a step in a positive direction, and an indication that I am starting to be okay. My intention is to resume building and sharing projects on this website like I used to.

__I feel it is important to address some of the recent changes in my life in a clear manner.__ I don't want to just resume posting code and pictures of circuits all the sudden without acknowledging the serious issues that I've dealt with and am continuing to deal with. It's important that it's obvious that (a) these things happened, (b) I'm working to be okay with them, and (c) I'm not ignoring them. I have noticed that ignoring serious issues by pretending that they do not exist is one of the most dangerous and destructive coping mechanisms a person can exhibit. People behave this way around me often, but I, in an effort to improve my situation, refuse to ignore my challenges. I will attempt to describe a few of the highlights of the last several months of my life. It's certainly not an exhaustive list, but it touches on a few of the significant experiences I have gone through, changes which have affected me, and a few of the events that made me happy since I last wrote here.

<div class="text-center img-border">

[![](12-2_thumb.jpg)](12-2.jpg)

</div>

__I began a new [Ph.D. program in Neuroscience](http://idp.med.ufl.edu/about/neuroscience/) through the Interdisciplinary Program in Biomedical Science through the College of Medicine at the University of Florida.__ I am currently in my 4th year of dental school (in my 10th year of college currently), and I'm considering starting a new program from scratch. Rather than throw-away my dental degree (which I've been working on for several years and spent quite a lot of money to pursue), I am seeking a combined D.M.D/Ph.D. degree. This will allow me to graduate with a degree in dental medicine (D.M.D.) through the UF College of Dentistry about the same time I get my Ph.D. in Neuroscience through the UF College of Medicine. I begin this August, and I couldn't be more excited. As my [Google Scholar author page](http://scholar.google.com/citations?hl=en&user=egCaj-AAAAAJ&oi=sra) reports, I've had excellent research experience in the past, and I'm eager to begin life again as a biomolecular graduate student. I have yet to decide the specific direction of my research, but if I could do anything in the world, I would try to find a project which lets me dip into [bioinformatics](http://en.wikipedia.org/wiki/Bioinformatics).

<div class="text-center img-border">

[![](2012-04-23_08.57.33_thumb.jpg)](2012-04-23_08.57.33.jpg)

</div>

__It looks like I'm kind of sick.__ To make a long story short, I'm in a strange diagnostic limbo where it's looking like I may have a pretty serious, rare, and somewhat difficult to diagnose form of cancer (stage 4 [peripheral T-cell lymphoma](http://en.wikipedia.org/wiki/Peripheral_T-cell_lymphoma-Not-Otherwise-Specified)), but at the same time it seems there is a chance it could be a weird, rare ailment that's not as serious (an obscure autoimmune condition or abnormal presentation of chronic infection). The type of cancer it is currently proposed to be is pretty bad, and people usually don't live too long after their diagnosis. Intriguingly, my symptoms and clinical presentation don't reflect the rapidly destructive nature commonly associated with this disease, leaving open the possibility that it might not be that form of cancer after all. I have hard, enlarged lymph nodes (with abnormal histology demonstrated by 1 needle biopsy and 2 separate surgeries) in all quadrants of my body, and have a lot of fatigue (which I combat with large volumes of coffee). Other than that, I'm relatively normal (physically, at least). The picture to the right is me on the first visit to the oncologist. I didn't take it too seriously. I kept thinking (and still do to some degree) there's no way it could be that bad.  I mean, who my age gets sick like this? And right on the heels of losing my wife? It's too coincidental, it can't be that serious! Realistically we still don't know for sure exactly what it is, and it's too early to tell how this will affect my life. It's a strange experience grappling with the idea that I might only live a few more years, knowing at the same time that my cancer might not be that bad and I may have a long, relatively normal life. I will know more a few months from now. In the mean time, I'm content planning my life as if I will be completely fine (which is certainly may be the case), and if I get sick along the way I'll re-evaluate my situation if the need arises. For now, I'm quite positive. If anyone were to get a one in a million disease and get through it unscathed, it would be me!

<div class="text-center img-border img-small">

[![](4-pet-ct-too_thumb.jpg)](4-pet-ct-too.jpg)
[![](IMG_5851_thumb.jpg)](IMG_5851.jpg)

</div>

__I've had some interesting medical experiences over the last few months.__ The left image is my [PET CT](http://en.wikipedia.org/wiki/PET-CT), which depicts active metabolism. I was injected with radioactive glucose, and the tissues that work hard absorb it and appear as "hot" on the image. I was lying down (for about 30 minutes), so the only active organs should be my heart and brain. The kidneys/bladder are illuminated because it filtered some of the material from the blood. Actively growing tumors also uptake glucose, and are labeled on this image. While the majority of my tumors are benign and slow growing, this image shows a few rapidly growing tumors: one on my upper right leg (which was removed with surgery #1, second picture), one small one at the base of my neck (which was removed with surgery #2, third picture), and a few scattered ones under each of my arms. The active ones were removed to aid in diagnosis, and it's not feasible to remove all of the affected lymph nodes. The last picture shows me after my most recent surgery coming out of anesthesia. I don't even remember it being taken - I was pretty out of it at the time, as you can infer from the photo :)

<div class="text-center img-border">

[![](IMG_0440_thumb.jpg)](IMG_0440.jpg)

</div>

**Many people have asked** how I have been doing since Angelina died. Unexpectedly losing a spouse at any age is difficult, but at such a young age (I was 25, she was 24, we were married for 4 years) it's even harder to rationalize sometimes. No words I write can even begin to describe the complex array of emotions I carry. Although I wish things had turned-out differently, I still feel fortunate to have had Angelina in my life, and I know unquestionably that I am a better person for having known her, and am thankful we got to share as much as we did. The picture on the right is the last one I have of us together. (I'm in the blue shirt, she's in the black shirt). It was taken about two weekends before she died. We went with a group of my dental school classmates to Islands of Adventure (part of Universal Studios) in Orlando. If you had told me then that I would be a widower in a couple weeks, I couldn't have even begun to comprehend it. I will always miss her, but I know that she would not want me to destroy my life because she is gone. In a note she wrote for me the day she died, she said "I love you, Scott, more than you will ever know." It's a phrase I remember and repeat in my mind every day, and it's given me comfort over the last several months. I know that I will always carry part of her with me.

__Several people have e-mailed me in concern due to the fact that I had stopped posting over the last few months.__ Again, I was surprised and honored the unexpected support I've been getting over the internet from people I don't really even know. The following quote is one that came in this morning, "_It has been a while since I have last visited and I really hope you’re doing OK since your last post. I can’t pretend to remotely know how you feel, even with the time that has passed since then. Just wanted to say I wish you well and miss your posts. All I can say is that I know that there have been periods of time in my life where I put down the soldering iron due to life… even for a couple of years. But, I always come back around because its part of who I am… and I hope it will be for you as well. --Jeremy_"

__The truth is__, when Angelina died, life stopped. I stopped answering email, I stopped adding to my website, I stopped making phone calls, I even distanced myself from my own family for a while. Slowly, one by one, I'm resuming these activities. A few months ago, I unpacked my electronics workstation in my new apartment. It was a little premature, as I only worked at my station 1 day and took a few more months before I came back to it, but now it's a weekly process. For a long time I felt guilty even thinking about picking-up my silly projects again. I felt that, after everything she and I had gone through, it seemed fickle. With a little time and some self-reflection, I realized that Angelina encouraged me to do these things throughout our marriage. I remember her telling me that she went to college and bragged "my husband is on Hackaday". I told her that my academic publications on PubMed are more impressive, and I'll always remember her response: "Yeah, but you get more excited every time you make it on hack-a-day". I remember this and remind myself that, if she were here, I think she'd still continue to encourage me to do what I enjoy. While silly little projects might not seem significant, they do make me happy, and I think she would be proud of me for working on them.

<div class="text-center img-border img-medium">

[![](angelina_carve_thumb.jpg)](angelina_carve.jpg)

</div>

<div class="text-center img-border img-small">

[![](angelina_solder_thumb.jpg)](angelina_solder.jpg)

</div>

<div class="text-center img-border img-medium">

[![](angelina_soldering_thumb.jpg)](angelina_soldering.jpg)

</div>

__Angelina left a few special reminders on my workbench.__ A few months after she died, and as I would unpacking my workstation again, I noticed a carving she made in my workbench. I almost threw away this table when I moved, and I'm so glad I didn't. I think Angelina carved it with a car key, probably [on the day this post was made](http://www.swharden.com/blog/2011-02-20-rf-workshop-launched/), when I left her unattended for a while soldering at my station. I also found a message she wrote on my roll of solder. I didn't remember seeing it before, so I imagine it was something she wrote the last few days she was alive. It is really special to me.

<div class="text-center img-border">

[![](09_thumb.jpg)](09.jpg)

</div>

__One of the things I've done__ that's really helped me a lot is to get out of my comfort zone a little bit and go places and do things I've never done before, often on a whim. This has led me to have a lot of a lot of fantastic experiences, and give me some new things to occupy myself with and remind me that there's still a lot of life out there left to live. Over the last several months, I tried to minimize the amount of time I spent doing things I'd done before. I noticed that the more time I spent doing the same old things, the more I felt like a part of me was missing, and the worse I felt. Changing scenery and being in new places, it felt less like something was missing, and began letting me establish the feeling of being okay on my own. I stayed away from Gainesville as much as I could, stayed away from family as much as I could (sorry mom and dad if you read this one day), and kept the amount of time I spent interacting with my old friends from dental school to a minimum. For some reason, nothing made me feel worse inside than being around my old environment, and avoiding it for a while was my way of trying to heal. For several months, this behavior was the _only_ thing that made me feel better. Luckily, within the last few weeks, things have started to settle down, and I'm a little more comfortable settling-back into some of my old environments. I'm going to toss-in a collection of random photos from the last several months. I'm not going to describe them in detail - it's more an indication that yes, I'm alive, and yes, I'm getting out there a little. A few days after my wife died, I got a new apartment and moved in with a dental school classmate. His name is Ray, and he's a pretty cool guy. I'm very lucky to have him. He moved out of his old apartment and into my apartment in less than a week's notice. 

<div class="text-center img-border">

[![](01_thumb.jpg)](01.jpg)

</div>

__I marched in the UF homecoming parade__ with the University of Florida [Gator Amateur Radio Club](http://gatorradio.org/). 

<div class="text-center img-border">

[![](02_thumb.jpg)](02.jpg)

</div>

__I participated in the "out of the darkness" walk for suicide awareness__ sponsored by the [Suicide Survivors of Northeast Florida group](http://www.neflsurvivors.org/community-walk.aspx). 

<div class="text-center img-border">

[![](03_thumb.jpg)](03.jpg)

</div>

**I operated as [net control](http://en.wikipedia.org/wiki/Amateur_radio_net) for [Gator Amateur Radio Society](http://www.gars.net/)** during the [5 points of life "relay for life"](http://www.wcjb.com/local-news/2012/02/5-points-life-marathon-relay) marathon ([official site](http://www.fivepointsoflife.com/)).

<div class="text-center img-border">

[![](10_thumb.jpg)](10.jpg)

</div>

__I practiced advanced suturing techniques utilizing a pig jaw.__ I actually messed it up pretty badly... oops? Next time I'll do it on a person. Scary, right? 

<div class="text-center img-border">

[![](14_thumb.jpg)](14.jpg)

</div>

**Here's a picture with me beside my friend Bill, W4HBK.** He and his wife were wonderfully kind in offering me a place to stay over a portion of the Christmas break. Bill is a fellow QRSS'er (who mans the [Pensacola Snapper](http://pensacolasnapper.blogspot.com/)) and we had a great time working with antennas, looking at QRP equipment, and testing 160M WSPR. It seemed like a random thing for me to do (drive 6 hours to spend several days with a family I hadn't met before), but was a wonderful experience and I am thankful to both of them.

<div class="text-center img-border">

[![](26_thumb.jpg)](26.jpg)

</div>

<div class="text-center img-border img-micro">

[![](25_thumb.jpg)](25.jpg)
[![](27_thumb.jpg)](27.jpg)
[![](28_thumb.jpg)](28.jpg)
[![](30_thumb.jpg)](30.jpg)
[![](24_thumb.jpg)](24.jpg)
[![](31_thumb.jpg)](31.jpg)
[![](011_thumb.jpg)](011.jpg)

</div>

__I started getting into electronics again a couple months ago.__ I learned how to etch PCBs at home (using the toner transfer method with hot ferric chloride) and am making digital QRSS transmitter designs. My signal is the one that looks drunk, swerving all over the QRSS road. The picture of me by a fence was in Ocala at a gokart racetrack. It was the week I found out I was sick. Also pictured is my QRSS transmitter, a somewhat novel design using no potentiometers. The oscillator is a 74HC240 with a varactor diode, allowing frequency adjustment via a potentiometer, and a lowpass-filtered PWM line from the microcontroller to provide modulation. The degree of modulation is adjustable via the second potentiometer.

<div class="text-center img-border img-medium">

![](2011-12-04_12.55.16.jpg)

</div>

I get my hair cut in my friend's kitchen. His name is Don and he is a dental student too. My hair cuts are $5. 

<div class="text-center img-border img-small">

[![](IMG_0284_thumb.jpg)](IMG_0284.jpg)

</div>

I operated the W4DFU radio station during the CQWW contest. 

<div class="text-center img-border img-medium">

[![](DSC_6218_thumb.jpg)](DSC_6218.jpg)

</div>

I also visited a museum. Can you believe I went my entire life without ever actually seeing a dinosaur skeleton in person? 

<div class="text-center img-border">

![](space.jpg)

</div>

__The photo from space__ is the result of a a successful retrieval of a camera that was launched back in August. It was placed on a high altitude balloon launched the same day Angelina and I drove to Orlando for the weekend (the next day the photo of us above was taken). It took photos as it ascended, then landed, and it was lost for several months. Some boys playing in the woods found it and gave it to their mom, who contacted us. The photos are pretty impressive, and I'll post details in a future entry. 

<div class="text-center img-border img-small">

[![](IMG_6603_thumb.jpg)](IMG_6603.jpg)

</div>

**This picture** of me sitting on the couch is from Christmas at a big family get-together. That was an experience. Like I mentioned above, my wife's death hurts the most when I'm in a place where I feel she should be. When I do "old things", and go to the places we used to go together, and be in situations where we always were together, her absence is unignorably overwhelming and painful. I imagine holidays will continue to hurt for a while. I don't know how I got this photo, did my sister take it? Anyhow, that's how that goes. 

<div class="text-center img-border">

[![](2012-03-14-23.03.53_thumb.jpg)](2012-03-14-23.03.53.jpg)

</div>

__Transitioning back into internet productivity, I will share some code__ which I utilized to create today's entry. I wanted to rapidly browse through numerous high resolution images to choose which ones to share, but pressing the left and right arrows was too slow (some of the large images took 5+ seconds to load). I therefore copied all of the images (*.jpg) created within the last 6 months and copied them into a single folder. I whipped-up a script to use ImageMagick's convert feature (which is available for linux and windows) to create 300px wide thumbnails and place them on a static HTML page for viewing in a browser. Each thumbnail was clickable, revealing the original, large image. Below is the script I used to do this.

```python
import os
out="<html><body>"
fnames=os.listdir("./")
fnames.sort() # alphabetize them
for fname in fnames:
if ".jpg" in fname or ".JPG" in fname:
if "sml_" in fname: continue
cmd="convert -resize 300 %s sml_%s"%(fname,fname)
print cmd #note that this requires ImageMagik installed
os.system(cmd)
out+='<a href="%s">'%(fname)
out+='<img src="sml_%s"></a><br>'%(fname)
out+='%s<br><br><br>n'%(os.path.split(fname)[1])
out+="</body></html>"
f=open("pics.html",'w')
f.write(out)
f.close()
print "DONE"
```

__What do I plan to do from here?__ I'm starting my PhD program in August, and I plan to hit it hard. I feel lucky that I have the opportunity to study biomedical science again. I'm holding my breath for it to start, and am looking forward to having something academically and intellectually challenging to devote myself to. I plan to continue making my electronics and programming projects, and publishing them here on my website. If my health changes, it all might change, but I'm holding out that I'll be okay.  All in all, I've lived through an unbelievably rough year, but I look forward to getting back into the game.

<div class="text-center img-border">

[![](DSC_5878_thumb.jpg)](DSC_5878.jpg)

</div>
Pages