Python & Arduino - Arduino does not restore my serial write() function

Asked

Viewed 44 times

1

I am trying to communicate a python code and Arduin, but it is not returning the value to light the LED.

Already all configured, Pip, pyserial etc.

import serial
import time
import os
conexao = serial.Serial('COM3', 9600)

def menu():
    os.system('cls') or None

     print("""
       CONTROLE DO LED
        1- ON
        2- OFF    

          """)
   op = int(input("OPTION: "))

   if op == 1:
      try:
           conexao.write(1)
           print("LED LIGADO")
           time.sleep(1)
           print("RETORNANDO AO MENU")
           time.sleep(1)
           return menu()

      except:
           print("HOUVE ALGUM ERRO")
           print("RETORNANOD AO MENU")
           time.sleep(2)
           return menu()


   if op == 2:
       try:    
           conexao.write(2)
           print("LED DESLIGADO")
           time.sleep(1)
           print("RETORNANDO AO MENU")
           return menu()

       except: 
           print("HOUVE ALGUM ERRO")
           print("RETORNANOD AO MENU")
           time.sleep(2)
           return menu()

 menu()
  • What do you mean? It’s not clear, it makes a mistake? He even prints the message "HOUVE ALGUM ERRO" or just does nothing? Edith the question and add this information.

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.