0

I am currently working on a personal project and im having some problems troubleshooting this particular error.

python3 ecg.py


Traceback (most recent call last):
  File "ecg.py", line 30, in <module>
    spi.open(0,0)
FileNotFoundError: [Errno 2] No such file or directory

I was thinking it might be an issue with spidev? but i have installed spidev into the pi and still have the error so im lost right now

I have included my code below, my project is basically trying to interface with a ADC chip with my code and there are 5 channels for the ADC

import RPi.GPIO as GPIO 
import spidev 
import time 
import os 


GPIO.setmode(GPIO.BCM) 
GPIO.setwarnings(False)

# Setup Pins
gpio_pins = [22, 27, 17, 23, 24, 25] 

for gpio_pin in gpio_pins:
    GPIO.setup(gpio_pin, GPIO.OUT) # Setup pin as output
    GPIO.output(gpio_pin, GPIO.LOW) # Set output to LOW to turn off the pins

# Open SPI bus
spi = spidev.SpiDev() 
spi.open(0,0)
spi.max_speed_hz = 1350000 
time.sleep(0.0005) #for stability





# Function to read SPI data from ADAS1000 chip Channel must a integer between 0-7
def ReadChannel(channel):
    adc = spi.xfer2([1,(8+channel)<<4,0])
    print("raw data",adc)
    data = ((adc[1]&3) << 8) + adc[2]
    return data

# Define sensor channels
LA_channel = 0 
LL_channel = 1
RA_channel = 2
V1_channel = 3
V2_channel = 4


# Define delay between readings
delay = 0.5


time.sleep(0.0005) #for stability

##main loop
try:
    while True:

        # Read the  sensor data
        LAdata = ReadChannel(LA_channel)
        LLdata = ReadChannel(LL_channel)
        RAdata = ReadChannel(RA_channel)
        V1data = ReadChannel(V1_channel)
        V2data = ReadChannel(V2_channel)


        # Print our results
        print ("--------------------")
        print ("LA : {}  LL : {}  RA : {}  V1 : {}  V2 : {}".format(LAdata,LLdata,RAdata,V1data,V2data))


        # Wait before repeating loop
        time.sleep(delay)

        #os.system('clear') 

except KeyboardInterrupt:
    GPIO.cleanup()  
0

Problem Fixed, i did:

sudo raspi-config

then

changed the spi to active

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.