Beispiel_ecg_read.py 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. import time
  2. from machine import Pin, UART, ADC
  3. # Pin Definitions (Assuming these are correct)
  4. output_pin = machine.Pin(26, machine.Pin.IN)
  5. lo_minus_pin = machine.Pin(27, machine.Pin.IN)
  6. lo_plus_pin = machine.Pin(8, machine.Pin.IN)
  7. # Configure ADC
  8. adc = ADC(output_pin)
  9. print("version_1")
  10. # Function to map ADC value to desired range
  11. def map_value(value, in_min, in_max, out_min, out_max):
  12. return (value - in_min) * (out_max - out_min) / (in_max - in_min) + out_min
  13. # Function to read and process ECG signal
  14. def read_ecg():
  15. adc_value = adc.read_u16()
  16. signal = map_value(adc_value, 0, 65535, 0, 100) # Example mapping
  17. return signal
  18. # Configure UART for 11520 baud rate
  19. #uart = UART(0, baudrate=11520, tx=Pin(0), rx=Pin(1)) # Adjust pins as needed
  20. k=0
  21. while True:
  22. printlist=[]
  23. for i in range(100):
  24. ecg_signal = read_ecg()
  25. printlist.append(ecg_signal)
  26. # Transmit the ECG signal
  27. #uart.write(str(ecg_signal) + "\n") # Send data with newline character
  28. for ecg_signal in printlist:
  29. #k=k+1
  30. #print(k)
  31. print(ecg_signal)
  32. # Optional delay between readings
  33. #time.sleep(0.00001) # Adjust delay as needed