Author Topic: Raspberry Pi for GPIB and data analysis: very easy and fully equipped  (Read 15693 times)

0 Members and 1 Guest are viewing this topic.

Offline martinr33

  • Frequent Contributor
  • **
  • Posts: 363
  • Country: us
Re: Raspberry Pi for GPIB and data analysis: very easy and fully equipped
« Reply #50 on: August 21, 2022, 04:02:06 am »
1) Using the HP E5810 and a Data Proof scanner, NI MAX and Python.

The scanner needs a tweak to its termination, or it won't action the request.
Example working code:

inst = rm.open_resource(DataProof)       #PyVisa function - "DataProof" is a fully-formed VISA address string. inst is the short version.
inst.write_termination = '\n'                   # This is the critical change. The scanner won't work otherwise.
inst.write("A05")                                    # Set scanner to A05

On the list: create a library function for this unit for Phil's library.


2) You must use a 32-bit version of the RPi OS, or you will get the painful failures recently reported. I am using a PC to develop, but the code will easily move to the Pi.

 


 
The following users thanked this post: e61_phil, alm

Offline MiDi

  • Frequent Contributor
  • **
  • Posts: 600
  • Country: ua
Re: Raspberry Pi for GPIB and data analysis: very easy and fully equipped
« Reply #51 on: August 21, 2022, 07:10:29 am »
2) You must use a 32-bit version of the RPi OS, or you will get the painful failures recently reported. I am using a PC to develop, but the code will easily move to the Pi.

Seems to be a problem with package management and jupyterlab, maybe only on 64bit raspi OS: Install jupyterlab in pip3 throws 'TypeError: expected string or bytes-like object'

Another report of the same error: PhilippCo/meas_rpi: Error when installing
 

Offline martinr33

  • Frequent Contributor
  • **
  • Posts: 363
  • Country: us
Re: Raspberry Pi for GPIB and data analysis: very easy and fully equipped
« Reply #52 on: August 25, 2022, 01:25:23 am »
OK, more baby steps on the way to making Philippe's system work. My end goal is the Raspberry Pi system using Philippe's library and Jupyter notebooks, but my first effort is to get to a functional system on the PC.

Please, no complaints, I know this is ugly and basic. But it also works to get folks started.

You'll need to complete each one, mostly in order, to avoid getting stuck.

1) Get your GPIB adapter or E5810 working and scan the instruments. Make sure you see what you expect to see!
The instruments must be listed for the next step (I think...), if your adapter has simple management software (it may not)

2) Load NI Explorer. This is your basic GPIB interface library. Find and install your instruments in the GPIB tree. They have long names, like the ones in my example code. In the snip attached, these are connected to the E5810.

 
3) Load Thonny. https://thonny.org/.
This is an easy starter environment. Later, Jupyter notebooks and the Raspberry Pi.

4) Load my test program, tweak for your instruments, and walk through any library errors. Thonny has many libraries already available, The only one you might have to hunt down is PyVISA.
The code is messy, and includes a lot of redundant or irrelevant stuff that I left in for reference. Also, the 34420A setup causes non-critical errors.

5) Start your first logging!

Once you are here, you can write code for many instruments.

6) At this stage, we are still hacking at the lowest level. This is where Philippe's libraries will help us. So get this started.

Next steps:
 - Philippe's libraries
 - Jupyter notebooks
 - Move to Raspberry Pi for logging (we'll keep development on the PC)








#This section is not essential, as the instrument names defined in here are local. However, it shows you how a Python function appears.
def InstrumentNames():
#Instrument inventory and aliases. Note that these are local names, so pretty useless.
    HP34420A = 'TCPIP0::192.168.0.110::gpib0,10::INSTR'
    HP3458A2 = 'TCPIP0::192.168.0.110::gpib0,20::INSTR'
    print ('\033[1m','\n',"Instrument    Addr   Name      GPIB Address",'\033[0m')
    print ("HP 34420A      10     HP34420A ",HP34420A)
    print ("HP 3458A2      20     3458A-2  ",HP3458A2)




#These three lines are critical.
import sys
import pyvisa
import time

localtime = time.asctime( time.localtime(time.time()) )

rm = pyvisa.ResourceManager()   #Shorthand for use later on.  when you use "rm", you get the component on the right - in this case, a function.

print("\nList of Instruments Detected\n",rm.list_resources())  # ...so here you see pyvisa.ResourceManager.list_resources()

HP34420A = 'TCPIP0::192.168.0.110::gpib0,10::INSTR'    #These next half dozen populated lines are not essential, but they do list your instruments.
HP3458A2 = 'TCPIP0::192.168.0.110::gpib0,20::INSTR'

print ('\033[1m','\n',"Instrument    Addr   Name      GPIB Address",'\033[0m')
print ("HP 34420A      10     HP34420A ",HP34420A)
print ("HP 3458A2      20     3458A-2  ",HP3458A2)

InstrumentNames()

#34420A init                                #I think this section is also redundant, except maybe for the timeout. Also, the INITs in this code do not work right.
inst = rm.open_resource(HP34420A)
inst.write("*RST;*CLS")
inst.write(":SENS:FUNC:VOLT;:SENS:CHAN 1;:SENS:VOLT:CHAN1:RANG:AUTO ON")
inst.write("VOLTage:DC:RESolution:MIN;VOLTage:DC:NPLCycles:MAX")
inst.timeout = 10


#This is where things start to happen.

f = open("Voltage_standards4.txt", "w")  #w means open for write. CHANGE TO #A (append) if you want to continue runs.
#f.write("Time  \t\t\t\t\t\t2142A     \t\t34420A-1        \t\t34420A-2\t\t8508A\r\n")



#open and read the file after the appending:
#f = open("demofile2.txt", "r")
#print(f.read())
#line = line.rstrip('\r\n') # strip out all tailing whitespace

#34420A commands
#SENSe1:VOLTage:RANGe 10 Channel 1 range 10 mV
#SENSe2:VOLTage:RANGe .1 Channel 2 range 10 mV
#ROUTe:TERMinals FRONt1 Select channel 1
#READ? Channel 1 measurement
#ROUTe:TERMinals FRONt2 Select channel 2
#READ?


#And finally the main loop.

i=1
while (i<50000):
    f = open("Voltage_standards4.txt", "a")
    i=i+1
    f.write(time.asctime(time.localtime(time.time())))
    f.write("\t")
   
   
    inst = rm.open_resource(HP34420A)
    inst.write("ROUTe:TERMinals FRONt1;")
    f.write(inst.query(":READ?").rstrip('\r\n'))
    f.write("\t")
   
   
    inst = rm.open_resource(HP34420A)
    inst.write("ROUTe:TERMinals FRONt2")
    f.write(inst.query(":READ?").rstrip('\r\n'))  #strip return and newline characters so we get one line per set of readings
    f.write("\n")   


print ("Complete!")

« Last Edit: August 25, 2022, 01:28:41 am by martinr33 »
 

Offline ErnieM

  • Newbie
  • Posts: 1
  • Country: us
Re: Raspberry Pi for GPIB and data analysis: very easy and fully equipped
« Reply #53 on: December 19, 2022, 04:56:10 pm »
krulls: I know it has been near forever since you last posted but based on this thread (the OP actually) I was able to get the install to work... but NOT on a Pi 3.

My first attempt on a Pi 3 worked somewhat as I got the driver to install. Connecting an Agilent USB->GPIB got me the beloved green connection light, but little else worked as the back end would not install. I figured out that the old Pi 3 I was using had an old incompatible version of Python, so after struggling to update that I just went to a new copy of NOOBS, but again the install would stall and no joy was there.

I managed to find a Pi 4 I has tucked away, made a clean NOOBS install, and the package installed first time no drips, runs, or errors.

e61_phil: I'm thinking that the Pi 3 has some incompatibility with the package. Besides the unobtanium nature of the Pi these days I am still thrilled with this result as I have been attempting to get GPIB support on a Pi off and on for a few years now.

Thank you for this effort!
 
The following users thanked this post: e61_phil

Offline martinr33

  • Frequent Contributor
  • **
  • Posts: 363
  • Country: us
Re: Raspberry Pi for GPIB and data analysis: very easy and fully equipped
« Reply #54 on: December 19, 2022, 05:04:37 pm »
One thing - you must use the 32-bit version of the OS.
 

Offline mendip_discovery

  • Frequent Contributor
  • **
  • Posts: 851
  • Country: gb
Re: Raspberry Pi for GPIB and data analysis: very easy and fully equipped
« Reply #55 on: December 19, 2022, 05:18:26 pm »
I found I needed to run a 32bit OS as I was having a nightmare with my 2B but read about some issues with 16bit so I tried it and it worked a charm but I wasnt 100% sure so didnt riase it on github as a requirement.
Motorcyclist, Nerd, and I work in a Calibration Lab :-)
--
So everyone is clear, Calibration = Taking Measurement against a known source, Verification = Checking Calibration against Specification, Adjustment = Adjusting the unit to be within specifications.
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf