STM software


I finally got around to finishing up the Teensy software for my STM! The Teensy controls scanning, PI control of the Z-axis piezo, sigma-delta modulation of the scanner DAC outputs, and serial communications with a PC. I also wrote a C# program (screenshot above) that receives the serial data sent by the Teensy and displays the images line by line, and can set the scan parameters.

Here are the files:

There are simple libraries for the DAC8814 and LTC2623-16 included with Teensy software. Put them in your \Arduino\libraries folder. The PC software contains a .exe file and .exe.config file. Just put them in the same folder somewhere.

I’ll do a more detailed writeup on this later, but here’s a brief summary of how it works: the Teensy uses a timer to call a function at a regular time interval. This function increments the scan, performs PI calculations to update the Z axis, and performs sigma-delta modulation of the scanner DACs. Since the scanning probe is a (sharp, fragile) solid object, it’s velocity needs to be controlled at all times. If it moves too fast, it will likely crash into something, so the tip scans in a zig-zag pattern rather than a traditional raster (as in a CRT or SEM for example). Since the STM is always incrementing the scan at the same time interval, doing a slower scan will acquire more data. All data acquired between pixels is averaged, so you’ll get less noise in a slower scan. Once a line of the image has been scanned in one direction and re-scanned in the other direction, the Teeny sends the Z data and error signal data over USB.

If you need to invert the Z-axis signal, find the “#define INVERT_Z true” at the top of the Teensy code and change it to false.

The PC software receives the data, does some basic processing, and adds it to the images on the screen. The left image is the topography (Z signal) and the right image is the error signal. The error signal looks like the gradient of the Z signal and has more high-frequency content. The topography data is displayed line by line in the graph at the bottom of the window. The red curve corresponds to the most recent scan line, and the blue curve is the same line scanned in the opposite direction. Ideally, these curves should be identical, but the agreement will never be perfect due to piezo hysteresis and things like that. If they don’t agree at all or show oscillations, try lowering the line rate, proportional and/or integral gains. For scans larger than ~500 nm or so, you’ll probably want to scan at ~0.5-2 Hz or so. For scans < 10 nm, you’ll want to go much faster to minimize thermal drift effect, ~10 Hz or more. You can also decrease the number of pixels to increase the speed.

Connect a LED to pin 0 on the Teensy. This is used to indicate serial communication is active. Connect another LED to pin 1. This one lights up when tunneling is achieved.

To use the software:

  1. Upload the code to the Teensy
  2. Turn the microscope on and start STM.exe
  3. Select the Teensy’s COM port from the list
  4. Do coarse approach until tunneling is achieved
  5. Press “Engage tip”. All this does at the moment is start the scan. You should see data coming in.

Images are saved as 16-bit, multi-page, uncompressed tiffs whenever a scan completes. You’ll want to use a program like Gwyddion to process the images, otherwise they’ll mostly just look gray. To view the error signal image (page 2 of the tiff), load the file into Gwyddion, click “Info” -> “Show Data Browser”, and check the box next to the error signal image.

There are still some issues in the PC software but it should work for the most part. It crashes on exiting, and I think I know what might be causing this but haven’t managed to fix it yet. I’ve also noticed that scan lines in the saved images are sometimes missing. CPU usage tends to be high when scanning at higher line rates. I’ll hopefully have a fix within a week or so and will update this post once I do.

If you find any other issues or have suggestions for improvements, please let me know in the comments!


12 thoughts on “STM software

  1. Dan,
    Great work. I am wondering how your STM will work with biological specimens? I would love to get up close and personal with some nematodes. As usual buying my own STM is way out of the question. I think i can afford your design.
    Jon S. Waldport Oregon


    • Hi Jon,

      Sorry for the late reply! Unfortunately STM isn’t suitable for imaging something the size of a nematode. The scan range of an STM is typically only ~1-10 um or so. The sample also needs to be conductive (or a single molecular insulating layer on a conductive surface). Sounds like an optical microscope of SEM would be more useful.



  2. Hi Dan,
    I just wanted to take a moment to thank you for documenting your work on your STM. I’m happy to say that I just got mine up and running too. I made the scanner several years ago, and it’s just been sitting on my desk until this week. I’m imaging gold plated connector contacts. It’s amazing how well this fairly simple machine works.


      • I wanted to share some results and attach pictures to my post, but I don’t see that option. Any way to do that?
        Also, I was wondering if you could share typical scope captures of your Z and error signals during scanning. My setup is having some trouble keeping the error steady during scans — especially the faster scans.


      • Maybe upload them to an image/file sharing site and share a link?
        The image at the top of this post is an example of a good Z trace and retrace. You can see the red and blue lines match up very well. That’s what you want to see. Don’t worry too much if the error signal seems to be jumping around a lot.
        For faster scans you’re ultimately limited by the scanner rigidity, and I find that for a ~1 um scan I get good images around a 1 Hz line rate or lower. Keep in mind most of the images I’ve posted here are of very smooth samples, so you might find you need to slow it down a bit. Try 0.5 Hz, and set the P-gain to zero to start, then adjust the I-gain to maximize image detail. If you start seeing oscillations in the tunneling current signal, lower the I-gain. If the image is a complete mess, the I-gain might be way too low which can cause a crash, and you might need to change tips.


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s