Coil simulator (mono coil)

モノコイルのシミュレーター ### Pulse magnet simulator v0.1 ### by A. Ikeda (UEC-Tokyo, 30 April 2022) ### references ### 1. Example program (3) in https://qiita.com/sci_Haru/items/b8d5c9cfe64c4366630a ### 2. A program for iGor pro, Master thesis, Takeshi Nakamura, Y. H. Matsuda lab., Univ. of Tokyo (2010) ### 3. Pulse magnet for high field generation, N. Miura (2008) # # # # # # # # # # # # # # # # # # # # # # # # # # # Imports # # # # # # # # # # # # # # # # # # # # # # # # # # # import numpy as np import matplotlib.pyplot as plt # %matplotlib inline # plt.style.use('./ai.mplstyle') # %matplotlib tk res_x = [] res_y = [] reserve_v = [] reserve_i = [] reserve_tp = [] reserve_t = [] reserve_bf = [] # # # # # # # # # # # # # # # # # # # # # # # # # # # Input parameter # # ...

Raspberry Piでリレーを動かす

そろそろミニバンクをつくらねば、ということで少しやる。

野田くんたちに任せっきりになっていたので申し訳ない。

このリレーをつかってみる。うごきました。



RaspberryPi4にリレーをつないで、GPIOをpythonでいじります。
tkinterをつかってGUIもつくりました。
RPiにVNC(リモートデスクトップ)接続もできたので、
遠隔操作もできました。

これはいいですね。
あとADコンバータをつなげば、ミニバンクのUIはできそう。

残念ながらRPiがなかなか手に入らない様子ですが。

 
コードはこちら
            
from tkinter import *
from tkinter import ttk
import RPi.GPIO as GPIO # RPi.GPIOモジュールを使用
import time

#GPIO initial set up
gpio_relay = [4, 17, 27, 22]
GPIO.setmode(GPIO.BCM)
for i in range(4):
    GPIO.cleanup(gpio_relay[i])
for i in range(4):
    GPIO.setup(gpio_relay[i], GPIO.OUT)
    GPIO.output(gpio_relay[i], 0)
    

#tk initial set up
root = Tk()
root.title('Checkbutton 1')


# Frame
frame1 = ttk.Frame(root, padding=(10))
frame1.grid()

# Checkbutton 1
v1 = BooleanVar()
v1.set(0) # 初期化
cb1 = ttk.Checkbutton(
    frame1, padding=(30), text='Relay 1',
    variable=v1,
    command=lambda: GPIO.output(gpio_relay[0], v1.get()))

# Checkbutton 2
v2 = BooleanVar()
v2.set(0) # 初期化
cb2 = ttk.Checkbutton(
    frame1, padding=(30), text='Relay 2',
    variable=v2,
    command=lambda: GPIO.output(gpio_relay[1], v2.get()))

# Checkbutton 3
v3 = BooleanVar()
v3.set(0) # 初期化
cb3 = ttk.Checkbutton(
    frame1, padding=(30), text='Relay 3',
    variable=v3,
    command=lambda: GPIO.output(gpio_relay[2], v3.get()))

# Checkbutton 4
v4 = BooleanVar()
v4.set(0) # 初期化
cb4 = ttk.Checkbutton(
    frame1, padding=(30), text='Relay 4',
    variable=v4,
    command=lambda: GPIO.output(gpio_relay[3], v4.get()))


exit_button = ttk.Button(
    root,
    text='Exit',
    command=lambda: root.quit()
)
            
# Layout
cb1.grid(row=0, column=0)
cb2.grid(row=0, column=1)
cb3.grid(row=0, column=2)
cb4.grid(row=0, column=3)
exit_button.grid(row=1, column=0, columnspan=2)

root.mainloop()
    
for i in range(4):
    GPIO.cleanup(gpio_relay[i])

コメント

このブログの人気の投稿

しばらく、うまく見られなかった・・・・しかし解決の兆し