Connect the tactile switch to GPIO of Raspberry Pi, and when the switch is pressed, ": RUN" ": STOP" of [SCPI command](https://www.google.co.jp/search?hl=ja&as_q=SCPI command) Is sent to the oscilloscope. Use pyVISA to send SCPI commands.
|BCM|Physical|I/O|function |---+--------+---+---- | 2 |3 |IN |RUN command(:RUN)Issue | 3 |5 |IN |STOP command(:STOP)Issue |17 |11 |OUT|LED lighting
The LEDs are connected via a 3kΩ current limiting resistor.
--Please install pyUSB, pyVISA, pyVISA-py on Raspberry Pi with pip command in advance. --The VISA address is hard-coded (see the appendix for how to find the VISA address) --Run with sudo python scpi-commander.py (sudo important!)
scpi-commander.py
import RPi.GPIO as GPIO
import time
import visa
PORT_RUN = 2
PORT_STOP = 3
PORT_LED = 17
VISA_ADDR = "USB0::6833::1230::DS1Zxxxxxxxxxx::0::INSTR"
GPIO.setmode(GPIO.BCM)
GPIO.setup(PORT_LED, GPIO.OUT)
GPIO.setup(PORT_RUN, GPIO.IN)
GPIO.setup(PORT_STOP,GPIO.IN)
def open_dso():
rm = visa.ResourceManager()
resources = rm.list_resources()
#print(resources)
try:
dso = rm.open_resource(VISA_ADDR)
except:
print("Not Found:", resources)
else:
pass
#print("Detected")
return dso
def main():
try:
dso = open_dso()
except:
print("DSO Open Failed, exit.")
exit(1)
else:
print("DSO Open Success.")
try:
while True:
port_run = GPIO.input(PORT_RUN)
port_stop = GPIO.input(PORT_STOP)
if port_run == GPIO.LOW:
GPIO.output(PORT_LED,GPIO.HIGH)
#print(dso.query("*IDN?"))
print(":RUN")
dso.write(":RUN")
while(GPIO.input(PORT_RUN)==GPIO.LOW):
#print("pressing...")
time.sleep(0.1)
if port_stop == GPIO.LOW:
GPIO.output(PORT_LED,GPIO.HIGH)
print(":STOP")
dso.write(":STOP")
while(GPIO.input(PORT_STOP)==GPIO.LOW):
#print("pressing...")
time.sleep(0.1)
GPIO.output(PORT_LED,GPIO.LOW)
time.sleep(0.1)
except KeyboardInterrupt:
GPIO.cleanup()
main()
――If you use the foot switch, you can operate it with your feet even if both hands are occupied.
This is an article that I used as a reference when creating this article.
-Use GPIO of Raspberry Pi from Python
Connect the oscilloscope and Raspberry Pi (or PC) in advance via USB.
> sudo python
>>> import visa
>>> rm = visa.ResourceManager()
>>> print(rm.list_resources())
('USB0::0x1AB1::0x04CE::DS1Zxxxxxxxxxx::0::INSTR')
Recommended Posts