Reputation: 1
Every time I run this script on my Raspberry Pi:
import curses
import RPi.GPIO as GPIO
GPIO.setwarnings(False)
GPIO.setmode(GPIO.BOARD)
motor1a = 7
motor1b = 11
motor1e = 22
motor2a = 13
motor2b = 16
motor2e = 15
GPIO.setup(motor1a,GPIO.OUT)
GPIO.setup(motor1b,GPIO.OUT)
GPIO.setup(motor1e,GPIO.OUT)
GPIO.setup(motor2a,GPIO.OUT)
GPIO.setup(motor2b,GPIO.OUT)
GPIO.setup(motor2e,GPIO.OUT)
screen = curses.initscr()
curses.noecho()
curses.cbreak()
curses.halfdelay(3)
screen.keypad(True)
try:
while True:
char = screen.getch()
if char == ord('q'):
break
elif char == curses.KEY_UP:
GPIO.output(motor1a,GPIO.HIGH)
GPIO.output(motor1b,GPIO.LOW)
GPIO.output(motor1e,GPIO.HIGH)
GPIO.output(motor2a,GPIO.HIGH)
GPIO.output(motor2b,GPIO.LOW)
GPIO.output(motor2e,GPIO.HIGH)
# except SOMEEXCEPTION is missing here, I am not sure why there is an exception in the first place
I get an error:
_curses.error: setupterm: could not find terminal
How can I fix this?
I saw a post where it said to do the following:
You must set environment variables
TERM
andTERMINFO
, like this:
export TERM=linux ; export TERMINFO=/etc/terminfo
But I'm not sure where to do that step.
Upvotes: 0
Views: 4718
Reputation: 30074
In order to use curses
, you need to tell which terminal you are using so that the library can send correct commands. This is done by running the commands you provided in a shell, at the same place where you run your program
$ export TERM=linux
$ export TERMINFO=/etc/terminfo
$ python3 myprogram.py
($
is the prompt of the shell, you may have something else)
As I mentioned in my comment, your code will not run anyway, there is an except
missing after the try
(I am not sure what you need the try
for, and you will need to understand this anyway in order to catch the right exception)
Upvotes: 2