1.2" 7 Segment Display w/Backpack - How to Dim

EL Wire/Tape/Panels, LEDs, pixels and strips, LCDs and TFTs, etc products from Adafruit

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
User avatar
gadkarisid
 
Posts: 6
Joined: Tue Jan 05, 2016 12:09 pm

1.2" 7 Segment Display w/Backpack - How to Dim

Post by gadkarisid »

I have a 1.2" 7 segment display with I2C backpack up and running on a Raspberry Pi using the Adafruit Python libraries, however I can't figure out how to dim the display via Python. After looking at https://learn.adafruit.com/matrix-7-seg ... ss-summary there seems to be a "setBrightness" function in the "Adafruit_LEDBackpack" library but every time I try to use it I get an error.

Can you please explain how to dim the entire display?

User avatar
adafruit_support_rick
 
Posts: 35092
Joined: Tue Mar 15, 2011 11:42 am

Re: 1.2" 7 Segment Display w/Backpack - How to Dim

Post by adafruit_support_rick »

That function should work. Can you post the entire error traceback?

User avatar
gadkarisid
 
Posts: 6
Joined: Tue Jan 05, 2016 12:09 pm

Re: 1.2" 7 Segment Display w/Backpack - How to Dim

Post by gadkarisid »

Here's what the traceback shows:
Traceback (most recent call last):
File "display_test.py", line 8, in <module>
display.setBrightness(5)
AttributeError: SevenSegment instance has no attribute 'setBrightness'

Here's the script I'm testing with:

#!/usr/bin/python

import time
from Adafruit_7Segment import *
from Adafruit_LEDBackpack import *

display = SevenSegment(address = 0x70)
display.setBrightness(5)
i = 0

while(i <= 9):
display.writeDigit(0, i)
i = i + 1
time.sleep(1)
display.disp.clear()

exit

In /usr/lib/python2.7/ I have the Adafruit_7Segment.pyc, Adafruit_I2C.pyc, and Adafruit_LEDBackpack.pyc so I don't think there's an issue importing the libraries. Since these are all .pyc files, I can't actually verify that Adafruit_LEDBackpack.pyc actually has a method to control the brightness.

Please let me know if you need anything else.

User avatar
adafruit_support_rick
 
Posts: 35092
Joined: Tue Mar 15, 2011 11:42 am

Re: 1.2" 7 Segment Display w/Backpack - How to Dim

Post by adafruit_support_rick »

Actually, I just looked and there's no setBrightness in that library.

User avatar
gadkarisid
 
Posts: 6
Joined: Tue Jan 05, 2016 12:09 pm

Re: 1.2" 7 Segment Display w/Backpack - How to Dim

Post by gadkarisid »

Thanks for the quick response!

Is there any way to control brightness from code as opposed to physical resistors?

User avatar
adafruit_support_rick
 
Posts: 35092
Joined: Tue Mar 15, 2011 11:42 am

Re: 1.2" 7 Segment Display w/Backpack - How to Dim

Post by adafruit_support_rick »

D'Oh! My python is really bad. setBrightness is in HT16K33.py. So it *is* there for seven segment displays after all.
And it appears to do the right thing. So I don't know why you're getting an error.

You can try pasting the function directly into SevenSegment.py. I don't know - maybe that will work.

Code: Select all

	def set_brightness(self, brightness):
		"""Set brightness of entire display to specified value (16 levels, from
		0 to 15).
		"""
		if brightness < 0 or brightness > 15:
			raise ValueError('Brightness must be a value of 0 to 15.')
		self._device.writeList(HT16K33_CMD_BRIGHTNESS | brightness, [])

User avatar
gadkarisid
 
Posts: 6
Joined: Tue Jan 05, 2016 12:09 pm

Re: 1.2" 7 Segment Display w/Backpack - How to Dim

Post by gadkarisid »

I tried to import HT16K33.py and call the function from there but it didn't work, most likely because I'm doing something wrong. Any chance you can send an example of how to call the function?

User avatar
drewfustini
 
Posts: 944
Joined: Sat Dec 26, 2015 1:19 pm

Re: 1.2" 7 Segment Display w/Backpack - How to Dim

Post by drewfustini »

fyi: it seems there are two different Python libraries for the 7 segment backpack

By Kevin Townsend:
https://github.com/adafruit/Adafruit-Ra ... Segment.py

By Tony DiCola:
https://github.com/adafruit/Adafruit_Py ... D_Backpack

User avatar
drewfustini
 
Posts: 944
Joined: Sat Dec 26, 2015 1:19 pm

Re: 1.2" 7 Segment Display w/Backpack - How to Dim

Post by drewfustini »

gadkarisid wrote:Here's what the traceback shows:

Code: Select all

Traceback (most recent call last):
  File "display_test.py", line 8, in <module>
    display.setBrightness(5)
AttributeError: SevenSegment instance has no attribute 'setBrightness'
Here's the script I'm testing with:

Code: Select all

#!/usr/bin/python

import time
from Adafruit_7Segment import *
from Adafruit_LEDBackpack import *

display = SevenSegment(address = 0x70)
display.setBrightness(5)
i = 0

while(i <= 9):
        display.writeDigit(0, i)
        i = i + 1
        time.sleep(1)
        display.disp.clear()

exit
In /usr/lib/python2.7/ I have the Adafruit_7Segment.pyc, Adafruit_I2C.pyc, and Adafruit_LEDBackpack.pyc so I don't think there's an issue importing the libraries. Since these are all .pyc files, I can't actually verify that Adafruit_LEDBackpack.pyc actually has a method to control the brightness.

Please let me know if you need anything else.
setBrightness() is actually a method of the class LEDBackpack, not the class SevenSegment.

As a test, you could try changing the default brightness value in Adafruit_LEDBackpack.py:

Code: Select all

    # Set maximum brightness
    self.setBrightness(15)

User avatar
gadkarisid
 
Posts: 6
Joined: Tue Jan 05, 2016 12:09 pm

Re: 1.2" 7 Segment Display w/Backpack - How to Dim

Post by gadkarisid »

Got it fixed!

I'm not sure exactly what originally happened, but I blew away the Adafruit libraries that I had and pulled down fresh copies from Github (https://github.com/adafruit/Adafruit-Ra ... EDBackpack). Once that was done, I modified "self.brightness(x)" in Adafruit_LEDBackpack.py and the entire display was dimmed.

Thanks for all the help!

User avatar
drewfustini
 
Posts: 944
Joined: Sat Dec 26, 2015 1:19 pm

Re: 1.2" 7 Segment Display w/Backpack - How to Dim

Post by drewfustini »

glad to hear it worked for you!

User avatar
gadkarisid
 
Posts: 6
Joined: Tue Jan 05, 2016 12:09 pm

Re: 1.2" 7 Segment Display w/Backpack - How to Dim

Post by gadkarisid »

Just a follow up to this. While I did get this working, it was by modifying 'self.setBrightness(x)' line in 'Adafruit_LEDBackpack.py' file which I didn't think was ideal since it was set the brightness globally, ie for all scripts you run using this library. After lots of trial and error and syntax issues, I figured out how to control it from each individual script:

#!/usr/bin/python
from Adafruit_7Segment import *

# Set display brightness (0 to 15)
LEDBackpack().setBrightness(5)


This works since the Adafruit_7Segment library calls the Adafruit_LEDBackpack library too. Again, thanks for the help!

User avatar
drewfustini
 
Posts: 944
Joined: Sat Dec 26, 2015 1:19 pm

Re: 1.2" 7 Segment Display w/Backpack - How to Dim

Post by drewfustini »

Very interesting. Thanks for the followup!

Locked
Please be positive and constructive with your questions and comments.

Return to “Glowy things (LCD, LED, TFT, EL) purchased at Adafruit”