Serial.serial is not working, thonny: module 'serial' has no attribute 'Serial'

Question:

I just started with Ardunino, Python and a serial Communication between RPI and Ardunio (using Thonny). I checked out some tutorials (e.g https://roboticsbackend.com/raspberry-pi-arduino-serial-communication/) to get my code run. But not even the standard code is running.

That is my code:

if __name__ == '__main__':
    ser = serial.Serial('/dev/ttyACM0', 9600, timeout=1)
    ser.reset_input_buffer()
    while True:
        if ser.in_waiting > 0:
            line = ser.readline().decode('utf-8').rstrip()
            print(line)```

This error keeps occuring: *AttributeError: module 'serial' has no attribute 'Serial'*

Your program tries to call method Serial of an object of type serial, but this type does not have such method. 

I have installed the library serial, the name of my file is : *Comm_testb.py*. 

I have tried also to do some other codes, which I found on stackoverflow ;). But either I failed to adapt them or there is something wrong. I also can not figure out other causes. So, I hope you can help me :).

Asked By: Arnic

||

Answers:

Are you sure you downloaded the right library?
In python there are both ‘serial’ and ‘pyserial’ and to communicate with Arduino you need the latter.

You better uninstall ‘serial’ library, because the line for importing pyserial is:

import serial

Pls, let me know if this works

Answered By: Filippo Ferrario