Wavefront shaping techniques in complex media

[tutorial] Control a Vialux DMD with Python

Vialux provides Texas Instrument DMD (Digital MicroMirror Devices) chips with an electronic board to send and display image sequences at high speed (up to 30kHz). While they provide a C++ dll, Labview and Matlab codes, I did not find any tool for Python. I share here a simple module that wraps the C++ functions for Python. It allows to use in a simple manner the basic functions while providing the advanced features of the ALP API.

DOI

 

The Python module is available on the ALP4lib Github repository. Please read the short introduction on the repository and the Vialux ALP API description document for a complete overview of the features. It uses the same syntax as the ALP API but functions can be called with fewer arguments to simplify the code when advanced features are not needed.

Here is a basic example of the use of the ALP4lib module. It displays a sequence of two images with all pixel black then white at a 50 Hz rate continuously until the user ask the DMD to stop.


import numpy as np
from ALP4 import *
import time
# Load the Vialux .dll
DMD = ALP4(version = '4.3', libDir = 'C:/Program Files/ALP-4.3/ALP-4.3API')
# Initialize the device
DMD.Initialize()
# Binary amplitude image (0 or 1)
bitDepth = 1
imgBlack = np.zeros([DMD.nSizeY,DMD.nSizeX])
imgWhite = np.ones([DMD.nSizeY,DMD.nSizeX])*(2**8-1)
imgSeq = np.concatenate([imgBlack.ravel(),imgWhite.ravel()])
# Allocate the onboard memory for the image sequence
DMD.SeqAlloc(nbImg = 2, bitDepth = bitDepth)
# Send the image sequence as a 1D list/array/numpy array
DMD.SeqPut(imgData = imgSeq)
# Set image rate to 50 Hz
DMD.SetTiming(illuminationTime = 20000)
# Run the sequence in an infinite loop
DMD.Run()
time.sleep(10)
# Stop the sequence display
DMD.Halt()
# Free the sequence from the onboard memory
DMD.FreeSeq()
# De-allocate the device
DMD.Free()

 

If this program was useful to your work, please consider citing it using its DOI:

DOI

Submit to FacebookSubmit to Google BookmarksSubmit to TwitterSubmit to LinkedIn

Comments   

 
#4 Sébastien Popoff 2018-11-25 16:41
Hi Ronnie

Quoting Ronnie:

In the folder, there aren't files like
alp41.dll', 'alp42.dll' and 'alp4395.dll'


There should be a .dll file coming with the Vialux ALP SDK, that is the core file of the SDK as it contains the functions.
Try reinstalling the SDK.

Quoting Ronnie:
By the way, to use this module, how to make the connection to PC? With mini-USB cable or some special cable? Thanks


Use the cable provided with the DMD!
On my devices it is a USB cable with a USB 3.0 Micro B connector on the DMD side and a regular USB type A connector on the computer.

Best,

Sebastien
Quote
 
 
#3 Ronnie 2018-11-23 01:53
Hi,
I installed the module with pip install ALP4lib and found the folder C:\Program Files\ALP-4.2.

In the folder, there aren't files like
alp41.dll', 'alp42.dll' and 'alp4395.dll'

What could be the problem?

By the way, to use this module, how to make the connection to PC? With mini-USB cable or some special cable? Thanks
Quote
 
 
#2 Sébastien Popoff 2018-10-04 19:19
Hi,

Are you sure you did not just type import ALP4?
ALP4 is both the name of the module and the name of the class inside the module, so you have to import the class from the module, either import erveything,
from ALP4 import *
or just the ALP4 class
from ALP4 import ALP4

Best,

Sebastien

Quoting yibo:
errors show in line 2 and line 5 when i run the code. Error message says 'module' object is not callable. Do you know what could be the reason.
Quote
 
 
#1 yibo 2018-10-03 13:27
errors show in line 2 and line 5 when i run the code. Error message says 'module' object is not callable. Do you know what could be the reason.
Quote
 

Additional information