Wio Terminal Accelerometer in CircuitPython

I’m exploring the Wio terminal so there may be other posts soon as I continue to tinker around with this cool board. I wasn’t finding a good example or tutorial on how to use the built-in LIS3DH accelerometer in CircuitPython, so I did some digging and got this to work:

import adafruit_lis3dh
import digitalio
import board
import busio
import time

int1 = digitalio.DigitalInOut(board.GYROSCOPE_INT)
i2c = busio.I2C(board.GYROSCOPE_SCL, board.GYROSCOPE_SDA)
lis3dh = adafruit_lis3dh.LIS3DH_I2C(i2c, int1=int1)
lis3dh.range = adafruit_lis3dh.RANGE_8_G
for i in range(5):
    print(lis3dh.acceleration)
    time.sleep(5)

This requires a library from the CircuitPython resources, I used Bundle for Version 7.x since that is what I have installed on my Wio Terminal. Once you have that bundle downloaded and unzipped, simply drag the adafruit_lis3dh.mpy file into a lib folder on your Wio drive (mine is called ARDUPY still, even though it is running CircuitPython):

Contents of the Wio drive

Notice that I have some extras from other tinkering, the adafruit_lis3dh.mpy file is the only lib file this example requires. If you are curious about the CMUTypewriter-Regular-70.bdf file, feel free to grab it, and check out adafruit tutorial for how to use bitmapped fonts. I converted a LaTeX font file that I had on my computer to bitmap by following a related adafruit tutorial Custom Fonts for CircuitPython Displays. I like this better than the American Typewriter font, and with the large size, it makes a very readable display (note: only three lines with 7-8 characters each fit on the screen, so it’s not appropriate for all uses).

A huge thanks to Adafruit for all sorts of contributions to the maker landscape. CircuitPython is an awesome way to interact with microcontrollers, and buying adafruit hardware and other products from the shop is a great way to support this work!

Glowforge Aluminum Instrument Panel

I spent some time with the glowforge to test settings for engraving our instrument panels. This is powder-coated aluminum from Hammond. The cases are used in a variety of our projects, but despite cutting holes on the CNC, we haven’t ventured into CNC routing labels and have relied on our tape-based label-maker. It does ok, but laser-engraved labels really up the look. With some time to kill, I ran a few tests on the inside of one panel. The end result is to run with 1000 speed, 50% power, 340 lines-per-inch, and 0.15″ focus height. Continue reading

Pluto SDR (ADALM-PLUTO from Analog Devices)

I picked up an ADALM PLUTO from Analog Devices; a very powerful Software Defined Radio (SDR) for only $99. The cost is low as is the documentation. Many links on Analog site are broken, and to their credit, there are a few comments that “people found these instructions hard to follow, so we are revising them.”

That’s good, but in the meantime, here are the instructions that finally worked for me: at John’s Musings

Bio-Rad Ciphergen PBS-II back to life

That’s a mouthful, but it’s an instrument, for science and stuff. I got a used one from eBay last week, and finally have it set up to where I can actually talk to it over the crude computer interface, it’s been a fun process. I’ll back up: this thing is an analytical instrument from the early 2000s. It is designed to measure the distribution of mass in a sample (such as as a sample of proteins from tissue cells). It does this by blasting the sample with a pulsed UV laser (337 nm, nitrogen), accelerating the charged particles (ions) across a high voltage, and measuring the time it takes them to reach an ion detector a few feet away. The distribution of arrival times is therefore a distribution of charge-mass ratios (a spectrum).

Long story short, it has a whole lot of good physics equipment in it, even if it doesn’t do it’s biology thing very well anymore (though it might…  I don’t have a good sample to test it on). I bought it for the parts, and want to see what it can do. This is an outline of the steps I took to get it working. While it may not apply to anyone else, the tricks are generally useful for hacking on vintage instruments.

This machine originally came with a PC for control, and it communicates via GPIB port. This is not always my favorite platform to work with, but it is here to stay (at least it was in 2000).

I have a prologix USB-GPIB so my first try was to set that up with the machine. It took a while (and a few passes through the manuals) to find the note that the PBSii defaults to address 8. Once that was set correctly, it responded to *idn? with Stanford Research Systems,TOF200,ver045 which was a bit surprising. It turns out SRS was working on a time-of-flight mass spectrometer (similar to this) at that time, and must have been selling time-of-flight boards for OEM use. I pulled out the TOF board to take a look, and noticed that it connects to the master box via a cable labeled “SPI”. Despite being an actual protocol, I think this refers to “Serial Port Interface” as the manual has that phrase in a few locations (but no real information beyond the name). There are a few GPIB commands listed in the service manual, things like how to read and set various registers, but nothing very high-level (the design relies on the software for all of that). I didn’t try those commands right away because without knowing what they did… I’d risk setting the machine into some odd state or enabling a subsystem that I shouldn’t.

fullsizeoutput_2f62

The SRS time-of-flight controller embedded in this instrument. GPIB chip (NAT9914) hiding under the top left ribbon cable.

Talking over GPIB was encouraging, but I still had no control over the vacuum system (or any readings from the gauges and various system status indicators). When it powers on, I could hear valves snapping open (or shut) and the pumps would start up; it clearly had a turn-on sequence and everything at least appeared to be working at this point.

After a few emails to the company, including an initial response to the effect of “that machine has been unsupported for over a decade,” I was sent a zip of the original software utilities. Lesson 1: the sooner you can get to an engineer in the company, the better. Find someone like you who enjoys diving in and isn’t afraid of the hardware-software boundary. Unfortunately, the software didn’t see my USB interface as a GPIB (why would it, its just a serial port). I couldn’t yet use the utility software. Sure, there may be some way to trick it into sending GPIB to the serial port, but a more direct route would be to revive some appropriate-era hardware.

The next step was to track down a PC with a GPIB card capable of running the windows utilities. They were written for Win2000 so I figured anything from NT to XP should work… and maybe even later. I borrowed a dusty XP machine from a colleague’s lab for some debugging. In that era of windows, there is an option for “Remote Desktop” which is nice, so I can check on things from outside the lab. Lesson 2: if you don’t want to be stuck in the same room as the machine for a week, set up VNC, remote desktop, or some other way to remotely check in on it

Fortunately everything fired up without a hitch, and the utility software started reporting status and accepting commands. At first, it reported the MAG gauge (high-vacuum gauge) at 0 volts, and turbo pump speed as LOW. Additionally, the backing valve was showing OPEN even though all valves were listed as commanded CLOSED. This was concerning, but not surprising given that it’s probably been sitting for at least a couple years. I cycled the power and the next time around both gauges were alive, and the turbo pump spun up to report OK. In retrospect, I should have followed the shutdown routine to make sure valves were properly closed and the turbopump was allowed to spin down before anything was vented. It seems to have defaulted ok, and the turbopump took a long (quiet) time to spin down. A good sign given the fact that turbos can be seriously damaged if vented too quickly.

Screen Shot 2018-10-21 at 12.18.58 PM

A screenshot of the utility software reporting the current status.

Now I’m at the hurry-up-and-wait stage of pumping down to 1e-6 Torr at which point I can fire up the high voltage and laser systems. I’ve only worked with a handful of vacuum systems (back in grad school) but I did remember that it’s useful to have a reference pumpdown curve… so I started charting away. This is where Remote Desktop really helps. I’d log in every so often to peek at the reported pressure. After 12 hours, it’s gone from roughing to 5e-6 Torr. The operating target is 1e-6, so we still have a ways to go. The flight tube had been open to atmosphere for who knows how long, so I suspect a bake-out is in order, and likely a replacement seal or two (rubber o-rings have a limited lifespan, especially in surplus storage warehouses).

Overall, it’s pretty cool to have something like this come to life even just to this level. At the very least, I got an operational high-vacuum system for $750 plus freight. Lesson 3: a lot of instrumentation is built from generally-useful parts. Such instruments become useless to the intended users even if only one tiny part stops working. Even worse, they become obsolete only through lack of software support. eBay is your friend, but you may have to battle your business office… mine requires personal payment and will only reimburse after equipment arrives on campus.

I owe a shout-out to Erik Sanchez from PSU who tipped me off on this amazing used-equipment find and sent me many helpful documents. Also thanks to Windell Oskay for a helpful conversation as I was starting out. He spent time as a hardware engineer at SRS, and gave me some insight on their hardware implementation of GPIB (using the NAT9914 chip).

Update: After about 48 hours, it wasn’t going below 3e-6 Torr so I started through the various seals and valves. There are several, all too specific to worry about here, but I cleaned the main sample seal o-ring with isopropyl alcohol, and cleaned out the two valves that vent the flight tube to higher pressures (one to atmosphere, one to the backing pressure). At this point, 12-hours later, it’s down to 1.2e-6 (closer!). I’ll give it a day, and see how it looks. Bottom line, the turbopump seems to be in working order (knock on wood) despite me absent-mindedly venting to atmosphere for a few seconds (doh!).

Projects I’d Love to Do

I’ve neglected this site for a bit, and will try to revive it by dumping the contents of my growing list of things I’d love to do if I could make 24 more hours in the day. Why share this? Because if someone else out there wants to work on one of these too, then that serves as extra motivation for me. Also, putting it out in the universe makes it a bit more real than if it sits in my head all the time. I’ll probably revise and will hopefully provide updates as warranted. These are not things that have to be done for the sake of humanity, or things that would even merit a paper or other substantial scholarship (which is probably why they keep getting pushed further down my list). That doesn’t mean they aren’t worth doing. Some lean toward personal projects, others are obviously aligned with my work. Here goes, in total random order:

  • Build a spatial light modulator from an old projector. Note: this has been done before, but I want one, and it sounds like a really fun project that touches on re-use, optics, electronics, and hacking (four of my favorite things!)
  • Directly image the output of a parametric down conversation crystal. Sure, we’ve seen pictures and this isn’t really new knowledge, but I think it really helps students understand what’s going on if you can watch it live. There are a lot of tricks to get this to work, but doing it on the cheap and easy would be sweet.
  • Demonstrate laser-to-RF mediated by at atomic medium. It’s all just E/M radiation, there has to be a fun demo in here somewhere. Are there four-wave mixing transitions that would generate RF that you could tune a radio to? I’ve yet to check this, but it would be cool if it worked.
  • Get my HAM license. I’ve studied up and everything, but just need to get to an exam session and do it.
  • 3D-print a working external cavity diode laser. I have some partial designs, just need to print and test the darn thing.
  • Part out an old argon laser system. I salvaged a laser slit lamp system from our college of optometry. It has all sorts of fun electronics, lasers, optics, and other parts. It doesn’t work anymore, but lots of it’s parts surely do.
  • Other stuff… to be added when I think of it, I’m sure it’s in my head somewhere.

In the meantime, feel free to comment on any of this. If you’d also like to work on something here, let me know.

Buildings?

This is a very cool visualization, and I will continue to play around and explore various parts of the country. One thing I noticed immediately, due to where I live, was an interesting consequence of the algorithm. According to the model, there are several very large buildings nearby (see the outskirts of Forest Grove in the picture).Screen Shot 2018-10-12 at 5.30.04 PM

There is one cluster in the lower left (near Ritchey Rd) and another in the upper right near Schefflin. These are not really buildings, they are hoop-houses. Structures made of only plastic sheets and a few metal pipes. You could argue this is nit-picking, and I’m fine with that characterization. But I’d love to press the issue and ask what would it take to train a neural network better… so it knows the difference between what you and I would call a building, and what merely looks like a building from space.

To be more clear, here is a picture of the Ritchey Rd area:

And a full-zoom of the satellite image, corresponding to the top left (northwest) portion of the nursery (the NYT article doesn’t zoom in from here):

Screen Shot 2018-10-12 at 5.37.37 PM

Clearly these are structures, but what would be the next step in developing the algorithm to know they aren’t actually buildings (or do you define them as such?). Certainly including some nurseries in the training set would be a first step.

Teaching Quantum Mechanics with Python

I’m excited to announce that I’ll be giving a talk at PyCon 2017, on May 18 in Portland OR. The talk is based on a set of Jupyter Notebooks that I’ve developed over the past two years for use in my quantum mechanics class. As the talk comes together, and as I clean up and document the resources, I plan to write a series of posts describing how I use the libraries (like QuTiP) that make these lessons possible, the process I used to revise these resources, and the things I learned along the way about teaching students python and teaching students with python.

Inkscape clipboard fix on mac

Inkscape is my go-to vector editing program and I’ve done many publication figures, exam questions, and other general work in inkscape on both mac and linux. I’ve always just resigned to use clone (ctrl-D) instead of copy/paste since on the mac, the copy/paste cycle results in a pixelated image being pasted into the document. After beating my head against a wall trying to create a pattern-on-path effect, I realized that there must be something wrong with the clipboard implementation on the mac. Sure enough, a quick search took me to the inkscape FAQ, and this section in particular:

Starting with XQuartz 2.3.2, X11 has some functionality to exchange the content of the clipboard with OS X. It currently does not know how to deal with vector images, so it just captures the screen, i.e., creates a bitmap copy, and then pastes that. You need to deactivate this functionality in X11 preferences > Pasteboard: uncheck “Update Pasteboard when CLIPBOARD changes”. However, this will also prevent copying text from any X11 application to Mac OS X ones. It will not prevent copying text from OS X to X11.

When you just want to make a copy of an object within Inkscape, you can also use duplicate (Ctrl-D) rather than copy/paste (Ctrl-C/Ctrl-V) — Duplicate does not interact with the X11/OSX clipboards. For other Inkscape commands involving the system clipboards (e.g.Paste StylePaste Size or Paste Path in path effects) there is no alternative workaround other than changing the X11/XQuartz preferences as described above.

On the bright side, I had found the suggested workaround, and was able to effectively duplicate items in my drawings. However, that doesn’t work when the effects are expected paths in the clipboard (and they weren’t there). Since inkscape is about the only thing I use X11 for on the mac, I went ahead and disabled the X11-mac clipboard sync. I will dive in the the nuanced solutions if I need to. It’s been a blessing to have access to many of the path effects and other cool tools in recent inkscape versions.

NSF Grant awarded to Photonics and Quantum Optics Lab at Pacific

I’m pleased to announce that my research group has been awarded a second NSF RUI grant to further support our research. The RUI (research at undergraduate institutions) program specifies resources for scientific research at colleges like Pacific and is a valuable funding mechanism for science research at smaller colleges. I feel very fortunate to continue to offer summer research opportunities to undergraduates for at least the next three years. Below is the public abstract that is posted on the NSF website.

As electronic devices reach their maximum processing speeds, the demand for high speed internet communications and data networks will require new technologies for storing and processing large amounts of data. Electronics are built on the use of the electron to carry and process information and in an analogous way the field of photonics is developing devices that use particles of light called photons to carry and process information. Individual photons obey the laws of quantum mechanics, so in order to fully understand the operation of photonic devices, quantum measurements must be performed on these new devices. One particularly essential component is a memory or information storage device. Many candidates for photonic memory exist but few have been characterized at the quantum (few-photon) level. This research program will apply new techniques for measuring the quantum properties of light to a variety of photonic memory devices. The result will be a deeper understanding of device operation that will lead to optimized devices for future applications.
Photonic memory devices have been demonstrated using slow and stored-light protocols based on electromagnetic-induced transparency (EIT) in Rubidium. The goal of this program is to measure the quantum state of light retrieved from several implementations of these devices in both warm and cold Rubidium vapor samples. The light stored and retrieved from such systems will be measured and analyzed using a highly efficient array of low-noise photodetectors. This technique can simultaneously measure multiple optical modes and will be used to correlate multiple modes and determine which modes (or combinations of modes) are most robust under different storage conditions. A full quantum-mechanical understanding of the optical signal retrieved from memory allows complete characterization of the device performance and will inform future work in the development of photonic memory devices.