Thanks to visit codestin.com
Credit goes to www.scribd.com

0% found this document useful (0 votes)
72 views27 pages

Python & GNURadio Integration Guide

The document discusses using Python to interface with hardware devices. It provides an overview of connecting an ADXL345 accelerometer to a Raspberry Pi and using it in a GNURadio application. It also discusses using embedded Python blocks and libraries like pyadi-iio to interface with devices from Python code.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
72 views27 pages

Python & GNURadio Integration Guide

The document discusses using Python to interface with hardware devices. It provides an overview of connecting an ADXL345 accelerometer to a Raspberry Pi and using it in a GNURadio application. It also discusses using embedded Python blocks and libraries like pyadi-iio to interface with devices from Python code.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 27

Python for the

Rest of Us
Presented by Mark Thoren
Recommended Preparation
► If you’ve never touched Python before, head straight to learnpython.org and go through the
“Learn the Basics” lessons. Now. Seriously. It doesn’t get any easier than this, programs
actually run, but in the browser, no installation necessary.
► If you prefer paper, Python for Kids by Jason R. Briggs is surprisingly good for adults, too.
► As usual, Google, YouTube, Udemy, etc. are your friends. Find something that suits your style.

► Get either an ADALM2000 or ADALM Pluto, follow installation directions.


– Install Putty (https://www.putty.org/) or use your favorite terminal, log in to 192.168.2.1 (user: root pw:
analog)
– Run iio_info and observe.
– Run “ps | grep iiod” to see the thing that lets you connect remotely
– On your local machine, open a command prompt, run “iio_info” and watch it fail
– Run “iio_info –n 192.168.2.1” and compare!

► A fairly complete exercise on bringing up RPi + ADXL345:


► https://wiki.analog.com/university/labs/software/iio_intro_toolbox

► Github repo for code / flowgraphs in this session:


► https://github.com/mthoren-adi/gnuradio_projects/tree/grcon_2020

2 // ©2020 Analog Devices, Inc. All rights reserved. September, 2020


Motivation: Uses for “raw” Python along side
GNURadio applications
Move complicated
► Automation, characterization, integrating GR with lab equipment GUIs outside of GR
► Devices not supported in GNURadio
No GNURadio
► Working around GR block limitations (partial / incomplete hardware support 
interfaces)
► Convenience
► GUIs

Direct GNURadio
support ☺

3 // ©2020 Analog Devices, Inc. All rights reserved. September, 2020


Agenda

1. Overview of hardware – ADXL345 Pmod board, connections to the Raspberry Pi expansion header, Power, Network, etc.
2. Overview of what’s on the ADI Kuiper Linux SD card – drivers precompiled into kernel, libiio / gr-iio pre-installed. Basically, everything to get you to
the point where you can see the accelerometer from within GNU Radio.
3. Example “Hello (physical) World!” application: GnuRadioADXL345-o-scope (IIO Attribute blocks feeding QT Time Sink)
4. Using embedded Python blocks
a) ADXL345 controlling VCOs as proof-of-concept
b) Using libiio to communicate with devices from within block
c) Establish communication to external Python programs
5. Getting around GR Block limitations with Python (ADALM2000)
6. Python interfaces to other “radio-ish” parts (ADAR1000 microwave beamformer, AD9166 DAC, ADF4371, etc.)

4 // ©2020 Analog Devices, Inc. All rights reserved. September, 2020


First set of exercises at learnpython.org

5 // ©2020 Analog Devices, Inc. All rights reserved. September, 2020


Toolbox item: Python environment
► There are lots – largely a matter of preference. Too many choices? No problem! Kuiper
► Anaconda, PyCharm comes with one (Thonny)

► “raw” installation (Mac, Linux)


► Jupyter Notebook

6 // ©2020 Analog Devices, Inc. All rights reserved. September, 2020


ADXL345 + Rpi +GNURadio =
World’s Silliest Theremin* Why ADXL345?
Linux driver exists, and it’s in the IIO framework

► Cheap Pmod
► Easy to connect w/ Schmartboard jumpers

Power (USB μ, C) ► A human is a perfectly adequate signal source

Display (optional if
connecting via VNC)
Alternate Hardware
Connectivity option
Connect amplifier
or headphones
Network, keyboard, mouse
(Wireless works, too)

*For the purists, Theremin-ish-like thingy.


7 // ©2020 Analog Devices, Inc. All rights reserved. September, 2020
Hardware Connections
Raspberry Pi
Expansion Header Pin Mapping:
ADXL345 Pmod
GPIO19 ↔ INT2
CS0 ↔ ~SS
COPI ↔ COPI
COPI
CIPO ↔ CIPO CIPO

SCLK ↔ SCLK
COPI
CIPO
GND ↔ GND
GND ↔ GND
3V3 ↔ VCC
3V3 ↔ VCC
CIPO
COPI
(Connect w/ Schmartboard 5” female jumpers)
8 // ©2020 Analog Devices, Inc. All rights reserved. September, 2020
Toolbox Item:

► ADI’s own variant of Raspbian!


► All appropriate Linux device drivers for ADI/LT parts enabled
► Software libraries: the libiio, libm2k, pyadi-iio
► GNURadio
All Python Compatible
► IIO Oscilloscope
► Documentation / instructions: https://wiki.analog.com/resources/tools-software/linux-
software/adi-kuiper_images
► Point config.txt to appropriate Device Tree Blob Overlay
For GRCon session (ADXL345): dtoverlay=rpi-adxl345

Pro Tip: run iio_info to check that connected hardware was found

9 // ©2020 Analog Devices, Inc. All rights reserved. September, 2020


What are “dtbo” and “dtb” files? PowerPoint
Overload Warning...
Do Live Demo
► dtb = device tree blob – information about
hardware
▪ Specific to a particular platform Snippet from file:
/linux/arch/arm/boot/dts/overlays/rpi-adxl345-overlay.dts
► dtbo = device tree blob overlay, information
about additional hardware (like the attached
ADXL345)
▪ Specific to a particular set of additional hardware
(usually)
► dts = device tree source. The Device tree
compiler (dtc) generates dtb,dtbo from these
► Where do they live?
▪ Compiled examples on the SD card (boot partition)
▪ Source in Linux repo – use these as a starting
point if you need to make changes (ports,
addresses, etc.)

10 // ©2020 Analog Devices, Inc. All rights reserved. September, 2020


Toolbox Item:
► From the Github Readme:
“pyadi-iio is a python abstraction module for ADI
Grab a chunk of data from an
hardware with IIO drivers to make them easier to use.”
SDR chip in three** lines of code:
► What pyadi-iio does for us – abstracts the gory details and
“goofiness” of libiio, leaving us with a clean, Pythonic interface
to our part.
► “glue layer” between iio (which has a bit of a learning curve)
and doing something useful

► Pre-installed on ADI Kuiper Linux

** Not counting comments ☺


11 // ©2020 Analog Devices, Inc. All rights reserved. September, 2020
Software Stack Glossary Raspberry Pi Win/Mac/Linux

► IIO – Industrial Input Output, a GNURadio,


standard way of interfacing to Python script, etc. Python script,
fancy GUI, etc.
data converters in Linux
► libiio – Library for talking to IIO
devices from your program
► IIOD server – shares IIO devices
over a network
► Client application – your (or
customer’s) program, can be
written in pretty much any
language.
► Pyadi-iio – If your client
application is in Python, this
ADXL345
makes your life easier Wired or
Wireless
Ethernet
https://wiki.analog.com/resources/tools-software/linux-software/libiio

12 // ©2020 Analog Devices, Inc. All rights reserved. September, 2020


Pyadi-iio for the ADXL345

“local:” if script is running on your Rpi


“ip:localhost” standard user write access via iiod
“ip:xxx.xxx.xxx.xxx” to access remote target

Connect
Device

Set
sampling
frequency
Read X
acceleration

13 // ©2020 Analog Devices, Inc. All rights reserved. September, 2020


Hello, Audio: Trippy sound effect generator

► Main purpose is to verify audio Raspberry Pi


functionality Audio Output

14 // ©2020 Analog Devices, Inc. All rights reserved. September, 2020


Hello, Physical World: ADXL345-o-scope

► Main purpose is to verify ADXL345-


GR connectivity
► Uses GR IIO blocks directly

15 // ©2020 Analog Devices, Inc. All rights reserved. September, 2020


This doesn’t work
Well, mostly doesn’t. You
get a little chirp every few
seconds.

Fundamental mismatch… attribute vs. stream?


Sample and hold: Fail 
Rational Resampler: Fail 
16 // ©2020 Analog Devices, Inc. All rights reserved. September, 2020
Theremin*: Control VCOs from ADXL345
► Bridges gap between GR and outside
world

17 // ©2020 Analog Devices, Inc. All rights reserved. September, 2020


First attempt failed badly on GR3.7
► Some pyadi-iio functions worked
under Python 2.7 by luck
► (Not the ADXL345 )
► Still possible to use “raw” libiio
functions… but pyadi-iio has made
the author lazy.

18 // ©2020 Analog Devices, Inc. All rights reserved. September, 2020


Final incarnation – external zmq publisher
► Separate script running in another
terminal – pyadi-iio reads adxl345,
publish to zmq
► Embedded Python block receives
data, passes to flowgraph
► May be possible to use GR ZMQ
blocks, but this method is infinitely
flexible.
► Use your favorite environment for
GUIs, other stuff you’d rather not do
in GNURadio.

19 // ©2020 Analog Devices, Inc. All rights reserved. September, 2020


What else can we use external Python scripts for?
► Adalm2000 block!
► See “Build a Radio with an m2k and
spare parts”
► How far can we milk the m2k in a
radio application?
► Inspired by Jon Kraft’s A.M. to F.M.
translator

20 // ©2020 Analog Devices, Inc. All rights reserved. September, 2020


Conceptual A.M. to F.M. translator

10Msps adequate to 88-108MHz F.M.


digitize entire A.M. Band broadcast band
(m2k will do 100Msps) out

530-1600kHz
Demodulate
A.M. broadcast
455kHz A.M. I.F.
band in
Remodulate
200kHz wide
F.M.

Show Stopper:
~2Msps USB
Bandwidth

21 // ©2020 Analog Devices, Inc. All rights reserved. September, 2020


Compromise: I.F. sampling
530-1600kHz
A.M. broadcast Educational A.M. Radio Kit
band in

88-108MHz F.M.
broadcast band
455kHz I.F. out

Demodulate
455kHz A.M. I.F.
Where Python Remodulate
comes in: 200kHz wide
Generating A.M. R.F. F.M.
test signals
(@7.5Msps)

22 // ©2020 Analog Devices, Inc. All rights reserved. September, 2020


A.M. to F.M. Translator Overview
Elenco AM550 Other random F.M. antenna
(A.M. Tune, devices (not used
downconvert to in this experiment)
455kHz)
Hello Kitty
(F.M. Rx)
ADALM2000:
Digitize I.F. @2Msps
(in GNURadio)
Generate modulated
RF test signal, 1MHz
ADALM-PLUTO
carrier (in Python)
(F.M. Tx)

R.F. Antenna

ADXL345 from
Raspberry Pi 4 Audio Sink
previous experiment
Output

23 // ©2020 Analog Devices, Inc. All rights reserved. September, 2020


Back to reality… practical stuff
CN0511 (In Development) D.S. to 5GHz
Raspberry Pi-based Signal Generator

Production test jig =


Rpi + Pluto + Pyadi-
AD9166 DAC w/ integrated NCOs iio + Python script
libiio, pyadi-iio compatible

24 // ©2020 Analog Devices, Inc. All rights reserved. September, 2020


Do-List

• Python GUI / ZMQ publisher for


phased array project

• Script flowgraph data processing /


capture from external Python script

25 // ©2020 Analog Devices, Inc. All rights reserved. September, 2020


Acknowledgements
► https://github.com/analogdevicesinc/libiio/grap
hs/contributors
► https://github.com/analogdevicesinc/pyadi-
iio/graphs/contributors
► https://github.com/analogdevicesinc/adi-
kuiper-gen/graphs/contributors
► Travis Collins – pyadi-iio
► Adrian Suciu and team – libm2k
► Mircea Caprioru – ADI Kuiper Linux

26 // ©2020 Analog Devices, Inc. All rights reserved. September, 2020


Thanks!

27
©2020 Analog Devices, Inc. All rights reserved.

You might also like