-1

find a solution about run python program getting error simple program

import serial 
ser =serial.serial ("dev/ttyAMA0",baudrate = 9600) 
ser.write("code") 
ser.close()

error attributeerror 'module' object has no attribute 'serial'
2

Capitalisation is important. You want serial.Serial() instead of serial.serial()

You've also not put the correct path to the serial device - dev/ttyAMA0 would be relative to the place the user runs the script from (so would only work if you run it from /).

Your code should be:

import serial
ser = serial.Serial("/dev/ttyAMA0", baudrate=9600) 
ser.write("code") 
ser.close()

See http://www.elinux.org/Serial_port_programming for more examples.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.