Saturday, November 7, 2020

In the End, Windows Gets us All: Siglent, SigRok, VISA, and a Weekend of Lab Double Happiness

Sometimes you gotta solder and sometimes you gotta spend? I have been using junker/clunker laptops at my bench for years now, castoffs w broken trackpads, slow CPUs, dim screens. Some of them Linux, some of them Macinsosh, occasionally Windows. Too much junk, and it had to stop. 

New NUC Windows 10 System

Sooo.....I got out the trusty credit card and bought an Intel NUC10I7FNH running Windows 10 Pro. Yes, Windows. Yes, Microsoft. I guess this day had to come. Too many software packages I wanted to run seem to work best with Windows, and perhaps the Windows Operating System gets us all in the end.  

Intel based desktops may one day be a thing of the past, but for now, the NUC abides; it's tiny, bench friendly, and packs a wicked punch in a small footprint. OK, it was a fair amount of dough. I'll deal with that later.

OK what to run on it?

Sigrok Logic Analysis:  If you haven't heard of Sigrok, run, don't walk, and get it here. It's open Source/free software that gets you (among many other things) an electronics logic analyzer at super low cost.  You can buy a super cheap USB Saleae clone (neighbor and fellow audio geek mvcl gave me a $10ish 24Hhz/8 probe he had sitting around as a gift--works!) and get going for next to nothing. 

Pulseview  is the logic analysis GUI tool that comes with Sigrok. I find myself using Pulseview all the time. This is extremely capable software! Something like 130 different protocols decoded (here) which includes "stack decoders"--what your reads mean without having to have an IC's datasheet in your lap; I.O formats (here); DMM UI is here. CLI here. Open source; which means makers and hobbiests like me can afford to put this on our bench and learn how things really work without investing a fortune on bench tools, which most non professionals simply aren't going to do. And if you want to dig even further you go study the programming that makes the tools you use to see how things work, work. This sort of thing restores my faith in humanity.  Required viewing: extremely informative video and tutorial, from one of the guys who wrote Pulseview, is here. "Windows Wins": I couldn't get the Pulseview or CLI Mac DMGs to install on my Macbook Pro; then I spent an entire evening trying to compile Sigrok from source on Fedora 29 before giving up and installing the it via yum  Update: running Sigrok and Fedora 29 keeps crashing, I am only using this on Windows now....

Windows 10 however--yes, Pulseview works great. You have to install the Vista or later driver using the "Zadig" tool (here, it was a bit scary installing this?) to use your Saleae clone with Windows, but, it works.  

MVCL's gifted $10 Saleae Clone. Note the broken grabber. Yeh, I did that.

Next up: Eagle and Fusion 360. This is for PCB layout and 3D design. I have argued about Eagle vs. Kicad at length with my maker friends; they tell me anyone who doesn't use Kicad should be shot; I won't discuss that here. As a long time subscriber to pay Eagle, the folks at Autodesk throw in a licensed copy of Fusion 360 "for free" to keep me in their world. It worked; I have no complaints about any of it, except, Eagle is an odd program, but an odd program I sort of know. There must be a girlfriend analogy in that somewhere? "Windows Wins": I have always used Eagle on Windows, pretty much. I have it on Mac which I never use. For what I do, it's good enough.

Next up: 3D printing. Been there, done that, post is here. Yes, it all works on Windows. Let's move on.

Next: Development. I installed PyCharm Python IDE and Microsoft Visual Studio Community for C/C++  programming.  Amazing that there are personal versions of these for Windows for $0.  "The Cherno" has great Youtube videos covering Virtual Studio Community on Windows tricks, here. And: for AVR development: Atmel Studio 7 for Windows, get that here. Good low key videos about basic set up and use for Atmel Studio is here

For compiling C++, outside of Visual Studio, I installed minGW, mostly to debug C functions for embedded systems without having to flash an MPU over and over.  After getting that going however, I discovered a C compiler "cl" (compile/link?) that can be run from the Visual Studio terminal, info here.  Works great!

Next: Linux on Windows, i.e.: Cats, sleeping with dogs? Turns out Windows has pretty good and easy to install Linux virtualization you get for free (well, after you buy W10, right?). 

Check out WSL2 here. I didn't know about that. I got that along with the Fedora WSL build (here) since I mostly work with Redhat/Centos/Fedora Linux, but Ubuntu is available for free here as well as Debian, SUSE and a few others. Can WSL2 make tea and toast? To get at Windows data from the the Linux VM open the WSL2 Linux system and cd to /mnt/c/[windows_foldername], cool! 

"Windows Wins": I installed a Ubuntu VM, but then I burned up at least 5 hours trying to get x-windows running.  Two problems here: xwindows has to run on the windows host, and, it seems, WSL can't run systemd. So I don't see a good way to do this....but, I did find a way to get a GUI working on WSL2 Ubuntu, see video here. Another post about this is here. Both Windows RDP protocol to get at the Ubuntu GUI, and thus doesn't need a Windows Xserver daemon. Odd way to solve this problem but it works.  

Update 3-10-21 this is described in the videos above but I often find myself forgetting: if you follow the instructions to set up an xrdp GUI on Ubuntu, you need to start the xrdp daemon each time or else RDP session will fail.  

Command to do that:

sudo /etc/init.d/xrdp start

Another good tool for Linux folks on Windows is cygwin, which allows users to run familiar Linux commands right from  the Windows terminal (like grep).  I downloaded and did a default install.  You have to update environment PATH for the cygwin commands to be found by the OS, info about how to do that is here.

Bench Automation: I went down yet another rabbit hole because the bench tool automation provided by Sigrok doesn't support most of my Siglent bench devices. 

Yep--Siglent. I know there is discussion about Siglent's poor security measures, politics surrounding this stuff, etc., but I can't afford top shelf bench gear, and based on my own limited EE skills (read my posts, is it obvious?) it probably would be pearls before swine if I bought a gazillion dollar Keysight scope. Yep, for many of us, Siglent is affordable and works....from the trench-level viewpoint of your humble geeky audio blogger, Siglent stuff indeed rocks. 

Sigrok led me to online discussions of controlling all my Siglent bench gear with Python, which led me to National Instruments NI-VISA. That way all my lab bench gear can be controlled from the new W10 system and a Python front end I can create, any way I want. 

Put it on your NI-VISA: So what is VISA? Sort of like MIDI, a bunch of manufacturers got together and came up with the a protocol for that would work across their different wares. For those with way too much time, the Wiki is one sentence--read more about the history of the VISA protocol here. OK with that in place we can send read-only and "change a setting" sort of statements to our bench gear using a protocol called SCPI (I have heard this called "skippy").

OK, but, how to get SCPI going? Download free Windows (Windows only!) software from National (here).  Install all of that. 

Next, hook a USB cable between your computer and your lab gear. Ethernet works as well, assuming your bench device supports it.  

The other SCPI??


An aside: I work with IP networking all the time, so I tried to get ethernet going with my new NUC and  my various Siglent bench dookies that had an RJ45 jack; all worked well with static IPV4; all except my 3303 Siglent power supply.  IPv4 seemed buggy on that device--at the very least, the static IP settings seemed to get wiped each time I power cycled, but it was way more bizarre than that. I called up Siglent support, not expecting anything (when can you ever get decent tech support nowadays?) and to my amazement the tech at Siglent US support picked up the phone and talked to me!  He was super friendly and helpful, but due to covid didn't have a 3303 at his home work setup to test. He was going to work on it.....and, after some more emails back and forth--Siglent got back to me very quickly--GO SIGLENT!!--I ended up using USB, which NI-VISA supports, works well on the power supply, and now, happily, the 3303 is recognized just fine by the W10 computer. 

Back to it: NI-VISA, you installed that already right? gives you the necessary drivers for your W10 machine to talk to your bench gear. 

Next, you can use NI-MAX (it is included in the giant NI-VISA download) to search for and probe each device, and finally run basic commands--see the siglent how to here--to see if everything is working. 

AUTO-MATE: Python works with VISA turns out, and that seals the deal. As usual, different ways to skin this one, but for me, the Pyvisa module got it done; get that here. Running PyCharm Community (here) and the latest version of Python for Windows (here), I created this code to first recognize my bench gear, and then generate 2K ramp wave on CH1 of my Siglent SDG1025.  

Python code looks like this (Get the latest version of these SCPI python scripts from github, here.)

######################

import pyvisa

rm = pyvisa.ResourceManager()

print(rm.list_resources())

#terminal now shows all the VISA devices found.

# this should match what you see in NI-max

# Devices are long strings like what you see in the next line; set this to a pyvisa object.... 

avg = rm.open_resource('USB0::0xF4ED::0xEE3A::SDG10GAD1R1738::INSTR')

print(avg.query('*IDN?'))

# that prints out all your VISA stuff.....

#new waveform, ramp, 2K, 0 sym,

avg.write('C1:BaSic_WaVe WVTP,RAMP')

avg.write('C1:BaSic_WaVe SYM,0')

avg.write('C1:BaSic_WaVe FRQ,2000')

####################

TERMINATED? If you read the pyvisa docs (here) it talks about termination characters, necessary to get some SCPI devices to work.  Yes, seen that too.  For instance to read in details of my Siglent SPD3303X-E power supply using SCPI termination codes are critical, however this was not needed for the waveform generator code. 

An example;

#################
rm = pyvisa.ResourceManager()
#print(rm.list_resources())
print(rm)
a = rm.list_resources()
print(a)
p = rm.open_resource('USB0::0x0483::0x7540::SPD3XHBX2R0646::INSTR')

p.read_termination = '\n'
p.write_termination = '\n'
p.query('*IDN?')
#####################


OK here's some working code to set basics on a SPD3303X-E supply:

Update 12-28-20 I found I had to add some sleep() to the 3303 code as well or else sometimes the power supply would miss an updated settings push. 

Get the latest version of the SCPI python scripts from github, here.


import pyvisa
############CHANGE THIS####################
ch1 = 5  #voltage ch1
ch2 = 12  #voltage ch2
amp1 = .50 #max curr ch 1
amp2 = .20 #max chrr ch 2
#turn channels on or off
x = "On"
########################################
value1 = x.upper()
value2 = x.upper()
value3 = x.upper()

rm = pyvisa.ResourceManager()
#print(rm.list_resources())
#print(rm)
a = rm.list_resources()
print(a)
p = rm.open_resource('USB0::0x0483::0x7540::SPD3XHBX2R0646::INSTR')
p.read_termination = '\n'
p.write_termination = '\n'
p.query('*IDN?')
#qq = p.query('*IDN?')
#print(qq)
p.read_termination = '\n'
p.write_termination = '\n'
ch1volts = 'CH1:VOLTage ' + str(ch1)
ch2volts = 'CH2:VOLTage ' + str(ch2)
ch1curr = 'CH1:CURRent ' + str(amp1)
ch2curr = 'CH2:CURRent ' + str(amp2)
ch1onoff = 'OUTPut CH1,' + value1
ch2onoff = 'OUTPut CH2,' + value2
ch3onoff = 'OUTPut CH3,' + value3
p.write(ch1volts)
p.write(ch2volts)
p.write(ch1curr)
p.write(ch2curr)

p.write(ch1onoff)
p.write(ch2onoff)
p.write(ch3onoff)

From here, think of the possibilities, right?  For the waveform generator, how about every second the frequency jumps up 1K (or whatever) and when it gets to 10K goes back down to 1K. That's a simple loop, with the 2000 replaced by a variable. I can now really easily sweep frequencies from my waveform generator.  

For the power supply, read the voltage, and if it drops well below the voltage set initially, turn off the channel after say 2 seconds, since you probably have a short?

Of course there are other ways to do all this, but, VISA and Python makes it, really, too damn easy?

OK that's enough for one weekend. Yes, the NUC set me back, but the rest of it--cost me what--$10? No! It was all open source/free and the results are amazing. I think bench gear has become similar to home studio recording gear in that it used to cost a fortune but not any more, and best of all, if I can do this, well, anyone can. 

Until next time--don't mask debate--automate!

No comments:

Post a Comment

Minimalist Atmel 328 Development Board--How to Build One

Hello again:  if you've been following the last few posts you see that I am trying to use Arduino's IDE a lot less, and learning to ...