2

I am trying to make a program for arduino also using Python 2.7 and pySerial that will put tweets on a lcd my only problem is the Python code it is giving me a error My code

#!/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()

The error

 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'

Any help is appreciated

  1. Windows 10
  2. Arduino Uno R3
abrad1212
  • 232
  • 2
  • 9

1 Answers1

0

Did you get part of your code from an example? Because '/dev/ttyACM0' is usually a COM port that a mac would use. Plug in your arduino, open up the arduino IDE, go into 'tools', go into 'boards', and select arduino/genuino uno. Then open up 'tools' again and go into 'port' you should see something like 'COM4' or 'COM2'. Then replace:

s = serial.Serial("/dev/ttyACM0" ,9600, timeout=10)

with

s = serial.Serial("Whatever you see there" ,9600, timeout=10)

EDIT: You must have your arduino plugged in, I tried the code without it plugging in, but as soon as I did, it worked.

EDIT: Looking at your arduino code, you're using pins 1 and 0 for your LCD, but these are the pins used by the arduino for serial communication (RX and TX), so try changing your LCD deceleration line from 1 and 0 to two other pins. That may help.

Hope this helped!

-Dave

Dave Fyre
  • 60
  • 10
  • It gives me this error `__Traceback (most recent call last): File "twitter_lcd.py", line 23, in s = serial.Serial("COM4" ,9600, timeout=10) File "build/bdist.cygwin-2.4.1-x86_64/egg/serial/serialutil.py", line 180, in __init__ File "build/bdist.cygwin-2.4.1-x86_64/egg/serial/serialposix.py", line 294, in open serial.serialutil.SerialException: [Errno 2] could not open port COM4: [Errno 2] No such file or directory: 'COM4'__` – abrad1212 Mar 09 '16 at 03:32
  • And you did verify that this is the port your arduino works on? – Dave Fyre Mar 09 '16 at 04:34
  • The only time it gave me this error is when the arduino wasn't plugged in, so try plugging it in and running the command from the shell. If it still doesn't work, it might be your arduino board. Try reuploading the code to it – Dave Fyre Mar 09 '16 at 15:08
  • Okay will try in 10 mins Iv been at school xD – abrad1212 Mar 09 '16 at 21:29
  • Not working here are some pics [link] (http://bit.ly/220DVnx) [link] (http://bit.ly/220E0rb) [link] (http://bit.ly/1UfPfWE) [link] (http://bit.ly/1QI0Dtm) [link] (http://bit.ly/1SAuyVz) – abrad1212 Mar 09 '16 at 22:25