serial通信で制御設定を変える

serial通信でポート制御設定を変える

// L->H(2sec)->L(val)->H(2sec)

#define LED_PIN 13

int blinkDelay = 500;

int LEDState = LOW;
int data = 1000;
void setup() {
  Serial.begin(115200);
  Serial.setTimeout(10);
  Serial.println("start");
  pinMode(LED_PIN, OUTPUT);
}

void loop() {
  if (Serial.available() > 0) {
    data = Serial.parseInt();
    if ((data >= 100) && (data <= 4000)) {
      blinkDelay = data;
    }
  }

//  if (LEDState == LOW) {
//    LEDState = HIGH;
//  }
//  else {
//    LEDState = LOW;
//  }
  Serial.println(blinkDelay);
  digitalWrite(LED_PIN, HIGH);
  delay(2000);
  digitalWrite(LED_PIN, LOW);
  delay(blinkDelay);
  blinkDelay +=100;

}

matplot tips 色指定 fill_between stem

検索: fill_between matplot sabopy.com

matplotlib.collections — Matplotlib 3.6.0 documentation

www.yutaka-note.com

# https://helve-blog.com/posts/python/numpy-fast-fourier-transform/
# https://sabopy.com/py/matplotlib-110/


import numpy as np
import matplotlib.pyplot as plt

N = 1024            # サンプル数
dt = 0.001          # サンプリング周期 [s]
f1, f2 = 50, 120    # 周波数 [Hz]

def func(t):
    return 1.5*np.sin(2*np.pi*f1*t) + np.sin(2*np.pi*f2*t) + 3 # 信号


t = np.arange(0, N*dt, dt) # 時間 [s]
print(t)
#x = 1.5*np.sin(2*np.pi*f1*t) + np.sin(2*np.pi*f2*t) + 3 # 信号
x =func(t)


fig, ax = plt.subplots()
ax.plot(t, x)
# ax.set_xlim(0, 0.1)
ax.set_xlabel("Time [s]")
ax.set_ylabel("Signal")
ax.grid()
#t_ = np.arange(0.04, 0.6, dt)
#ax.fill_between(t_,func(t_),fc="0.8",ec="0.5")
plt.show()


F = np.fft.fft(x) # 変換結果
freq = np.fft.fftfreq(N, d=dt) # 周波数

fig, ax = plt.subplots(nrows=3, sharex=True, figsize=(6,6))
ax[0].plot(F.real, label="Real part")
ax[0].legend()
ax[1].plot(F.imag, label="Imaginary part")
ax[1].legend()
ax[2].plot(freq, label="Frequency")
ax[2].legend()
ax[2].set_xlabel("Number of data")
plt.show()

Amp = np.abs(F/(N/2)) # 振幅

fig, ax = plt.subplots()
ax.plot(freq[1:int(N/2)], Amp[1:int(N/2)])
ax.set_xlabel("Freqency [Hz]")
ax.set_ylabel("Amplitude")
ax.grid()

#ax.fill_between(freq[1:int(N/2)],Amp[1:int(N/2)])
ax.fill_between(freq[5:50],Amp[5:50],fc="tab:blue")

plt.show()

もしくはstemをつかう。

qiita.com

VTF (dooley)

import math
import numpy as np
import matplotlib.pyplot as plt

#vtf = 5.05*math.exp(-0.138 * math.pi*300/180 * u ) * ( 1 - math.exp(-0.1 * math.pi * 300/180 * u) )

u = np.linspace(0, 10, 101)

#print(u)
#print(u.size)

vtf = np.empty(u.size)
for i in range(u.size):
    vtf[i] = 5.05*math.exp(-0.138*math.pi*300/180*u[i])*(1-math.exp(-0.1*math.pi*300/180*u[i]))

#print(vtf)

plt.plot(u, vtf)
plt.show()

FFT 参考

helve-blog.com

import numpy as np
import matplotlib.pyplot as plt


N = 1024            # サンプル数
dt = 0.001          # サンプリング周期 [s]
f1, f2 = 50, 120    # 周波数 [Hz]

t = np.arange(0, N*dt, dt) # 時間 [s]
x = 1.5*np.sin(2*np.pi*f1*t) + np.sin(2*np.pi*f2*t) + 3 # 信号

fig, ax = plt.subplots()
ax.plot(t, x)
# ax.set_xlim(0, 0.1)
ax.set_xlabel("Time [s]")
ax.set_ylabel("Signal")
ax.grid()
plt.show()


F = np.fft.fft(x) # 変換結果
freq = np.fft.fftfreq(N, d=dt) # 周波数

fig, ax = plt.subplots(nrows=3, sharex=True, figsize=(6,6))
ax[0].plot(F.real, label="Real part")
ax[0].legend()
ax[1].plot(F.imag, label="Imaginary part")
ax[1].legend()
ax[2].plot(freq, label="Frequency")
ax[2].legend()
ax[2].set_xlabel("Number of data")
plt.show()

Amp = np.abs(F/(N/2)) # 振幅

fig, ax = plt.subplots()
ax.plot(freq[1:int(N/2)], Amp[1:int(N/2)])
ax.set_xlabel("Freqency [Hz]")
ax.set_ylabel("Amplitude")
ax.grid()
plt.show()

プリンタ不具合

https://www2.epson.jp/support/manual/data/ink/scs30650/SCSBEHB_C.PDF

https://www.onyxgfx.com/wp-content/uploads/2014/11/ONYX%E3%83%81%E3%83%A5%E3%83%BC%E3%83%88%E3%83%AA%E3%82%A2%E3%83%AB_%E3%82%BF%E3%82%A4%E3%83%AB%E3%83%AF%E3%83%BC%E3%82%AF%E3%83%95%E3%83%AD%E3%83%BC%E3%82%92%E4%BD%BF%E7%94%A8%E3%81%99%E3%82%8B.pdf

tmp

Version 4 SHEET 1 880 680 WIRE -304 -32 -304 -96 WIRE -128 -32 -128 -96 WIRE 208 -32 208 -96 WIRE -304 112 -304 48 WIRE -128 112 -128 48 WIRE 208 144 208 48 WIRE 160 224 64 224 WIRE 208 336 208 240 WIRE 208 464 208 416 FLAG 208 464 0 FLAG 208 -96 Vpri FLAG -304 -96 Vpri FLAG -304 112 0 FLAG -128 112 0 FLAG -128 -96 Vgs FLAG 64 224 Vgs SYMBOL nmos 160 144 R0 SYMATTR InstName M1 SYMATTR Value R6020PNJ SYMBOL ind 192 -48 R0 SYMATTR InstName L1 SYMATTR Value 1m SYMBOL res 192 320 R0 SYMATTR InstName R1 SYMATTR Value 1 SYMBOL voltage -304 -48 R0 WINDOW 123 0 0 Left 0 WINDOW 39 0 0 Left 0 SYMATTR InstName V1 SYMATTR Value 390 SYMBOL voltage -128 -48 R0 WINDOW 123 0 0 Left 0 WINDOW 39 0 0 Left 0 SYMATTR InstName V2 SYMATTR Value PULSE(0 5 100m 0 0 500m 1) TEXT -338 488 Left 2 !.tran 5s