-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathesperienza2_sensoretemperatura.py
123 lines (108 loc) · 4.83 KB
/
esperienza2_sensoretemperatura.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
# -*- coding: utf-8 -*-
"""Esperienza2_SensoreTemperatura
Automatically generated by Colab.
Original file is located at
https://colab.research.google.com/drive/1fB8pf2G_8i24xfoCpHr6U4xYieE0dPjV
Laboratorio di Elettronica e Tecniche di Acquisizione Dati
#Esperienza 2: Digitalizzazione di un segnale proveniente dal sensore di temperatura LM35 mediante ADC sotto forma di termometro a LED
*Laura Francesca Iacob \\
Sara Pieri \\
Sara Schippa*
"""
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
"""# Andamento lineare LM35: ddp VS Temperatura"""
#LM35 lineare
plt.figure(figsize=(7, 4))
plt.style.use('default')
plt.title('Andamento lineare in temperatura LM35')
x=np.arange(-55, 151, 2)
y=10*x
plt.plot(x, y, color='red', label='y=(10mV/C°)x')
plt.grid()
plt.legend()
plt.xlabel('Temperatura [°C]')
plt.ylabel('Differenza di potenziale [mV]')
plt.show()
"""#Visualizzazione andamento dei dati atteso"""
#Array di dati (si segue il video finale in consegna +-)
t=np.array([0,0.5,1,1.5,2,2.5,3,3.5,3.5,4,4.5,5,5,5.5,6,6,6.5,7,7.5,8,8.5,9,9.5,10,10,10.5,11,11.5,12,12.5])
#26 campionamenti
led1=np.array([0,0,0,0,0,0,0,0,260,260,260,260,260,260,260,260,260,260,260,260,260,260,260,260,260,260,260,260,260,260])
#8 campionamenti+ (soglia 260), 4.5
led2=np.array([0,0,0,0,0,0,0,0,0,0,0,0,280,280,280,280,280,280,280,280,280,280,280,280,280,280,280,280,280,280])
#10 campionamenti+ (soglia 280), 5.5
led3=np.array([0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,300,300,300,300,300,300,300,300,300,300,300,300,300,300,300])
#12 campionamenti+ (soglia 300), 6.5
led4=np.array([0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,330,330,330,330,330,330])
#20 campionamenti+ (soglia 330), 10.5
ddp=np.array([224, 230, 231, 247, 250, 252, 258, 260, 260, 274, 281, 286, 286, 300, 303, 303, 309, 312, 318, 321, 324, 320, 333, 333, 332, 341, 341, 343, 344, 344])
digit=np.array([0,0,0,0,0,0,0,0,260,260,260,260,280,280,280,300,300,300,300,300,300,300,300,300,330,330,330,330,330,330])
#Grafico simulato
import matplotlib.pyplot as plt
plt.figure(figsize=(15,5))
plt.style.use('default')
plt.plot(t, ddp, label='Segnale analogico', color='black', lw=4.0)
plt.scatter(np.linspace(0, 12.5, 40), np.full(40, 260), color='grey', marker='_')
plt.scatter(np.linspace(0, 12.5, 40), np.full(40, 280), color='grey', marker='_')
plt.scatter(np.linspace(0,12.5, 40), np.full(40, 300), color='grey', marker='_')
plt.scatter(np.linspace(0,12.5, 40), np.full(40, 330), color='grey', marker='_')
plt.plot(t, led1, label='Led 1', color='#A3B56B', linewidth=9.0)
plt.plot(t, led2, label='Led 2', color='#78A161', linewidth=9.0)
plt.plot(t, led3, label='Led 3', color='#4D8C57', linewidth=9.0)
plt.plot(t, led4, label='Led 4', color='darkgreen', linewidth=9.0)
plt.plot(t, digit, color='yellow', label='Segnale digitale')
plt.legend()
plt.xlim(0,12.5)
plt.xlabel('Tempo [s]', fontsize=12)
plt.ylabel('Differenza di potenziale [mV]')
plt.grid()
plt.show()
"""##Neon :)"""
def neon_plot(x, y, l, col, ax=None):
if ax is None:
ax = plt.gca()
line, = ax.plot(x, y, zorder=6, label=l, color=col, lw=4.0)
for cont in range(20, 1, -1):
ax.plot(x, y, lw=cont, color=line.get_color(), zorder=5, alpha=0.05)
return ax
#Grafico simulato: neon1
plt.figure(figsize=(15,5))
plt.style.use('dark_background')
plt.plot(t, ddp, label='Segnale analogico', color='white', lw=4.0)
plt.scatter(np.linspace(0, 12.5, 40), np.full(40, 260), color='grey', marker='_')
plt.scatter(np.linspace(0, 12.5, 40), np.full(40, 280), color='grey', marker='_')
plt.scatter(np.linspace(0,12.5, 40), np.full(40, 300), color='grey', marker='_')
plt.scatter(np.linspace(0,12.5, 40), np.full(40, 330), color='grey', marker='_')
neon_plot(t,led4, 'Led 4', 'deeppink')
neon_plot(t,led3, 'Led 3', 'darkviolet')
neon_plot(t,led2, 'Led 2', 'mediumspringgreen')
neon_plot(t,led1, 'Led 1', 'deepskyblue')
plt.plot(t, digit, color='white', label='Segnale digitale', zorder=10)
plt.legend()
plt.xlim(0,12.5)
plt.xlabel('Tempo [s]', fontsize=12)
plt.ylabel('Differenza di potenziale [mV]')
plt.grid()
plt.show()
#Grafico simulato: neon2
plt.figure(figsize=(15,5))
plt.style.use('dark_background')
plt.plot(t, ddp, label='Segnale analogico', color='white', lw=4.0)
plt.scatter(np.linspace(0, 12.5, 40), np.full(40, 260), color='grey', marker='_')
plt.scatter(np.linspace(0, 12.5, 40), np.full(40, 280), color='grey', marker='_')
plt.scatter(np.linspace(0,12.5, 40), np.full(40, 300), color='grey', marker='_')
plt.scatter(np.linspace(0,12.5, 40), np.full(40, 330), color='grey', marker='_')
neon_plot(t,led4, 'Led 4', 'limegreen')
neon_plot(t,led3, 'Led 3', 'lime')
neon_plot(t,led2, 'Led 2', 'greenyellow')
neon_plot(t,led1, 'Led 1', 'yellow')
plt.plot(t, digit, label='Segnale digitale', color='red', lw=2, zorder=10)
plt.legend()
plt.xlim(0,12.5)
plt.xlabel('Tempo [s]', fontsize=12)
plt.ylabel('Differenza di potenziale [mV]')
plt.ylim(-20, 380)
plt.grid()
plt.show()