I want to execute the blink example in Arduino UNO using LED pin 13 (inbuilt) And I want to use Python to do so.... "I did upload the Standard Firmata code in Arduino using the Arduino IDE" Then I hopped on to VS code I tried to create a virtual environment named "pyArdu" and then installed Serial and firmata using pip. Then in the code I tried accessing the port to which i connected Arduino UNO. Still the program isn't running.

Here is the code

from pyfirmata import Arduino, util
import time

board = Arduino('COM4')

iterator = util.Iterator(board)
iterator.start()
while True:
    board.digital[13].write(1)
    time.sleep(1)
    board.digital[13].write(0)
    time.sleep(1)

I tried watching youtube solutions. There is not much of Figmata stuff on it.

I switched from python 3.12.2 to python 3.9.9

Here is the error :

File "c:\Users\Sparsh\OneDrive\Documents\Skills\PyFirmata\Firstone.py", line 4, in board = Arduino('COM4') File "C:\Users\Sparsh\OneDrive\Documents\Skills\PyFirmata\pyArdu\lib\site-packages\pyfirmata_init_.py", line 19, in init super(Arduino, self).init(*args, **kwargs) File "C:\Users\Sparsh\OneDrive\Documents\Skills\PyFirmata\pyArdu\lib\site-packages\pyfirmata\pyfirmata.py", line 89, in init self.sp = serial.Serial(port, baudrate, timeout=timeout) AttributeError: module 'serial' has no attribute 'Serial'

1

There are 1 best solutions below

1
SpR On

PyFirmata dosen't support python 3.9.9 in VS code. So when I tried with Python 3.6.3, it ran pretty much perfectly !