Skip to content

Commit aaca3be

Browse files
Merge pull request #1 from Tom-Hirschberger/development
Development
2 parents 1d3db4f + 2302757 commit aaca3be

15 files changed

+53
-6
lines changed

README.md

+36-3
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,9 @@ The strip can be controlled either via hardware or software spi. The preferred m
66
**If you want to use an WS281X strip like i.e. WS2812B you can not use the build in sound output of the Raspberry Pi because both machnism use PWM. The installation guide will show you how to disable the kernel module of the on-board sound card!**
77

88
## Wiring ##
9-
The strip uses 5V spi lanes but the Raspberry uses 3.3V. We need to use an level converter to get rid of this problem. Connecting the strip directly to the Pi may cause harm to it.
10-
11-
The buttons will be connected with a 2kOhm pull down resistor each. The resistors will pull down the gpio to 0V if the buttons are not pressed. When the buttons are pressed the gpio pins will be connected to the 3.3V lane which results in an high flag.
9+
The strip uses 5V spi lanes but the Raspberry uses 3.3V. We need to use an level converter to get rid of this problem. Connecting the strip directly to the Pi may cause harm to it!
1210

11+
There are different possibilities to wire the buttons. I will show three examples.
1312

1413
### Wiring WS2801 ###
1514
This example uses the hardware spi pins to connect the led strip.
@@ -27,6 +26,31 @@ This example uses the GPIO21. 10, 12 and 18 are supported, also.
2726

2827
![Wiring WS281X](https://github.com/Tom-Hirschberger/PythonLedControl/raw/master/ledcontrol-WS281X.png "Wiring WS281X")
2928

29+
### Wiring the Buttons with pull-down resistors ###
30+
GPIO pins do not have an inital default state. To get one we connect an resistor to the ground and to the pin. The GPIO then is low and will be set to high if the switch is pressed and the connection to the VCC pin is closed.
31+
32+
![Two buttons pull-down](https://github.com/Tom-Hirschberger/PythonLedControl/raw/master/ledcontrol-buttons-pulldown.png "Wiring the buttons with pull-down resistors")
33+
34+
You need to set "LED_BTN_TRIGGER_ON_HIGH=1" in the environment file to get this setup work (default)!
35+
36+
### Wiring the Buttons with pull-up resistors ###
37+
GPIO pins do not have an inital default state. To get one we connect an resistor to the VCC and to the pin. The GPIO then is high and will be set to low if the switch is pressed and the connection to the ground pin is closed.
38+
39+
This setup is more robust against influnces of other electronical devices like frigerators or microwaves.
40+
41+
![Two buttons pull-up](https://github.com/Tom-Hirschberger/PythonLedControl/raw/master/ledcontrol-buttons-pullup.png "Wiring the buttons with pull-up resistors")
42+
43+
You need to set "LED_BTN_TRIGGER_ON_HIGH=0" in the environment file to get this setup work!
44+
45+
### Wiring the Buttons with pull-up resistors and capacitors###
46+
GPIO pins do not have an inital default state. To get one we connect an resistor to the VCC and to the pin. The GPIO then is high and will be set to low if the switch is pressed and the connection to the ground pin is closed.
47+
48+
This setup is more robust against influnces of other electronical devices like frigerators or microwaves than the one which only uses pull-up resistors.
49+
50+
![Two buttons pull-up with capacitors](https://github.com/Tom-Hirschberger/PythonLedControl/raw/master/ledcontrol-buttons-pullup-withCapacitors.png "Wiring the buttons with pull-up resistors")
51+
52+
You need to set "LED_BTN_TRIGGER_ON_HIGH=0" in the environment file to get this setup work!
53+
3054
## Installation ##
3155
### General###
3256
```
@@ -118,6 +142,8 @@ Open the file /home/pi/ledcontrol/ledcontrol.env in your favorit editor. In exam
118142
LED_BTN_TWO_GPIO=27
119143
#How many milliseconds should be waited before another press of the same button is accepted?
120144
LED_BTN_DEBOUNCE_DELAY=300
145+
#Should the button be triggerd on a high (default) or low value of the gpio
146+
LED_BTN_TRIGGER_ON_HIGH=1
121147
122148
#How many leds does the connected led stripe have?
123149
LED_MAX_LEDS=160
@@ -159,6 +185,13 @@ Open the file /home/pi/ledcontrol/ledcontrol.env in your favorit editor. In exam
159185
LED_PONG_RESULT_DELAY_DURING=2
160186
#How many seconds should the final result be displayed (fraction support!)?
161187
LED_PONG_RESULT_DELAY_AFTER=5
188+
189+
#Should the status be published after every config change? This is only needed if you use two different sources to change the configuration of the strip and want the second source to be updated if the first source changes a value.
190+
LED_PUBLISH_STATUS_AFTER_EVERY_CONFIG_CHANGE=0
191+
#Should the status be published if the output state changed? This feature is enabled because if one of the buttons gets pressed and you have an control source active the source gets informed that the output state changed.
192+
LED_PUBLISH_STATUS_IF_TOGGLED=1
193+
#Should the status be published at the script start?
194+
LED_PUBLISH_STATUS_AT_START=1
162195
```
163196

164197
### MQTT Messages ###

ledcontrol-WS2801.fzz

-56.9 KB
Binary file not shown.

ledcontrol-WS2801.png

-23.3 KB
Loading

ledcontrol-WS2813.fzz

-4.02 KB
Binary file not shown.

ledcontrol-WS2813.png

-21.4 KB
Loading

ledcontrol-WS281X.fzz

-56.2 KB
Binary file not shown.

ledcontrol-WS281X.png

-19.8 KB
Loading

ledcontrol-buttons-pulldown.fzz

4.38 KB
Binary file not shown.

ledcontrol-buttons-pulldown.png

116 KB
Loading
6.03 KB
Binary file not shown.
133 KB
Loading

ledcontrol-buttons-pullup.fzz

4.78 KB
Binary file not shown.

ledcontrol-buttons-pullup.png

116 KB
Loading

ledcontrol.env.example

+4-1
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ LED_BTN_ONE_GPIO=17
3131
LED_BTN_TWO_GPIO=27
3232
#How many milliseconds should be waited before another press of the same button is accepted?
3333
LED_BTN_DEBOUNCE_DELAY=300
34+
#Should the button be triggerd on a high (default) or low value of the gpio
35+
LED_BTN_TRIGGER_ON_HIGH=1
3436

3537
#How many leds does the connected led stripe have?
3638
LED_MAX_LEDS=160
@@ -75,6 +77,7 @@ LED_PONG_RESULT_DELAY_AFTER=5
7577

7678
#Should the status be published after every config change? This is only needed if you use two different sources to change the configuration of the strip and want the second source to be updated if the first source changes a value.
7779
LED_PUBLISH_STATUS_AFTER_EVERY_CONFIG_CHANGE=0
78-
7980
#Should the status be published if the output state changed? This feature is enabled because if one of the buttons gets pressed and you have an control source active the source gets informed that the output state changed.
8081
LED_PUBLISH_STATUS_IF_TOGGLED=1
82+
#Should the status be published at the script start?
83+
LED_PUBLISH_STATUS_AT_START=1

ledcontrol.py

+13-2
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
DEFAULT_BTN_ONE_GPIO=17
2626
DEFAULT_BTN_TWO_GPIO=27
2727
DEFAULT_BTN_DEBOUNCE_DELAY=300
28+
DEFAULT_BTN_TRIGGER_ON_HIGH=True
2829
DEFAULT_PONG_BTN_DELAY=2.0
2930
DEFAULT_PONG_MAX_WINS=2
3031
DEFAULT_PONG_TOLERANCE=2
@@ -44,6 +45,7 @@
4445
DEFAULT_COLOR_B=255
4546
DEFAULT_PUBLISH_STATUS_AFTER_EVERY_CONFIG_CHANGE=False
4647
DEFAULT_PUBLISH_STATUS_IF_TOGGLED=True
48+
DEFAULT_PUBLISH_STATUS_AT_START=True
4749

4850
#set the gpio mode to use the gpio numbering and not the pin numbering
4951
GPIO.setmode(GPIO.BCM)
@@ -105,6 +107,7 @@ def get_board_pin(gpio_nr):
105107
btn_one_gpio = sys_var_to_var("LED_BTN_ONE_GPIO", DEFAULT_BTN_ONE_GPIO)
106108
btn_two_gpio = sys_var_to_var("LED_BTN_TWO_GPIO", DEFAULT_BTN_TWO_GPIO)
107109
btn_debounce = sys_var_to_var("LED_BTN_DEBOUNCE_DELAY", DEFAULT_BTN_DEBOUNCE_DELAY)
110+
btn_trigger_on_high = sys_var_to_var("LED_BTN_TRIGGER_ON_HIGH", DEFAULT_BTN_TRIGGER_ON_HIGH)
108111

109112
reverse_mode = False
110113
cur_pixel = 0
@@ -152,6 +155,7 @@ def get_board_pin(gpio_nr):
152155

153156
publish_status_after_every_config_change = sys_var_to_var("LED_PUBLISH_STATUS_AFTER_EVERY_CONFIG_CHANGE", DEFAULT_PUBLISH_STATUS_AFTER_EVERY_CONFIG_CHANGE)
154157
publish_status_if_toggled = sys_var_to_var("LED_PUBLISH_STATUS_IF_TOGGLED", DEFAULT_PUBLISH_STATUS_IF_TOGGLED)
158+
publish_status_at_start = sys_var_to_var("LED_PUBLISH_STATUS_AT_START", DEFAULT_PUBLISH_STATUS_AT_START)
155159

156160
led_gpio_mode = False
157161
if led_gpio_pin > 0:
@@ -639,12 +643,19 @@ def do_cleanup(signum, frame):
639643
GPIO.setup(btn_one_gpio, GPIO.IN)
640644
GPIO.setup(btn_two_gpio, GPIO.IN)
641645

642-
GPIO.add_event_detect(btn_one_gpio, GPIO.RISING, callback=callback_one, bouncetime = btn_debounce)
643-
GPIO.add_event_detect(btn_two_gpio, GPIO.RISING, callback=callback_two, bouncetime = btn_debounce)
646+
if btn_trigger_on_high == True:
647+
trigger_on = GPIO.RISING
648+
else:
649+
trigger_on = GPIO.FALLING
650+
651+
GPIO.add_event_detect(btn_one_gpio, trigger_on, callback=callback_one, bouncetime = btn_debounce)
652+
GPIO.add_event_detect(btn_two_gpio, trigger_on, callback=callback_two, bouncetime = btn_debounce)
644653

645654
#only if mqtt should be used we activate the clients
646655
if mqtt_active:
647656
connect_mqtt_client()
657+
if publish_status_at_start:
658+
publish_current_status()
648659

649660
try:
650661
while not stop_now:

0 commit comments

Comments
 (0)