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?
1.2" 7 Segment Display w/Backpack - How to Dim
Moderators: adafruit_support_bill, adafruit
Please be positive and constructive with your questions and comments.
- gadkarisid
- Posts: 6
- Joined: Tue Jan 05, 2016 12:09 pm
- adafruit_support_rick
- Posts: 35092
- Joined: Tue Mar 15, 2011 11:42 am
Re: 1.2" 7 Segment Display w/Backpack - How to Dim
That function should work. Can you post the entire error traceback?
- gadkarisid
- Posts: 6
- Joined: Tue Jan 05, 2016 12:09 pm
Re: 1.2" 7 Segment Display w/Backpack - How to Dim
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.
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.
- adafruit_support_rick
- Posts: 35092
- Joined: Tue Mar 15, 2011 11:42 am
Re: 1.2" 7 Segment Display w/Backpack - How to Dim
Actually, I just looked and there's no setBrightness in that library.
- gadkarisid
- Posts: 6
- Joined: Tue Jan 05, 2016 12:09 pm
Re: 1.2" 7 Segment Display w/Backpack - How to Dim
Thanks for the quick response!
Is there any way to control brightness from code as opposed to physical resistors?
Is there any way to control brightness from code as opposed to physical resistors?
- adafruit_support_rick
- Posts: 35092
- Joined: Tue Mar 15, 2011 11:42 am
Re: 1.2" 7 Segment Display w/Backpack - How to Dim
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.
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, [])
- gadkarisid
- Posts: 6
- Joined: Tue Jan 05, 2016 12:09 pm
Re: 1.2" 7 Segment Display w/Backpack - How to Dim
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?
- drewfustini
- Posts: 944
- Joined: Sat Dec 26, 2015 1:19 pm
Re: 1.2" 7 Segment Display w/Backpack - How to Dim
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
By Kevin Townsend:
https://github.com/adafruit/Adafruit-Ra ... Segment.py
By Tony DiCola:
https://github.com/adafruit/Adafruit_Py ... D_Backpack
- drewfustini
- Posts: 944
- Joined: Sat Dec 26, 2015 1:19 pm
Re: 1.2" 7 Segment Display w/Backpack - How to Dim
setBrightness() is actually a method of the class LEDBackpack, not the class SevenSegment.gadkarisid wrote:Here's what the traceback shows:Here's the script I'm testing with: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'
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.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
Please let me know if you need anything else.
As a test, you could try changing the default brightness value in Adafruit_LEDBackpack.py:
Code: Select all
# Set maximum brightness
self.setBrightness(15)
- gadkarisid
- Posts: 6
- Joined: Tue Jan 05, 2016 12:09 pm
Re: 1.2" 7 Segment Display w/Backpack - How to Dim
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!
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!
- drewfustini
- Posts: 944
- Joined: Sat Dec 26, 2015 1:19 pm
Re: 1.2" 7 Segment Display w/Backpack - How to Dim
glad to hear it worked for you!
- gadkarisid
- Posts: 6
- Joined: Tue Jan 05, 2016 12:09 pm
Re: 1.2" 7 Segment Display w/Backpack - How to Dim
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!
#!/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!
- drewfustini
- Posts: 944
- Joined: Sat Dec 26, 2015 1:19 pm
Re: 1.2" 7 Segment Display w/Backpack - How to Dim
Very interesting. Thanks for the followup!
Please be positive and constructive with your questions and comments.