I have an Arduino hooked up with 2 DS18B20 temp sensors. I'm very (VERY) new to python. I am looking for a way to read the serial input and parse it into a sqlite database, but that is getting ahead of myself. Why do I get an error while trying to define my serial port to a variable?
First things first sys.version
2.7.1 (r271:86832, Jul 31 2011, 19:30:53)
[GCC 4.2.1 (Based on Apple Inc. build 5658) (LLVM build 2335.15.00)]
My current, just read input from the serial connection program.
from serial import serial
import time
# open serial port
ser = serial.Serial('/dev/tty.usbmodem621',9600,timeout=2)
ser.open()
while True:
print('dev 0' + ser.read())
pass
ser.close()
I can not currently get it to compile. Most of the results I've found for this error tell to add from serial import serial, but in this case it hasn't worked.
The error.
$ python ser.py
Traceback (most recent call last):
File "ser.py", line 1, in <module>
from serial import serial
File "/Users/frankwiebenga/serial.py", line 8, in <module>
AttributeError: 'module' object has no attribute 'Serial'
Also if I just use import serial I get the same error
$ python ser.py
Traceback (most recent call last):
File "ser.py", line 1, in <module>
import serial
File "/Users/frankwiebenga/serial.py", line 8, in <module>
AttributeError: 'module' object has no attribute 'Serial'
Also, per comment. Created new file named something.py and still get the same error regardless of using import serial or from serial import serial.
$ python something.py
Traceback (most recent call last):
File "something.py", line 1, in <module>
from serial import serial
ImportError: No module named serial
When running my bash script I get an output that is valid, so I know it isn't the Arduino code.
Output:
Requesting temperatures...DONE
Device 0: 25.62
Device 1: 25.75
Requesting temperatures...DONE
Device 0: 25.62
Device 1: 25.81
Bash:
while true # loop forever
do
inputline="" # clear input
# Loop until we get a valid reading from AVR
until inputline=$(echo $inputline | grep -e "^temp: ")
do
inputline=$(head -n 1 < /dev/tty.usbmodem621)
done
echo "$inputline"
done
import serial. Your updated error hasfrom serial import serial, which uses the wrong case forSerial. As dkamins mentions, use eitherimport serialorfrom serial import Serial