Quantcast
Channel: Recent Questions - Raspberry Pi Stack Exchange
Viewing all articles
Browse latest Browse all 50638

Hello, I can't seem to identify the problem of why my ECG value(AD8232) is negative and not giving me a proper reading. What do I need to change

$
0
0
import machineimport timefrom blynklib import Blynk# Initialize Blynk with your auth tokenBLYNK_AUTH = 'fgVF4IWzS-RFyKmb8DvNTKfm8Rwgt0JU'blynk = Blynk(BLYNK_AUTH)adcpin = 4sensor = machine.ADC(adcpin)LO_POS_PIN = 15LO_NEG_PIN = 14adc = machine.ADC(1)  # Initialize ADC on pin GP27_AD# Configure pinslo_pos_pin = machine.Pin(LO_POS_PIN, machine.Pin.IN)lo_neg_pin = machine.Pin(LO_NEG_PIN, machine.Pin.IN)# Function to read temperaturedef ReadTemperature():    adc_value = sensor.read_u16()    volt = (3.3/65535) * adc_value    temperature = 27 - (volt - 0.706)/0.001721    return round(temperature, 1)# Function to read ECG signaldef read_ecg():    ecg_signal = lo_pos_pin.value() - lo_neg_pin.value()    return ecg_signal# Function to convert ECG signal to voltagedef convert_to_voltage(ecg_signal):    # Assuming 3.3V reference voltage    voltage = (ecg_signal / 1023) * 3.3    return voltage# Main loopwhile True:    # Reading temperature    temperature = ReadTemperature()    print("Temperature:", temperature)    blynk.virtual_write(1, temperature)  # Send temperature data to virtual pin V1    # Reading ECG signal    ecg_value = read_ecg()    voltage = convert_to_voltage(ecg_value)    adc_value = adc.read_u16()    print("ECG Value:", ecg_value)    print("Voltage:", voltage)    print("ADC Value:", adc_value)    blynk.virtual_write(2, ecg_value)  # Send ECG value to virtual pin V2    blynk.virtual_write(3, voltage)  # Send voltage value to virtual pin V3    blynk.virtual_write(4, adc_value)  # Send ADC value to virtual pin V4    blynk.run()    time.sleep(1)

The pin connections for Ad8232

Lo+ - pin 15Lo- - pin 14Vout - pin 27Vin - 3V3Gnd - gnd

Viewing all articles
Browse latest Browse all 50638

Trending Articles