Wednesday 28 December 2016

AuroraWatch UK camera update #1

ZWO ASI 174MC colour USB 3.0 camera. Image from ZWO website.
Recently AuroraWatch UK purchased a ZWO ASI174MC colour USB 3.0 camera to (hopefully) record images of the aurora. The aim is to build an all-sky imager. To minimise the cost the camera will be connected to a Raspberry Pi single-board computer and be located outside in a waterproof enclosure. This particular camera was chosen for several reasons:
  • No mechanical shutter to wear out. 
  • The large pixel size (5.86um) should give good sensitivity. 
  • The sensor has an IR cut-off filter fitted (filters cannot be used with the fish-eye lens). 
  • The manufacturer provides support to access the camera from Linux. 
At present the Linux support from ZWO is limited to a software development kit (SDK) which provides a C language library and header file. This is sufficient for a Raspberry Pi to be able to interface with the camera. However my preferred approach is to write the image capture and control software in Python since that will simplify development and access to the AuroraWatch UK API. I therefore decided to write a Python wrapper for the C library. This is not something I have done before and after a little experimentation with ctypes, Cython and CFFI and I settled on using ctypes. You can find the source code for my Python wrapper on Github. It's also available on pypi so you can install it simply by running "pip install zwoasi".

I've written a short demo program to illustrate how to access the camera from Python. The camera can operate in two modes. The first, snapshot mode, takes a single exposure. The second, video mode,  continually takes exposures which can be downloaded from the camera as and when required. At first glance either mode would appear suitable for the purpose of taking a single exposure once a minute. My main concern is how to set the exposure correctly for an automated system which will run in a variety of different lighting levels (twilight, nighttime, and possibly even daytime). Fortunately this particularly camera provides an auto-exposure mode which can adjust the exposure time and gain settings according to the ambient light levels. It does this by analysing the image histogram after each exposure. The documentation doesn't explain the auto-exposure mode but I suspected that the camera would have to be operated in video mode for this to work. A quick test proved this to be correct. How well the auto-exposure algorithm works at night has yet to be discovered; since it is an astronomy camera I'm optimistic that it will be suitable and save me from having to implement an exposure control algorithm.

Sample ASI174MC image
Sample image from ASI174MC and Fukinon FE185C057HA-1 2/3" fisheye lens.
The complete control system is intended to timestamp and watermark images, change the recording cadence according to AuroraWatch UK status and solar elevation, record temperature and humidity, and control heating and fans.


  1. He Steve. As a matter of interest, how are you powering it all?

    1. The plan is to use power-over-ethernet so that the Raspberry Pi can be located outside at a convenient location. I need to test the system outside for a while before the final deployment to check there are no issues with the power. I hope to run the test this month.

    2. Cool. :) I noticed you've done PoE things before so imagined that that might be the case. Are you intending to run the OS from USB or MicroSD? I've noticed occasional SD card corruption still with B+ (most commonly) and 2 (less so) after a large batch of writes (doing upgrades) no matter the quality of PSUs and memory cards, have you ever noticed similar? I keep meaning to try out the method of using the SD card just for the boot partition and then hand-off to a USB device instead to see if that's more resilient. Having said that, sans heavy bouts of writing I've found the Model 2 to have good up-time for home projects like ADS-B receiver node.

    3. The plan is to use PoE but right now I'm not sure if that is possible. I'm having a few issues with the Raspberry Pi 3, PoE and the USB camera. PoE operation is possible with the Raspberry Pi 2 and the Raspberry Pi v2 camera.

      I've tried to avoid situations which cause repeated writes to the SD card. I remove the swap file (apt-get remove dphys-swapfile) and mount a small tmpfs filesystem which I use for non-essential files.

      For the camera images I'm thinking of storing them for a short time in a tmpfs filesystem. There would be a regular cron job to rsync them to another server (the --remove-source-files option will be essential). Files on the tmpfs filesystem that are older than a certain age would be transferred to local persistent storage to cover times when the remote server is not accessible. Can you forsee any problems with that?


    4. PoE does indeed work ok with the ASI174MC and ASI178MC cameras. It was a silly configuration problem that lead me to think becaue the camera wasn't starting up properly it must be power-related. That's because I had some bad experiences with earlier Raspberry Pis and USB, especially when hot-plugging devices.

  2. Hi Steve,

    I'm using a ZWO ASI 174MM. I'm relatively new to python and was wondering if you could give me some extra information/help on how to setup the python wrapper you made for use on a Macbook?

    I've tried a few things but I am currently stuck. I can't get your scripts to detect the camera!

    1. Hi Daniel,
      Have you installed the ASI SDK from ? I've not tried using the SDK on a Mac but there should be some demo programs in there that you can use to check everything is ok. My Python module needs to know the location of the libASICamera2 library (on the Mac its called libASICamera2.dylib).

      You can either set an environment variable ZWO_ASI_LIB with the full path and file name of the library or you can call the program with the full path and name of the library, eg,

      python /Users/Daniel/SDK/lib/mac/libASICamera2.dylib

      Do you get any error messages when you run the python demo program?

    2. Hey Steve,

      It worked! I was just missing USB drivers so I could not communicate with the camera. Everything is working fine now! Thank you so much for everything :)

    3. Glad you have it working. Please post back here if you create any interesting code using the zwoasi module.

  3. Hi Steve
    Thank you for this convenient library.
    I have however a problem with the capture function: when I use it in a main program it works just fine but when I use it inside a program with parralelized threads it does not work. My guess is that it needs to be in the main thread which is not the case in the program I made. How can I fix that ?

    1. It's not necessary for the capture function to be called from the main thread. My cameralogger software, which uses zwoasi, calls capture() from a new thread each time an image is needed. To make sure everything works correctly you will need to use locks so that only one thread accesses shared resources (variables, hardware etc) at any one time. If you look at and you can find examples of how I do this.

    2. Thank you Steve. It was actually an error from my code, I was initiating the camera outisde the multithreading. Anyway, I added the locks as you did for safety.

  4. Hi! Great work, I am using your Python wrapper for my all sky camera (ASI120MC-S)

    I have one question tho - for dark frame substraction, no matter what I do I get "Invalid file format" error (ZWO_IOError 7). I tried with bmp, fit, tiff,... (it should be bmp afaik but I tried others since it did not work).

    Best Regards!

    1. This isn't a feature I've tested since I don't have a shutter or the ability to create true dark frames with my camera. The documentation indicates the file should be BMP file using RGB8 raw format.

  5. Hi Steve!

    Congrats for your work, I managed to run an ASI 120MM with your demo code, but when it try to capture I get this error:

    Enabling stills mode
    Capturing a single 8-bit mono image
    Traceback (most recent call last):
    File "", line 100, in
    File "/usr/local/lib/python2.7/dist-packages/zwoasi/", line 535, in capture
    raise ZWO_CaptureError('Could not capture image', status)
    zwoasi.ZWO_CaptureError: Could not capture image

    What do you think it could be? Thanks a lot.

    All my best

    1. Are you using the USB 2.0 or USB 3.0 version of the ASI 120MM? ZWO report that the USB 3.0 version has better compatibility with Linux. I wasn't able to get the USB 2.0 version to work under Linux, with the same error you report.

  6. Hi Steve!
    Sorry my English is not very good...
    There is some question...
    When I run the I will get Error: "AttributeError: 'NoneType' object has no attribute 'ASIGetNumOfConnectedCameras'"

    Then I run the I will get: "The filename of the SDK library is required (or set ZWO_ASI_LIB environment variable with the filename)"
    What should I do to solve this problem??

    1. The problems are because the examples need to know the location of ZWO SDK library. This path depends on where you installed it, and whether you are using an Intel processor with x86 (32 bit), x64 (64 bit) OS, or an ARM operating system.

      Please update to version 0.0.22. This fixes the binning demo. Then run either demo. Be sure to call the program with the full path to the (for Linux) or to ASICamera2.dll (for Windows).

  7. Hello,

    I want to use the zwo asi 120mm with python and opencv on raspberry pi 3. I've installed opencv for python 3.
    Is your binding also available for python 3?


    1. The module should work for both Python 2 and Python 3. If you experience any problems please create an issue on the Github page:

    2. Thanks a lot for your fast answere!

      I've installed it with 'pip install zwoasi' and can't import zwoasi in python 3.
      How do I install it for python 3?

  8. Hi Steve,
    Thanks for sharing this great work! Any experiences on auto-exposure mode under night sky?
    - Harri


Note: only a member of this blog may post a comment.