Operate an oscilloscope with a Raspberry Pi

1.First of all

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. scpi commander

2. Wiring

|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.

3. Program

--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()

4. Conclusion

――If you use the foot switch, you can operate it with your feet even if both hands are occupied.

5. Reference materials

This is an article that I used as a reference when creating this article.

-Use GPIO of Raspberry Pi from Python

X. Appendix How to find the VISA address

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

Operate an oscilloscope with a Raspberry Pi
Using a webcam with Raspberry Pi
Build a Tensorflow environment with Raspberry Pi [2020]
Make a wash-drying timer with a Raspberry Pi
Create a car meter with raspberry pi
GPGPU with Raspberry Pi
DigitalSignage with Raspberry Pi
Create a socket with an Ethernet interface (eth0, eth1) (Linux, C, Raspberry Pi)
Mutter plants with Raspberry Pi
A memorandum when making a surveillance camera with Raspberry Pi
Let's operate GPIO of Raspberry Pi with Python CGI
Create a web surveillance camera with Raspberry Pi and OpenCV
Create an LCD (16x2) game with Raspberry Pi and Python
Make an air conditioner integrated PC "airpi" with Raspberry Pi 3!
I made a resource monitor for Raspberry Pi with a spreadsheet
getrpimodel: Recognize Raspberry Pi model (A, B, B +, B2, B3, etc) with python
I made a surveillance camera with my first Raspberry PI.
Creating a temperature / humidity monitor with Raspberry Pi (pigpio version)
[Raspberry Pi] Stepping motor control with Raspberry Pi
Operate a receipt printer with python
Servo motor control with Raspberry Pi
OS setup with Raspberry Pi Imager
Try L Chika with raspberry pi
VPN server construction with Raspberry Pi
Try moving 3 servos with Raspberry Pi
Control the motor with a motor driver using python on Raspberry Pi 3!
Let's make a cycle computer with Raspberry Pi Zero (W, WH)
I made a web server with Raspberry Pi to watch anime
Christmas classic (?) Lighting a Christmas tree with Raspberry Pi and Philips Hue
Make a thermometer with Raspberry Pi and make it viewable with a browser Part 4
Make a Kanji display compass with Raspberry Pi and Sense Hat
[Note] Using 16x2-digit character LCD (1602A) from Python with Raspberry Pi
Let's make an IoT shirt with Lambda, Kinesis, Raspberry Pi [Part 1]
Measure SIM signal strength with Raspberry Pi
[Raspberry Pi] Add a thermometer and a hygrometer
Hello World with Raspberry Pi + Minecraft Pi Edition
Get BITCOIN LTP information with Raspberry PI
Try fishing for smelt with Raspberry Pi
Programming normally with Node-RED programming on Raspberry Pi 3
Improved motion sensor made with Raspberry Pi
Try Object detection with Raspberry Pi 4 + Coral
Working with sensors on Mathematica on Raspberry Pi
Use PIR motion sensor with raspberry Pi
Infer Custom Vision model with Raspberry Pi
Get data from an oscilloscope with pyVISA
Inkbird IBS-TH1 value logged with Raspberry Pi
Working with GPS on Raspberry Pi 3 Python
A memo to simply use the illuminance sensor TSL2561 with Raspberry Pi 2
Detect analog signals with A / D converter using python on Raspberry Pi 3!
[Electronic work] I made a Suica touch sound detector with Raspberry Pi
Make a wireless LAN Ethernet converter and simple router with Raspberry Pi
[Python + PHP] Make a temperature / humidity / barometric pressure monitor with Raspberry Pi
I tried to make a traffic light-like with Raspberry Pi 4 (Python edition)
Discord bot with python raspberry pi zero with [Notes]
Delete files that have passed a certain period of time with Raspberry PI
[Python] Make a game with Pyxel-Use an editor-
Make a monitoring device with an infrared sensor
Build a Django environment on Raspberry Pi (MySQL)
Try using a QR code on a Raspberry Pi
I got an error when I put opencv in python3 with Raspberry Pi [Remedy]
Source compile Apache2.4 + PHP7.4 with Raspberry Pi and build a Web server --2 PHP introduction