Advertisement
Guest User

Untitled

a guest
Dec 12th, 2019
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.02 KB | None | 0 0
  1. import serial
  2. import matplotlib.pyplot as plt
  3.  
  4. L1=[]
  5. L2=[]
  6. values = []
  7.  
  8. serialArduino=serial.Serial('com5',9600)
  9.  
  10. def plotValues():
  11. plt.title('Grafic senzor umiditate')
  12. plt.grid(True)
  13. plt.ylabel('Valoare')
  14. plt.plot(values, 'rx-', label='Senzor umiditate=' +v+'L1='+L1+'L2'+L2
  15. ,color='blue')
  16. plt.legend(loc='upper left')
  17. plt.xlabel('Timp')
  18.  
  19. for i in range(0,40):
  20. values.append(0)
  21.  
  22. while True:
  23. while(serialArduino.inWaiting()==0):
  24. pass
  25. valueRead,L1,L2=serialArduino.readline().decode('utf8').split(';')
  26.  
  27. try:
  28. valueInInt=int(valueRead)
  29. print(valueInInt)
  30. if valueInInt <=1024:
  31. if valueInInt >=0:
  32. value.append(valueInInt)
  33. values.pop(0)
  34. drawnow(plotValues)
  35. else:
  36. print("Numar negativ")
  37. else:
  38. print("Valoare venita de la Arduino e prea mare")
  39. except ValueError:
  40. print("Valoarea nu poate fi parsata")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement