Remote Control for Poor Man's Arbitrary Wave Form Generator

by wolf2018 in Circuits > Remote Control

1886 Views, 11 Favorites, 0 Comments

Remote Control for Poor Man's Arbitrary Wave Form Generator

win8.1.PNG

With the instructable Poor Man's Waveform Generator Based on RP2040 Raspberry-pi-Pico Board (AWG) you can build a nice self contained wave form generator - but.... recently I got a question from a friend, if the AWG could be remote controlled by his PC, as he did not want to build the whole generator. I thought this is a nice idea and if you did hesitate so far to build the full AWG hardware, read on. This instructable describes how to install and use the Remote User Interface for the AWG, in short: RemoteUI.

This instructable covers a step on hardware, actually two steps, to briefly describe the hardware you need for the AWG.

I will use italics letters to denote commands you type, e.g. in a terminal window.

Supplies

AWG_Hardware.jpg
TestedOpSys-Python.png

To run the Remote UI you need a PC with either Windows or Linux operating system, or a Raspberry Pi 2+ or higher with a recent Raspberry Pi OS with desktop. Screen resolution needs to be 1024x768 or larger.

We need Python 3.7 or higher installed as well as the modules tkinter and pyserial.

I did test the RemoteUI on Windows 8.1 (on a laptop), Windows 11, Ubuntu 20.04 (on a laptop and PC) and the Raspberry Pi OS release of 28-Jan-2022 (bullseye) on a Raspberry Pi 3+. I do not have a Mac, using python tkinter to build the UI, the RemoteUI should run on a Mac as well. For tested operating systems vs. python versions, please refer to the picture.

And, of course, you need the AWG hardware (see Step 1) and a USB-A to micro-USB cable to connect the pico board to your computer.

AWG Hardware and AWG Software

IMG_0109.jpg
RP2040AWG_8-bitSchematics.png

Although this is a software project, you need at minimum an RP2040 pico board and a few components to build an AWG. Please refer to the AWG instructable for more details building the hardware. As a reference I have attached the schematics and a picture of the AWG board I use with the RemoteUI. The bill of material for the AWG board you can find in the attached pdf file.

Few remarks:

  • To test the software, you do not need to solder the hardware components to a PCB, it is sufficient if you build the AWG hardware on a bread board.
  • You should be aware that the RP2040 can drive small loads only. If you need more power to drive low impedance or plan to use the AWG for higher frequencies, there are two solutions. (1) I have added a step below to describe a simple video amplifier, or (2) you follow the above mentioned AWG instructable and build the full hardware with an class AB output stage.
  • For the RemoteUI you do not need the connectors for the TFT display and the user interface (which you see mounted on my board).


This instructable assumes you have some basic knowledge on how to use a Pico board, load micro-python and python modules to the Pico. In case you need help, please find the step by step guide getting started with micropython on raspberry pi pico.

The AWG is implemented using micro-python. Please load micropython to the Pico. Use version 1.17 ( rp2-pico-20210902-v1.17.uf2 ) or newer.

Next download following files to the AWG:

  • AWG.py - Control program for communication with the RemoteUI
  • wave_gen.py - Program to calculate the wave and program the RP2040 DMA and PIO
  • main.py - module to load and start AWG.py

Quick check: if all went well and you restart the pico board, the onboard LED should flash once to signal the AWG has started and is ready to connect to the RemoteUI.

Credits: To calculate the wave and program the DMA and PIO I use modules developed by rgco, please see his instructable for details.

Installing on a Linux System

python.png
AWGremoteLinux.png

If you install on a Linux system, either on a PC or Raspberry Pi, you have python installed by default. If you are familiar with Linux/Python, and have tkinter and pyserial installed, you can skip this step.

Check Python version:

Open a terminal / console window and type: python. You will see the python version printed on screen. In the attached picture you can see I have python 3.9.7 installed. You are good with a version of 3.7 or above.

If the python version is not version 3, you probably running python 2.7. Then type exit() to exit python and type python3 in the terminal window. If that reports version 3.7 or higher you are fine and just need to replace python with python3 for this instructable. I will mention this in (parenthesis) throughout this step.

If your version is below 3.7, the RemoteUI might not run, I recommend updating your operating system to a more recent release.

Check for Tkinter and pyserial:

Open a terminal / console window and type: python (python3). On the >>> prompt type import tkinter. If the >>> prompt returns without an error message, good.

Then type >>> import pyserial. If the >>> prompt returns without an error message again, perfect, we are good to go.

If you get a "ModuleNotFoundError:" you need to install the missing module.

If no error, jump down to "Download and run the RemoteUI".


Installing Tkinter (if not installed):

It is recommended that you install Tkinter using your package manager, as there are conditions where pip does not work properly. For Debian based systems (Ubuntu, RPi OS...) open a terminal window and type:

sudo apt-get install python-tk

(sudo apt-get install python3-tk)

Enter your password and the installation should be fine. Check for TKinter again (see above).


Installing pyserial (if not installed):

If not installed, we can use the python package manager pip:

pip install pyserial

(pip3 install pyserial)

The >>> import pyserial command should return without an error message now.


Download and run the RemoteUI:

Attached please find the Python file AWGremote.py. Download the file to a working directory.

Open a terminal, change to your working directory and start the RemoteUI by typing:

python ./AWGremote.py

(python3 ./AWGremote.py)

The remoteUI should start and look similar to attached picture. Step 4 will describe the usage of the RemoteUI.

Downloads

Installing on a Windows System

pythonWin.png
pyserial.png
AWGwelcome.png
Zadig.PNG

If you need to install Python on your Windows system please see the python.org/downloads site. I recommend to use the "Latest Python 3 Release" (currently 3.10.2). You need to scroll down a bit on the download page, then select the version which fits to your Windows system (32 or 64 bit). I am using the windows installer version.

One important remark: do not forget to tick the box "add Python 3.xx to path". (see picture)


To open a terminal/console window press the "windows key" and type cmd or open a power shell.

Check Python version:

Open a terminal / console window and type: python. You will see the python version printed on screen. You are good with a version of 3.7 or above.

If the python version is not version 3, you probably running python 2.7 or if your version is below 3.7, the RemoteUI might not run, I recommend updating to a more recent Python 3 release.


Check for Tkinter and pyserial:

Python 3.7 or greater for Windows comes with everything you need to run Tkinter fully configured out-of-the-box.


Checking and Installing pyserial (if not installed):

Open a terminal / console window and type: python. On the >>> prompt type import pyserial. If the >>> prompt returns without an error message, perfect, we are good to go.

If you get a "ModuleNotFoundError:" you need to install pyserial, type exit() to exit python then type:

pip install pyserial

See picture for expected output. Now the >>> import pyserial command should return without and error message.


Download and run the RemoteUI:

Download the Python file AWGremote.py attached to Step2 to your working directory or your desktop. The file is the same for Linux and Windows.

If you copied to desktop double-click the RemoteUI icon. Alternatively open a terminal, change to your working directory and start the RemoteUI by typing:

python ./AWGremote.py

The remoteUI should start, see picture.

Step 4 will describe the usage of the RemoteUI.


Remark: If you are using Windows 8.1, you need to install a driver to connect to the RP2040 pico board via USB. I am using the open source software Zadig to do the driver installation, as Microsoft update does not find a suitable driver. If you use Zadig, please select the "USB serial driver" (see picture). The pico board should then show in device manager under COM&LPT as "Board CDC (Interface0) COMxx". COMxx is the port to use when connecting to the AWG.

Set the Communication Port

Now it is time to connect the AWG hardware. Take the USB-A to micro USB cable, plug the USB-A end to an USB port of your computer and the micro-USB port to the pico board. Watch the LED on the pico board, it should blink once to signal ready for connection to the RemoteUI.

The RemoteUI connects via serial interface (USB) to the AWG, therefore we need to know what interface your computer uses.

For Linux:

  • For Linux this is typically /dev/ttyACM0, which is the default in RemoteUI.
  • If you get an error message connecting, open a terminal and type: ls -l /dev | grep ACM to list all interfaces, which contain the string "ACM".
  • You should get an output such as /dev/ttyACM1. If you do not get an output, then the AWG is not connected to USB. Check the cable. Check if the LED binks once when you connect the pico board.

For Windows:

  • For Windows you best go to the device manager (press the Windows key and type device manager)
  • Check in COM&LPT ports to which COM port the pico is connected to. On my Windows test-computers ist was COM4 or COM5.

The RemoteUI Screen and Use Model

RemoteUI_screen.png
user_flow.png

The RemoteUI has three sections (see picture for details):

  1. The top section (gray color) displays the version date on the top left side. On the top right side is the field to enter the port and two buttons to connect and disconnect the AWG. Next below is the main entry area to set up a wave. It has entry fields for function, frequency and frequency range, sliders for amplitude and offset and, depending on the function selected, one or more entry fields for the parameters of the wave. If you start the RemoteUI, the parameter section displayes few instructions on how to use the RemoteUI.
  2. The middle section (white color) shows the controls for the AWG: a setup and stop generator button and a field to chose the number of samples the AWG should use to calculate the wave. Higher sample rates provide more accuracy, but take longer to calculate. The default value is 512 samples. Below the controls is a status/message field (yellow background color), which displays messages and status information.
  3. The bottom section (blue color) shows the AWG status and version. All that data is sent from AWG to the RemoteUI. The dark blue colored fields change during usage. They display actual AWG status, AWG output frequency and number of samples used for the calculated wave.

The control flow is attached as a picture and pdf. Please have a look it shows the possible actions a user can take and (most of) the status messages.

The user interface is programmed to be context sensitive, which means:

  • Only the buttons which make sense in a step in the control flow are enabled, the others are "greyed out".
  • When a wave is selected the parameters which can be adjusted for that wave are displayed.
  • When a wave is selected amplitude, offset and the parameters are set to a default value, so if you press the setup generator button, you get a consistent wave as output.
  • All parameters are bracketed, so you cannot adjust a parameter to out of range.
  • Amplitude and Offset are intentionally not bracketed, this gives flexibility to the user, e.g. to generate "clipped" waves by adjusting the offset or increasing the amplitude.

Downloads

Using the Remote UI

FK3ZXL2L0NV3JX6.png
runningAWG.png

Connecting the RemoteUI to the AWG:

RemoteUI and AWG connect with a handshake. When you plug the AWG to the computer's USB port it starts up and blinks once the onboard LED to signal that it is ready for connection. Start the RemoteUI as described in the installation sections, enter the port and press the connect to AWG button.

It does not matter if you start the RemoteUI first or plug the AWG first to the computer's USB port, just make sure the AWG is plugged to the USB of the computer before you click the connect to AWG button.

If the connection is established, the current status changes to "connected to AWG on port..." and the AWG status shows connected

If you start the RemoteUI python program either a terminal/console window is open or python opens one. In that terminal window python displays print() and error messages of the python program. The picture attached shows an example of messages upon connection, after pressing the setup generator button and after disconnect.

Remark: If you unplug and re-plug the USB cable, make sure you check if the port is still the same, esp. on Linux systems the port may change

Setting up a wave and start the AWG output:

The AWG is programmed with the following steps:

  1. Select a function using the function radio buttons
  2. Enter a frequency and frequency range (frequency can be a float number e.g. 8.634 kHz)
  3. Adjust Amplitude and offset (if needed)
  4. Adjust parameters (if needed)
  5. press the setup generator button

The AWG calculates the wave and starts outputting the wave. The AWG flashes the onboard LED four times and the AWG status in the RemoteUI changes to "running".

You can repeat steps 1. - 4. as often as you like to change the function, frequency or parameters. Pressing the setup generator button programs the generator with the entries you made. You do not need to press stop generator between changes.

Pressing the stop generator button stops the output. You can restart the generator by pressing the setup generator button or close the connection with the disconnect AWG button.

If you close the window, you are asked if you want to quit, if you answer yes, the connection to the AWG will be reset and the program will be closed.

Error Handling, Tips, Improvement Ideas

AWG_Error.png
variables.png

Error handling:

  • Should a user produce an error, the program displays a message in the current status field.Typically the user can recover by changing an entry or press a (different) button.
  • Program errors, which cannot be recovered result in an Error message (see example picture). The user will need to exit the program by pressing the disconnect and close button. The program tries to reset the connection to the AWG, the AWG does a soft reset and returns to the state, where the RemoteUI can open the connection again once restarted.
  • Should the program not be able to reset the AWG connection upon exiting from an error state, the user needs to press the AWG's reset button or unplug and re-plug the USB cable (hard reset).

Tips:

  • Be aware of the fact that the calculated frequency will change in steps due to the digital nature of the AWG. So the frequency generated my be slightly off the frequency you entered. This frequency error is small but increases with increasing frequency. The frequency steps can be reduced to a certain extent by increasing the number of samples used.
  • There are two variables in the file AWGremote.py you might want to change (refer to attached picture):
  • The variable interface_port on line 72 defines the default port. If you are working with the same computer all the time, you might want to change the value to the port you always use. E.g. on Windows it is a COMxx port. Changing the variable avoids that you have to override the port each time you start the RemoteUI. Save the file after the change was made.
  • The variable maxsamp_values (line 68) holds the list with the valid numbers of samples the AWG uses to calculate the wave. You can add or remove values. Be aware the value must be a multiple of 4 and if you enter values larger than 4096, you need to adjust the buffer size in the file AWG.py in lines 81 and 82 as well to the largest number of samples you want to use. If you use a large number, make sure the RP2040 does not run out of memory.
  • If you are not satisfied with the wave generated, try to adjust the parameters, amplitude and/or offset and increase or decrease the number of samples. This way the wave output can be improved in many cases.
  • For higher frequencies lower number of samples might result in less jitter.
  • The RP2040 CPU can drive small loads only. If your load is too high, the output signal gets small and/or distorted. Then you need to add an output stage. (see Step 8 or build the AWG hardware with an class AB output stage)
  • If you work with higher frequencies you might get distorted waves, because the output/cable impedance do not match. Then you should add an output amplifier (Step 8).

Improvement Ideas:

  • The AWG can basically generate any wave you want. A functionality to calculate a wave on your PC and download the wave file to the AWG would be a nice extension.
  • The RemoteUI is programmed with fix geometry, so it does not resize while changing the window size. This could be one improvement, esp if screens with less than 1024x768 resolution are used (e.g. small Raspberry Pi displays).

Any comments, thoughts, improvements are very welcome.

A Simple Output Amplifier

video_amp.png
IMG_0108.jpg

One benefit of the RemoteUI is that you just need a RP2040 Pico board and a few components to build an AWG. However one limitation is the low output current of the RP2040 GPIO pins.

This Step provides a very simple solution, which is built around the AD8055AN video Amplifier. Find the schematics, BOM and a picture of the board I use attached to this step.

You can connect the amplifier (amp) with two short bread board cables to the AWG board, which works nicely even at higher frequencies. See picture in Step Supplies. As an alternative use your favorite HF connectors.

Remarks and specifications

  • The RP2040's output swing of 3.2Vpp can over-drive the input stage of the AD8055. To prevent this R1 is added, to reduce the amp's input signal by 10%.
  • The amp's gain is set to 2, with the resistors R2 and R3.The output swing is max. 6.2Vpp.
  • By changing R4 you can adjust the output impedance, but R4 needs to be minimum 27 Ohms to drive capacitive loads (which you always have to some degree)
  • The rise time of the RP2040’s GPIOs is ~11ns (may be faster, as the best scope probe I have has 8pf input capacitance). This can lead to overshooting signals and overdrive the AD8055 input stage. I added optional C2 to limit rise time. Actually I did not need it on my board.
  • You need a +/- 5V power supply being able to supply 200mA current as the output stage of the AD8055 can drive up to 130mA.
  • My test showed that this amp can drive loads down to 50 Ohm impedance.
  • If you need an AD8055 datasheet you can find it attached to my other instructable.

Downloads