Electrical engineering best practices for the Mac

Electrical engineering best practices for the Mac.

# Quickly Get to a Digikey Part Info Page

Trust me, this one is going to save you seconds every day...seconds!

I have a tool called Alfred running on all of my Macs, it is similar to the Spotlight tool on OS X except has a few more tricks up its sleeve. Alfred let's you build small applications called workflows to do a variety of things. One of the workflows that I created is to quickly go to the Digikey info page for a component. Here is the workflow:

1. Copy the part number that I'm interested in (⌘-C)
2. Press Ctrl-Shift-D

That's it! After pressing those two key combinations I am instantly taken to the part info page on Digikey.com. Here is what the workflow looks like while you're building it:

You can see that typing the hotkey Ctrl-Shift-D will cause your default browser to open with the Digikey search URL modified to contain the contents of your clipboard.

You can download the workflow here if you are an Alfred user. Or if you can think of another way to do this same thing, simply use the URL: http://www.digikey.com/scripts/dksearch/dksus.dll?vendor=0&keywords=QUERY where you replace QUERY with the contents of your clipboard.

# Arduino, Automator, and Beer

My wife recently gifted me with a brew your own beer kit. Cool, but as I started learning about how to brew this delicious beverage, I realized there was one geeky way to improve the process.

It seems that there are two common mistakes in brewing: unsanitary conditions and improper temperatures. There isn't much an EE can do about the former except use best practices, but the later can certainly be controlled. During the fermentation cycle, it is recommended that the temperature be controlled within the range of 68 to 76° F.

So I threw the fermentor into a cooler, stuck some thermistors on it, and attached an Arduino Uno and Ethernet Shield to measure the temperature. Nothing fancy here and nothing to warrant a posting to a blog about engineering using a Mac.

The interesting part was finding a way to get the status of the thermistors in an accessible way. I tried for a few minutes to get the Arduino to periodically email me the temperatures, but that is frustrating to say the least. I finally settled on the following:

1. Have the Arduino post the temperatures to a website as simple text. Here is that code (shamelessly stolen from various places on the web).
2. Have an Automator app running on a MacBook periodically grab the text from the website
3. Let Automator email me the results

Automator functions similarly to LabView in that you drag and drop building blocks that perform simple functions together and the result of each block is passed to the next block. In this case, I'm simply passing text between each block. But you can pass text files, images, music, etc. It's actually quite powerful and built right into OS X.

Here is a high-level view of the Automator app:

Looking at each step:

1. Run Shell Script - simply runs this bash command echo "http://10.0.1.99". This is the IP address of the Arduino. It feeds the address to the next step.

2. Get Text from Webpage - fetches the contents of the website that the Arduino outputs and passes it to the next step.

3. Run AppleScript - takes the text from the webpage (the temperatures reported by the Arduino), puts them into an email, and sends it to me. Here is the code:

on run {input, parameters}
set recipientName to "Jason"
set theSubject to "Beer: " & item 1 of input
set theContent to "Temperature: " & item 1 of input
set theSender to "myemail@gmail.com"
tell application "Mail"
set theMessage to make new outgoing message with properties {sender:theSender, subject:theSubject, content:theContent, visible:true}
tell theMessage
send
end tell
end tell
return input
end run
4. Pause - simply waits for an hour (I only want to see the temperature every hour).
5. Loop - loops the entire app continuously.

And that's it. It could certainly be more fancy, but it is good enough for my purpose. Building the app is simple too: just drag and drop the building blocks in the order you wish them to run and they will pass the output data from block to block.

So, have a look at Automator for the Mac. It can run shell scripts, Python, Javascript, AppleScript or you can simply use the built-in tools to do things like select a list of PDF files and combine them into one file.

# Creating a Test Log

Whenever I do any sort of testing or debugging, I like to keep a very accurate log of what I'm doing. I've found this to be a really good practice for a few reasons:

1. This gives you a really nice record of events to go back over in case you forget if you tested something or how you tested it. In some ways, it can become a journal of what you did that day.
2. It forces you to be very methodical about your testing procedure. You don't want to change two variables at a time when testing. A step-by-step log puts you in the mindset of doing one thing at a time.
3. It slows you down and forces you to think. The act of writing down what you just did gives your brain some time to process what you just did.
4. It gives you a way of looking back at things so that you can see at what step a problem came up. This is really useful in debugging software or system-level issues.

I have two ways of creating a test log. The first is completely unexciting and we've all been doing it since we were kids. Pen and paper. Or in my case, an Uni Kuru Toga mechanical pencil and a Moleskine Folio Hard Cover 8.25 x 11.75 notebook. Yes, I record test results with a pencil, but don't worry, I have a way of making things permanent. When I'm done with the notebook I rip it apart and put it through a scanner to keep a digital copy. I only use paper when the testing is particularly dirty and I know I would destroy a laptop in the field.

The second is my favorite and involves two really useful pieces of software: DayOne and TextExpander. DayOne is a beautiful journaling app that lets you sync journal entries with Dropbox and I've talked about TextExpander before. DayOne lets you add the current location and weather to any entry, which is perfect for keeping a log of testing.

I have a few TextExpander snippets that I use in order to quickly create my test log and all of them have to do with the date/time:

• ddati will expand to the date and time in a nice format. It looks like this: 2014-10-15-11-50-10
• chma will expand to the date and time and also a text phrase to record that I've made a change. It simply looks like this: 2014-10-15-11-50-40 CHANGE MADE:
• reafch looks similar to chma except that the text phrase indicates that these are the results after a change was made. It looks like this: 2014-10-15-11-52-36 RESULT AFTER CHANGE:
• ddano is also similar except that the text phrase indicates a thought I had or something to note. I use this if there is something interesting going on, but it isn't a result of a change that was made. It looks like this: 2014-10-15-11-53-59 NOTES:

And that's it. Just using those four snippets will help me to quickly create a nice test log. I start every line with one of these timestamp variants and it will generate a file that can be easily parsed later on. You should know that if you want to get the log file out of DayOne, you'll need to export it manually. If you know you'll always need to use the log file somewhere other than copying and pasting it into a larger document, you may want to just use a simple text file instead of DayOne.

# TextExpander

I want to show you how I use TextExpander with the goal of showing you how you can save some time even if you don't write a lot of text.

TextExpander is a utility that runs in the background and looks at what I'm currently typing. If I type a short phrase that I've predefined in TextExpander, it will replace that phrase with something else. For instance, when I type oscope, it is replaced with oscilloscope automatically. Think about how many times you write oscilloscope in your test plan and that alone should be worth the price of the software.

TextExpander also allows for variables. So if I type ddate, I get today's date in the format I like (YYYY-MM-DD). This is especially helpful in naming files for easy sorting later on. You can also use the clipboard as a variable. So you can add the contents of the clipboard to a longer string of text. Or you can manipulate the contents of the clipboard to covert the case or remove all of the formatting.

TextExpander is great for software that is keyboard-driven as well. With Eagle if I want to copy a group of items, that is two commands (copy, then group). So I can either mouse over to the copy icon, click that, then mouse over to the group icon and click that. Or I can type copy%key:enter%group%key:enter%. Or I can use TextExpander and type cpgp and it will enter that string of keystrokes for me. Magic.

You can also ask TextExpander to give you pop-up windows to let you enter values on the fly. So if you wanted to draw a box using the rect(x,y) command, you could have TextExpander open a small window and ask for the x and y values to fill in. David Sparks has a great screencast about this feature.

TextExpander is availble for the Mac and iOS. It is a great tool for EE's even if you don't think you work with text that much.

# You and Your Windows-based Coworkers

Keep in mind that not everyone shares your love of the Mac. If folks find it difficult to work with you because of added friction, you're not going to make any converts either. Here's just a few things to keep in mind when interacting with Windows users.

### Keep Things Simple

If you can share files as plaintext, do that. You can be sure everyone will be able to open and edit a plaintext file.

### Beware of File Conversion

If you have any deliverable documentation like an ICD or User's Manual resist the urge to write it using Pages and just export the finished work as a PDF. Inevitably, someone will want to make some edits later on and they'll be pretty miffed when they find out they can't.

You also want to avoid writing something in Pages and exporting it as a Word document. It might be alright for simple documents, but as soon as you throw your company's formatting into the mix I guarantee it won't export properly and things will look wonky.

Your best bet here is to use whatever program everyone has access to. Microsoft Office for OS X may not be very Apple-like, but at least you can be sure your docs will look the same everywhere.

If you're sending someone a link to a file, remember to include both Linux and Windows link formats. The Windows format looks like "C:\path\to\file" and Linux format is "/path/to/file". And every time you have to reach your finger for that awkward "\" character and you want to mock your Windows counterparts, remember the next piece of advice:

### Be Nice

This is more of a mindset than a tip, but in all seriousness, be kind. Electrical engineering is still primarily a Windows-based profession and you are the outlier. We all want to enjoy our work so you may have to put in the extra effort to reduce some friction. This may mean researching things for your IT department if they don't support Macs on the network. Or taking the extra time to preview a file on a Windows machine before sending it out for review. We're all on the same team and want to do the best work possible with the tools we like using.

If you take a moment to think about how others are going to interact with your work, then hopefully it will be as seamless as possible. The goal here is for people to forget that you're not on a Windows machine, although they may wonder why you don't join in when they gripe about their computer problems.

# Running Windows programs on a Mac

Try as you may, there are just some times when you have to run a Windows-only program on your Mac. This is especially true in electrical engineering where there is a lot of really helpful software that may not run on OS X any time soon. There are a few ways that you can get around this obstacle.

1. Boot Camp
2. A virtual machine running Windows
3. A VNC software suite and access to a computer running Windows

## Boot Camp

Boot Camp is Apple's answer to the Windows-only software problem. It allows you to boot into Windows when you turn on or restart your Mac. It will look and feel just like you are running Windows on a PC. Boot Camp is included with OS X for free, but you will need your own licensed copy of Windows (XP, Vista, 7, or 8).

Pros: free if you own a copy of Windows; Windows has direct access to your Mac's hardware including USB drives, optical drives, microphone, etc.; no new software to learn.

Cons: you loose all of the great features that make Mac OS X such a joy; you have to reboot your Mac every time you want to run software on a different operating system, no shared files between Windows and Mac.

## A virtual machine running Windows

Don't be put-off by the terminology, this is a great way to roll. A virtual machine allows you to run another operating system within your current OS. I use Parallels daily to run Internet Explorer or Visio without having to reboot my Mac. This lets you run Windows programs and Mac programs side by side, almost seamlessly.

Pros: no need to reboot; you can share files between Windows and Mac; Windows has access to your Mac's hardware.

Cons: virtual machine software has a cost; running the VM can be a drain on your battery;

## A VNC software suite and access to a computer running Windows

This last option is probably the most difficult to setup and maintain, but may be good if you only need Windows on the rarest of occasions. You install a VNC server on the Windows PC and a VNC client on your Mac. RealVNC is a good option. Then you open the client on your Mac and remotely connect to the Windows computer.