USE UPS NEXT DAY AIR FOR ANY USA ORDER BEFORE 11AM ET *TODAY* 12/19/2014 TO GET YOUR PACKAGE IN TIME FOR XMAS - PLEASE SEE OUR SHIPPING DEADLINE NOTICE FOR MORE DETAILS!

Syntax error in Adafruit_CharLCD.py??
Moderators: adafruit_support_bill, adafruit

Forum rules
Talk about Adafruit Raspberry Pi® accessories! Please do not ask for Linux support, this is for Adafruit products only! For Raspberry Pi help please visit: http://www.raspberrypi.org/phpBB3/

Syntax error in Adafruit_CharLCD.py??

by joep on Mon Feb 11, 2013 3:58 pm

Hi, folks! Being new to the Pi, I thought it'd be a good idea to get my hands dirty with a little project here, so, I got the 16x2 LCD kit, and a cobbler, and just jumped right in!... All went well until I tried to run the Adafruit_CharLCD.py sample program.... My first inclination was to run it from a command-line, since I was already there doing all the other "sudo" stuff... and I get this nasty-gram from the Pi:
File"./Adafruit_CharLCD.py", line 60
If not GPIO:
IndentationError: expected an indented block


So have I gotten hold of a bad version of this program somehow?

Thanks for any light you guys/gals can shed on this one!!

JoeP
joep
 
Posts: 14
Joined: Wed Jan 16, 2013 5:25 pm

Re: Syntax error in Adafruit_CharLCD.py??

by tldr on Mon Feb 11, 2013 5:28 pm

congratulations. you have discovered the single most annoying feature of python. by staring at your keyboard wrong and accidentally adding or deleting a space at the beginning of a line you can render your code unusable.

check to make sure the code is indented correctly. note that this error is in the library, not in the file you are trying to run.

the code in the general vicinity of your error should look like this...

Code: Select all | TOGGLE FULL SIZE
    def __init__(self, pin_rs=25, pin_e=24, pins_db=[23, 17, 21, 22], GPIO = None):
        # Emulate the old behavior of using RPi.GPIO if we haven't been given
        # an explicit GPIO interface to use
        if not GPIO:
            import RPi.GPIO as GPIO
        self.GPIO = GPIO
"If I had known it was harmless, I would have killed it myself." - Phillip K. Dick, A Scanner Darkly
User avatar
tldr
 
Posts: 466
Joined: Thu Aug 30, 2012 1:34 am

Re: Syntax error in Adafruit_CharLCD.py??

by tldr on Mon Feb 11, 2013 5:42 pm

oops. i guess it's possible that the library is the code you were trying to run.

anyway... check the indentation.
"If I had known it was harmless, I would have killed it myself." - Phillip K. Dick, A Scanner Darkly
User avatar
tldr
 
Posts: 466
Joined: Thu Aug 30, 2012 1:34 am

Re: Syntax error in Adafruit_CharLCD.py??

by joep on Mon Feb 11, 2013 6:03 pm

Thanks for the reply! What I'm trying to run is the Adafruit_CharLCD.py sample mentioned in the tutorial for the Adafruit 16x2 LCD, to be gotten from GITHUB... followed the instructions in the tutorial, and the error message was the result... I'm certainly not above beating my way through the code shoving things around to deal with this, but a) shouldn't the samples be reasonably @ready to run@?, and b), how to know what the author intended the indentation to be?

Here's the code in the area you mentioned.....
Code: Select all | TOGGLE FULL SIZE

def __init__(self, pin_rs=25, pin_e=24, pins_db=[23, 17, 21, 22], GPIO = None):
    # Emulate the old behavior of using RPi.GPIO if we haven't been given
    # an explicit GPIO interface to use
    if not GPIO:
        import RPi.GPIO as GPIO
    self.GPIO = GPIO
    self.pin_rs = pin_rs
    self.pin_e = pin_e
    self.pins_db = pins_db
    self.GPIO.setmode(GPIO.BCM)
    self.GPIO.setup(self.pin_e, GPIO.OUT)
    self.GPIO.setup(self.pin_rs, GPIO.OUT)


Now it's complaining about another section further down... I'm not sure what the author intended.....

Thanks again for any light you can shed on this (so far) rather murky subject!
Joep
joep
 
Posts: 14
Joined: Wed Jan 16, 2013 5:25 pm

Re: Syntax error in Adafruit_CharLCD.py??

by TxBobS on Wed Feb 20, 2013 5:18 pm

I went through the tutorial last night and the code I downloaded worked fine.

http://learn.adafruit.com/adafruit-16x2 ... spberry-pi

Did you get the code from the same place?
TxBobS
 
Posts: 8
Joined: Wed Jan 30, 2013 3:11 pm

Re: Syntax error in Adafruit_CharLCD.py??

by joep on Wed Mar 13, 2013 3:23 pm

Hi again! Sorry to have been so tardy in responding - Went thru the download process a few days later, and all seems to work as advertised.... Guess I must have botched something somewhere along the way... On to other challenges!

JoeP
joep
 
Posts: 14
Joined: Wed Jan 16, 2013 5:25 pm