0

I wrote a small program in order to learn how to interface with my arduino. Actually, i got it here: https://github.com/WaveShapePlay/ArduinoPySerial_LearningSeries/blob/master/Part2_AddingUserInput/ArduinoSerialCom.py

This is the code:

import serial

ser = serial.Serial('COM3', baudrate = 9600, timeout = 1)

def getValues():

    ser.write(b'g')
    arduinoData = ser.readline().decode('ascii')
    return arduinoData


while(1):

    userInput = input('Get data point?')

    if userInput == 'y':
        print(getValues())

I changed the COM port to be the one my arduino is using. Unfortuantely i get this error:

ser = serial.Serial('COM14', baudrate = 9600, timeout
AttributeError: module 'serial' has no attribute 'Serial'

Many people have gad this program, so i did a lot of reading online in order to mitigate it.

I tried: *from serial import Serial (instead of import serial) * pip uninstall serial and then pip install pyserial. It succefully uninstalled serial but pyserial was already installed. Still it didn't work.

I am out of ideas... Any help pelase?

user1584421
  • 3,499
  • 11
  • 46
  • 86

1 Answers1

0

This is the code that worked for me

import serial

ser = serial.Serial('COM14', baudrate = 9600, timeout = 1)


def getValues():

    ser.write(b'rf')
    arduinoData = ser.readline().decode('ascii')
    return arduinoData


while(1):

    userInput = input('Get data point?')

    if userInput == 'y':
        print(getValues())
user1584421
  • 3,499
  • 11
  • 46
  • 86