morris1974
Posts: 25
Joined: Wed Jun 10, 2015 8:13 am

python & raspberry errore esecuzione programma

Wed Aug 31, 2016 12:00 pm

Ciao a tutti sto cercando di unire due programmi uno per mandare una mail e un altro per un led che si accenda e quando faccio partire il programma invia mail.
Ho controllato la sintassi e non mi da errori ma appena faccio partire il programma ottengo questo:

Code: Select all

Traceback (most recent call last):
  File "mail1-b7blink.py", line 10, in <module>
    GPIO.output(18)
TypeError: function takes exactly 2 arguments (1 given)
cosa significa in termini semplici? ho guardato su google ma non ho ben capito cosa intendesse spiegarmi :oops:
Cmq questo è il programma:

Code: Select all

#!/usr/bin/env python
 
import RPi.GPIO as GPIO
import time, smtplib
 
GPIO.setmode(GPIO.BOARD)
GPIO.setup(23, GPIO.IN)
GPIO.setup(18, GPIO.OUT)
GPIO.input(23)
GPIO.output(18)
GPIO.output(18, True)
GPIO.output(18, False)
GPIO.setwarnings(False)
 
smtpserver = 'smtp.gmail.com:587'
fromaddr = 'xxxx'
toaddr = 'xxxx'
msg = 'mail1-7' 
#Aggiungo i dati per l'invio
username = 'xxxxxxxxx' #inserire proprio indirizzo
password = 'xxxxxxxxx' #inserire propria password
 
inviata = False
stato = True
while True:
    GPIO.output(18, stato)
    stato = not stato
    time.sleep(0.5)
    if not GPIO.input(23):
        if not inviata:
            server = smtplib.SMTP(smtpserver)
            server.starttls()
            server.login(username, password)
            server.sendmail(fromaddr, toaddr, msg)
            server.quit()
        inviata = True
    else:
        inviata = False
qualcuno può spiegarmi? grazie a tutti in anticipo

User avatar
lmarmisa
Posts: 1265
Joined: Thu Feb 14, 2013 2:22 am
Location: Jávea, Spain

Re: python & raspberry errore esecuzione programma

Thu Sep 01, 2016 8:45 am

La funzione GPIO.output() richiede due argomenti: il porto e il livello del segnale.
Questa istruzione (linea 10) non è corretta:

Code: Select all

GPIO.output(18)
Questi altri due istruzioni (linee 11 e 12) se sono corrette

Code: Select all

GPIO.output(18, True)
GPIO.output(18, False)

Return to “Italiano”