pi_clown
Posts: 3
Joined: Sat Oct 18, 2014 10:03 pm

Nokia 5110 display error

Sat Oct 18, 2014 10:18 pm

I have a Nokia 5110 display that works fine with the sample scripts. When I try to use it in a script that includes turning on and off a gpio pin which i am using to turn on and off the leds on the screen i get an error. If I comment out the gpio code the script runs. Here is the script.

Code: Select all

#!/usr/bin/python
import os, shutil, glob, time, sys, math, time, Image, ImageFont, ImageDraw
import RPi.GPIO as GPIO
import Adafruit_Nokia_LCD as LCD
import Adafruit_GPIO.SPI as SPI

def main():
#--LDC setup--
# Raspberry Pi hardware SPI config:
    DC = 25
    RST = 24
    SPI_PORT = 0
    SPI_DEVICE = 0
    
    # Hardware SPI usage:
    disp = LCD.PCD8544(DC, RST, spi=SPI.SpiDev(SPI_PORT, SPI_DEVICE, max_speed_hz=4000000))
    
    # Initialize library.
    disp.begin(contrast=60)
    
    # Clear display.
    disp.clear()
    disp.display()
    
    # Create image buffer.
    # Make sure to create image with mode '1' for 1-bit color.
    image = Image.new('1', (LCD.LCDWIDTH, LCD.LCDHEIGHT))
    
    # Load default font.
    font = ImageFont.load_default()
    
    # Create drawing object.
    draw = ImageDraw.Draw(image)
    
    text = 'Testing my lcd'
    maxwidth, height = draw.textsize(text, font=font)
    
    # Set starting position.
    startpos = 83
    pos = startpos
    
    #setup gpio for lcd led
    GPIO.setmode(GPIO.BOARD)
    GPIO.setup(11, GPIO.OUT)
    

    #turn on lcd led
    GPIO.output(11, True)
    
    print 'Press Ctrl-C to quit.'
    draw.text((8,30),'hello',font=font)    
    
    disp.image(image)
    disp.display()
    time.sleep(1.0)
    #turn off lcd led and clean up
    GPIO.output(11, False)
    GPIO.cleanup()
    
if __name__ == '__main__':
    main()


Here is the run time error

Code: Select all

Traceback (most recent call last):
  File "./lcdtest1.py", line 62, in <module>
    disp.display()
  File "/usr/local/lib/python2.7/dist-packages/Adafruit_Nokia_LCD-0.1.0-py2.7.egg/Adafruit_Nokia_LCD/PCD8544.py", line 142, in display
    self.command(PCD8544_SETYADDR)
  File "/usr/local/lib/python2.7/dist-packages/Adafruit_Nokia_LCD-0.1.0-py2.7.egg/Adafruit_Nokia_LCD/PCD8544.py", line 105, in command
    self._gpio.set_low(self._dc)
  File "/usr/local/lib/python2.7/dist-packages/Adafruit_GPIO-0.5.5-py2.7.egg/Adafruit_GPIO/GPIO.py", line 57, in set_low
    self.output(pin, LOW)
  File "/usr/local/lib/python2.7/dist-packages/Adafruit_GPIO-0.5.5-py2.7.egg/Adafruit_GPIO/GPIO.py", line 106, in output
    self.rpi_gpio.output(pin, value)
ValueError: The channel sent is invalid on a Raspberry Pi
I have googled "ValueError: The channel sent is invalid on a Raspberry Pi" but haven't found anything.

If i run just the code to turn it off and on it works just fine.

Code: Select all

import RPi.GPIO as GPIO
import time

GPIO.setmode(GPIO.BOARD)

GPIO.setup(11, GPIO.OUT)

GPIO.output(11, True)
time.sleep(2)
GPIO.output(11, False)

GPIO.cleanup()
This is my first project so I might be missing a simple point/config.

User avatar
mahjongg
Forum Moderator
Forum Moderator
Posts: 13092
Joined: Sun Mar 11, 2012 12:19 am
Location: South Holland, The Netherlands

Re: Nokia 5110 display error

Sat Oct 18, 2014 10:21 pm

not a python expert but i think this error often occurs when you try to open a stream (to the GPIO) that is already open, perhaps you forgot to close it.

pi_clown
Posts: 3
Joined: Sat Oct 18, 2014 10:03 pm

Re: Nokia 5110 display error

Sat Oct 18, 2014 11:45 pm

I double checked I cant see anything related to closing a stream. One new bit of info is this. I went through the script and commented out all the code related to displaying the image on the lcd. I ran the script over and over each time uncommenting lines of code related the lcd. I was able to run the script ever time until I uncommented this line

Code: Select all

disp.display()
then I get the error.

User avatar
B.Goode
Posts: 10356
Joined: Mon Sep 01, 2014 4:03 pm
Location: UK

Re: Nokia 5110 display error

Sun Oct 19, 2014 7:09 am

A pure guess -

Does the Adafruit_Nokia_LCD module itself rely on RPi.GPIO? And if so does it use 'BCM' numbering of the GPIO pins?

Perhaps try omitting your added GPIO.setmode(GPIO.BOARD) and change all the instances of '11' to '17'? (That would be easier if you used a constant to hold the pin definition, as in the adafruit sample code.)

pi_clown
Posts: 3
Joined: Sat Oct 18, 2014 10:03 pm

Re: Nokia 5110 display error --SOLVED

Sun Oct 19, 2014 5:13 pm

That fixed it. I removed the GPIO.setmode and change the 11 to 17 and now its running. Thanks for the help. :D

Return to “Troubleshooting”