STM software

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!

38 thoughts on “STM software

  1. Hi Dan,

    Thanks for sharing this amazing project. Its really fun. For the electronics PCB board, did you assemble the components by yourself or did you use a vendor to assemble them for you? I was planning to use JLCPCB’s SMT service but they do not assemble all the components used in your schematic. I want to use reflow soldering using stencil only as the last resort. Please advise.

    Thanks
    Aksh

    Like

    • Hi Aksh,

      I hand-soldered everything, but I’ve made a few copies of the board with a stencil and reflow soldering in a toaster oven. I’ve used Macrofab’s assembly service before for another project, and found them quite easy to use.

      Cheers,
      Dan

      Liked by 1 person

    • Hi Vishnu,
      I happen to know most of the authors on that paper from McGill Physics, and have used the AFM in that paper several times 🙂
      Like in the paper, you’d need an AFM with a conductive tip to replicate their pore formation. Since silicon nitride is an insulator, an STM can’t detect its surface. You could form small indents in a conductive surface by plunging the tip a short distance into the sample but to form pores through a membrane in this way you’ll likely need an AFM.
      Dan

      Like

      • Thank you, Dan. I just had one more quick query. What positional resolution along XY could you achieve using simple piezo buzzers?

        Like

      • The resolution can be subatomic, as long as you have good vibration isolation. A buzzer is more sensitive to vibrations than a tube scanner or piezo stack, so it’s more challenging but doable.

        Like

  2. Hey Dan! Can you share your rawdata from your scans you have done with your STM so that we in our group project can test our image processing? Thank you for the inspiration.

    Like

  3. Hello Dan,
    First I need to thank you for sharing such an awesome project with so much detail. I have been so excited about it that it has been constantly running on my mind for weeks, and now that the summer break has come I will attempt this project with one or two friends. I had a small question regarding the software you shared. Is this version of software completely compatible with your previous electronics setup? I want to do my own system and I felt like until then a temprary system on a breadboard would be ideal. If the software doesn’t have any difference I would prefer to start with the old electronics guide that you provided.
    Thank you in advance for your attention and sorry if I asked an obvious question due to my ignorance

    Like

    • Hi Zübeyir,
      Unfortunately the software won’t work with my older electronics setup. You would need to modify the Teensy code to work with the different data converters. Alternatively, you could build the newer electronics design on a breadboard instead of a PCB, following my schematic.
      Cheers,
      Dan

      Like

      • Thank you very much for your reply! We decided to use Veroboard to follow your new circuit diagram. I will ask one or two more questions in related pages, but they are just some brainstorming questions so feel free to not respond or respond really shortly.
        Again thank you for such an awesome DIY site for such a cool project

        Like

    • This version of the software is for use with manual approach only. The feedback loop is always active. You have to manually bring the tip into tunneling and then click “Engage tip” in the software to start the scan. I had planned on adding motorized coarse approach to this software but ended up rewriting the whole thing, and haven’t published it here yet.

      Like

    • Very nice! The tunneling current images are not blurry at all, they look great! If you want sharper topography images, you can try reducing the scan speed and maybe also the resolution, and taking a smaller scan.

      Like

  4. Hi Dan,
    Great work on that project!
    We would like to know if there is any other option instead of using the DAC8734, just because it has been so hard to find for us.

    Like

    • Hi Genis,
      Thanks! Yes there are many other options that will work. I use the DAC8814 in my current design for example, it’s shown in the schematics on the electronics page.

      Like

      • We used the DAC8734 and the ADS8517 in our STM, we tried to give a try with your software but as expected it did not work at all. We believe that by changing the libraries and changing some sentences should be enough, is there something else we must change?

        Like

      • You’ll have to modify the DAC8814 and LTC2326-16 libraries that are included with the Teensy STM firmware (DAC8814.cpp, DAC8814.h, LTC2326_16.cpp, and LTC2326_16.h), to work with the DAC8734 and ADS8517 SPI protocols instead. These files are pretty simple so it shouldn’t be too much trouble. Let me know if you run into issues.

        Like

  5. 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

    Liked by 1 person

    • 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.

      Best,
      Dan

      Like

  6. 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.

    Like

      • 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.

        Like

      • 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.

        Like

Leave a comment