我正试图为arduino制作一个程序,它还使用Python2.7和pySerial,它将推特放到液晶显示器上,我唯一的问题是Python代码,它给了我一个错误,我的代码
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import tweepy
import serial
import time
from datetime import datetime
import pytz
import signal
import sys
def exit_handler(signal, frame):
global s
print 'You pressed Ctrl+C!'
print 'Closing properly'
s.write(chr(10))
s.close()
sys.exit(0)
s = serial.Serial("/dev/ttyACM0" ,9600, timeout=10)
CONSUMER_KEY = ''
CONSUMER_SECRET = ''
ACCESS_KEY = ''
ACCESS_SECRET = ''
auth = tweepy.OAuthHandler(CONSUMER_KEY, CONSUMER_SECRET)
auth.set_access_token(ACCESS_KEY, ACCESS_SECRET)
api = tweepy.API(auth)
tweets = api.user_timeline(count = 1)
print "Wait a moment please"
signal.signal(signal.SIGINT, exit_handler)
time.sleep(4)
tweet = tweets[0].text
while len(tweet) < 26:
tweet = tweet + " "
#Adjust to local timezone
eastern = pytz.timezone('US/Eastern')
utc = pytz.timezone('UTC')
tweet_time = utc.normalize(utc.localize(tweets[0].created_at))
tweet_time_local = str(tweet_time.astimezone(eastern))
s.write(chr(13))
s.write(tweet[0:16])
s.write(chr(10))
# We need a small delay
time.sleep(0.1)
s.write(tweet[16:26])
time.sleep(0.1)
s.write(" ")
time.sleep(0.1)
s.write(tweet_time_local[11:16])
s.close()误差
Traceback (most recent call last):
File "twitter_lcd.py", line 23, in <module>
s = serial.Serial("/dev/ttyACM0" ,9600, timeout=10)
File "build/bdist.cygwin-2.4.1-x86_64/egg/serial/serialutil.py", line 180,
File "build/bdist.cygwin-2.4.1-x86_64/egg/serial/serialposix.py", line 294, e in open
serial.serialutil.SerialException: [Errno 2] could not open port /dev/ttyACM0: [Errno 2] No such file or directory: '/dev/ttyACM0'任何帮助都是非常感谢的。
发布于 2016-03-09 02:43:14
你从一个例子中得到了部分代码吗?因为'/dev/ttyACM0‘通常是mac会使用的COM端口。插入您的arduino,打开arduino IDE,进入“tools”,进入“board”,然后选择arduino/genuino uno。然后再次打开'tools‘并进入'port’,您应该会看到类似于'COM4‘或’COM2 2‘的东西。然后替换:
s = serial.Serial("/dev/ttyACM0" ,9600, timeout=10)使用
s = serial.Serial("Whatever you see there" ,9600, timeout=10)编辑:你必须把你的arduino插入,我尝试了它没有插入代码,但一旦我做到了,它的工作。
编辑:查看您的arduino代码,您正在使用引脚1和0为您的LCD,但这些是由arduino用于串行通信(RX和TX)的引脚,所以请尝试将您的LCD减速线从1和0更改为另外两个引脚。也许会有帮助。
希望这能帮上忙!
-Dave
https://stackoverflow.com/questions/35881254
复制相似问题