Advertisement
alphauser420

oscilloscope1

Oct 15th, 2023
7
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.96 KB | None | 0 0
  1. import time
  2. import matplotlib.pyplot as plt
  3.  
  4. #import numpy
  5. from drawnow import *
  6.  
  7. # Import the ADS1x15 module.
  8. import Adafruit_ADS1x15
  9.  
  10. # Create an ADS1115 ADC (16-bit) instance.
  11.  
  12. adc = Adafruit_ADS1x15.ADS1115()
  13.  
  14. GAIN = 1
  15. val = [ ]
  16. cnt = 0
  17. plt.ion()
  18.  
  19. # Start continuous ADC conversions on channel 0 using the previous gain value.
  20. adc.start_adc(0, gain=GAIN)
  21. print('Reading ADS1x15 channel 0')
  22.  
  23. #create the figure function
  24. def makeFig():
  25. plt.ylim(-5000,5000)
  26. plt.title('Osciloscope')
  27. plt.grid(True)
  28. plt.ylabel('ADC outputs')
  29. plt.plot(val, 'ro-', label='Channel 0')
  30. plt.legend(loc='lower right')
  31.  
  32. while (True):
  33. # Read the last ADC conversion value and print it out.
  34. value = adc.get_last_result()
  35. print('Channel 0: {0}'.format(value))
  36. # Sleep for half a second.
  37. time.sleep(0.5)
  38. val.append(int(value))
  39. drawnow(makeFig)
  40. plt.pause(.000001)
  41. cnt = cnt+1
  42. if(cnt>50):
  43. val.pop(0)
  44.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement