This version (01 Feb 2021 01:26) was approved by Doug Mercer.The Previously approved version (25 Mar 2016 18:16) is available.Diff

ADALM1000 Python tutorial materials


This tutorial will introduce you to the libpysmu Python interface software layer to control the ADALM1000 active learning hardware module. Python is a general-purpose, object-oriented interpreted language you can use along with the ALM1000 hardware for countless standalone projects.

Required files:

These tutorial example programs are written in Python and requires that version 2.7.8 of Python be installed on the user's computer. The programs only import modules generally included with standard Python installation packages. The following files are required do these tutorials:

All OS:

Common Notes:

As in all the ALM activities we use the following terminology when referring to the connections to the ALM1000 connector and configuring the hardware. The green shaded rectangles indicate connections to the M1000 analog I/O connector. The analog I/O channel pins are referred to as CA and CB. When configured to force voltage / measure current -V is added as in CA-V or when configured to force current / measure voltage -I is added as in CA-I. When a channel is configured in the high impedance mode to only measure voltage -H is added as CA-H.

Scope traces are similarly referred to by channel and voltage / current. Such as CA-V , CB-V for the voltage waveforms and CA-I , CB-I for the current waveforms.

The digital I/O channel pins are referred to as D0 through D3. These correspond to the pins labeled PIO 0 – PIO 3 on the ALM1000 board silkscreen.

Table of Contents:

  1. Using the CD4052 dual 4:1 analog Mux for more analog inputs
  2. Read temperature values from an AD22100 sensor
  3. Control a DC motor
  4. Control a Servo Motor
  5. Drive a piezoelectric transducer and use as a vibration sensor
  6. Use an electret microphone as a sound detector
  7. How to read acceleration data from the ADXL327


ADALM1000 hardware module

High Level Functions in libpysmu:

There is are a few pre-defined python functions that interface to the C++ libsmu library. Contained in the file they provide the high level access functions to configure and control the ALM1000 hardware. The file must be imported or cut and pasted into your python program. The following lists the functions currently implemented:

Must be run first
Returns a list of the devices currently plugged into the computer
devx = Smu()

takes a integer for the device, 0 for first device in list, 1 for second etc.
returns index to that device

Both = devx.devices[0]

takes one of the following strings as input 'A' , 'B' for first device, 'C' , 'D' for second device etc.
returns index to that channel

CHA = devx.channels['A']
CHB = devx.channels['B']

AllChan = Both.get_samples(n_samples):
query device for a list of samples from all channels
n_samples parameter is number of samples
n_samples is of type int
returns list of n samples from all the device's channels

AnalogInA = CHA.get_samples(20) get 20 readings and return them to list variable AnalogInA

CHA.set_mode(mode) or CHB.set_mode(mode):
mode can be one of the following strings:
'V' or 'v' sets channel to source voltage measure current ( SVMI )
'I' or 'I' sets channel to source current measure voltage ( SIMV )
'D' or 'd' set channel to high impedance mode, measure voltage

The following functions control the waveform of the analog output channels (could be CHA or CHB).

value is a floating point number from 0 to 5 representing the DC output voltage for that channel
or value is a floating point number from -0.200 to + 0.200 representing the DC output current for that channel

CHA.sine(value1, value2, periodvalue, delayvalue)

CHA.triangle(value1, value2, periodvalue, delayvalue)

CHA.sawtooth(value1, value2, periodvalue, delayvalue)

CHA.square(value1, value2, periodvalue, delayvalue, dutycyclevalue)

CHA.stairstep(value1, value2, periodvalue, delayvalue)

To better visualize how to specify a waveform look at figure 1 where:
value1 is the first peak value of the waveform, could be the minimum or the maximum peak.
value2 is the second peak value of the waveform, could be the minimum or the maximum peak.
If for example value1 is less than value 2 the apparent phase of the wave is 180 degrees from a wave where value1 is greater than value2.
dutycyclevalue is a fractional number from 0 to 1. dutycyclevalue only applies to the square waveform.

Figure 1 How to build a waveform.

To calculate the period from frequency ( in Hertz ) use the following formula:
periodvalue = SAMPLErate/freqvalue where SAMPLErate is generally fixed at 100,000 SPS

To calculate the delay from the phase ( in degrees ) use the following formula:
delayvalue = periodvalue * phasevalue / 360

Direct control over ADALM1000 functionality can be accomplished using the implemented control transfers, a synchronous and slow communication endpoint accessible regardless of the configuration of the device.

Note that the higher level functions libpysmu implements on top of LIBSMU make use of many of the control transfers to configure device state during normal operation. As such, using these low level control transfers while streaming data may not produce the expected results.

The ALM1000 implements many control transfers, including the following:

  • 0x17 - read a number of bytes from the ADM1177 hot-swap controller
  • 0x50 - Set a GPIO pin low
  • 0x51 - Set a GPIO pin high
  • 0x91 - Get a GPIO input pin value
  • 0x53 - Set device Mode
  • 0x59 - Set potentiometer state

M1000 microcontroller pin mappings are described below.

IO NameNet NameNet DescriptionPin ID
PA0PIO0user DIO 0-220Ω0
PA1PIO1user DIO 1-220Ω1
PA2PIO2user DIO 2-220Ω2
PA3PIO3user DIO 3-220Ω3
PA4PIO0user DIO 0-470Ω4
PA5PIO1user DIO 1-470Ω5
PA6PIO2user DIO 2-470Ω6
PA7PIO3user DIO 3-470Ω7
PB0UA11-IN050Ω from ChA to 2v532
PB1UA11-IN150Ω from ChA to GND33
PB2UA11-IN2ChA close voltage sense loop34
PB3UA11-IN3ChA connect output35
PB5UB11-IN050Ω from ChB to 2v5 37
PB6UB11-IN150Ω from ChB to GND38
PB7UB11-IN2ChB close voltage sense loop39
PB8UB11-IN3ChB connect output40
PB17PWR_ENABLEturn on power for analog components49


import libpysmu

devx = Smu()
DevID = devx.serials[0] # device ID for 1st M1000 in list

# set PIO1 high
devx.ctrl_transfer(DevID, 0x40, 0x51, 1, 0, 0, 0, 100)

# set PIO1 low
devx.ctrl_transfer(DevID, 0x40, 0x50, 1, 0, 0, 0, 100)

# get state of PIO0
print devx.ctrl_transfer(DevID, 0xc0, 0x91, 0, 0, 0, 1, 100)

# get state of PIO1
print devx.ctrl_transfer(DevID, 0xc0, 0x91, 1, 0, 0, 1, 100)

# set CHA 2.5 V switch to open
devx.ctrl_transfer(DevID, 0x40, 0x51, 32, 0, 0, 0, 100)

# set CHA GND switch to open
devx.ctrl_transfer(DevID, 0x40, 0x51, 33, 0, 0, 0, 100)

# set CHB 2.5 V switch to open
devx.ctrl_transfer(DevID, 0x40, 0x51, 37, 0, 0, 0, 100)

# set CHB GND switch to open
devx.ctrl_transfer(DevID, 0x40, 0x51, 38, 0, 0, 0, 100)

# open CHA voltage sense loop
devx.ctrl_transfer(DevID, 0x40, 0x51, 34, 0, 0, 0, 100)

# open CHB voltage sense loop
devx.ctrl_transfer(DevID, 0x40, 0x51, 39, 0, 0, 0, 100)

For Further Reading:

Active Learning Interface (for) Circuits (and) Electronics (Python program)
ALICE-SA Spectrum Analyzer (Python program)
ADALM1000 Analog Inputs
ADALM1000 Digital Outputs

Return to ALM Table of Contents

university/tools/python-tutorial/table-of-contents.txt · Last modified: 01 Feb 2021 01:26 by Doug Mercer