Im using pyudev for detecting when an usb device is placed in raspberry pi. But i need get file directory of it for saving a excel file in an usb after i detect it
Code is:
import pyudev
import RPi.GPIO as GPIO
import time
from time import sleep
from os import path
#FUNCION PARA DETECTAR USB Y GUARDAR DATOS
def guardarUSB():
context = pyudev.Context()
monitor = pyudev.Monitor.from_netlink(context)
monitor.filter_by(subsystem='usb')
Led = 32
GPIO.setwarnings(False)
GPIO.setmode(GPIO.BOARD)
GPIO.setup(Led,GPIO.OUT)
GPIO.output(Led, GPIO.LOW) #poner la seƱal de salida en alto (High) o bajo (low)
time.sleep(3)
GPIO.cleanup() #limpiar el pin
for device in iter(monitor.poll, None):
if device.action == 'add':
print('{} connected'. format(device.sys_path))
guardarUSB()
Using the Raspbian OS, which is similar to Linux, external hard drives with be placed in
/media/pi
. If you useos.listdir
, you will be able to find if you have hard drives or not. Maybe use this code to find how many hard drives are in: