xSnowHeadx / ambi-tv

a flexible ambilight clone for embedded linux
7 stars 2 forks source link

Segmentation Fault with Pi 3B+/4 and WS2812b #5

Open patrickmollohan opened 3 years ago

patrickmollohan commented 3 years ago

I've decided to upgrade my ambi-tv setup with a high-density WS2812b strip. Along with that and a few other upgrades, I was hoping to use a newer Raspberry Pi, so I bought a new Pi 4 (1GB). I was able to get everything working with my older Pi 2B, so I swapped the old Pi for the new one. Upon running the ambi-tv command, I get a segmentation fault. The same is true on a Pi 3B+. I don't have a Pi 3 to test with. I tried swapping the working SD card over to the new Pi, as well as starting over from scratch; however, there is no change. I followed the setup of these instructions to ensure the wiring is correct, Pi is working, etc.

The output I get when running the ambi-tv command is:

*********************************************************
*  ambi-tv: diy ambient lighting for your screen or tv  *
*                                         (c) @gkaindl  *
*********************************************************

registration: registered component 'v4l2-video' (class v4l2-grab-source).
    device name:              /dev/video0
    video-norm:               NTSC
    buffers:                  8
    crop-top:                 20
    crop-right:               10
    crop-bottom:              15
    crop-left:                15
    auto-crop luma threshold: 15
registration: registered component 'audio-grab' (class audio-grab-source).
    device name:              hw:2,0
registration: registered component 'timer-30fps' (class timer-source).
    millis: 33
registration: registered component 'timer-10Hz' (class timer-source).
    millis: 100
registration: registered component 'led-frame' (class ledstripe-sink).
    device name:         DMA5
    dev hz:              800000
    dev type:        WS281x
    number of leds:      588
    blending frames:     8
    led insets (tblr):   0.0%, 0.0%, 0.0%, 0.0%
    brightness:          100%
    intensity (rgb):     90%, 100%, 100%
    intensity-min (rgb): 4%, 4%, 4%
    gamma (rgb):         1.66, 1.60, 1.65
registration: registered component 'led-frame_fast' (class ledstripe-sink).
    device name:         DMA5
    dev hz:              800000
    dev type:        WS281x
    number of leds:      588
    blending frames:     0
    led insets (tblr):   0.0%, 0.0%, 0.0%, 0.0%
    brightness:          100%
    intensity (rgb):     90%, 100%, 100%
    intensity-min (rgb): 4%, 4%, 4%
    gamma (rgb):         1.66, 1.60, 1.65
registration: registered component 'avg-color' (class avg-color-processor).
registration: registered component 'edge-color' (class edge-color-processor).
    type:  0
    box-width:  8
    box-height: 12
registration: registered component 'edge-color_fast' (class edge-color-processor).
    type:  0
    box-width:  40
    box-height: 60
registration: registered component 'sbs-color' (class edge-color-processor).
    type:  1
    box-width:  4
    box-height: 12
registration: registered component 'tob-color' (class edge-color-processor).
    type:  2
    box-width:  8
    box-height: 6
registration: registered component 'audio-proc-spectrum' (class audio-processor).
    type       : 0
    sensitivity:  150
    smoothing  : 6
    levelcolor : 000000
    linear     : 0
registration: registered component 'audio-proc-average' (class audio-processor).
    type       : 1
    sensitivity:  150
    smoothing  : 6
    levelcolor : 000000
    linear     : 0
registration: registered component 'audio-proc-lmeter' (class audio-processor).
    type       : 2
    sensitivity:  150
    smoothing  : 6
    levelcolor : 000000
    linear     : 0
registration: registered component 'mood-light-180' (class mood-light-processor).
    speed:  2.0
    mode:  0
registration: registered component 'mood-light-360' (class mood-light-processor).
    speed:  1.0
    mode:  1
registration: registered component 'mood-light-full' (class mood-light-processor).
    speed:  1.0
    mode:  2
program: 'program_tv_edge_color': appended component 'v4l2-video'.
program: 'program_tv_edge_color': appended component 'edge-color'.
program: 'program_tv_edge_color': appended component 'led-frame'.
program: registered program 'program_tv_edge_color'.
program: 'program_tv_edge_color_fast': appended component 'v4l2-video'.
program: 'program_tv_edge_color_fast': appended component 'edge-color_fast'.
program: 'program_tv_edge_color_fast': appended component 'led-frame_fast'.
program: registered program 'program_tv_edge_color_fast'.
program: 'program_tv_sbs_color': appended component 'v4l2-video'.
program: 'program_tv_sbs_color': appended component 'sbs-color'.
program: 'program_tv_sbs_color': appended component 'led-frame'.
program: registered program 'program_tv_sbs_color'.
program: 'program_tv_ttb_color': appended component 'v4l2-video'.
program: 'program_tv_ttb_color': appended component 'tob-color'.
program: 'program_tv_ttb_color': appended component 'led-frame'.
program: registered program 'program_tv_ttb_color'.
program: 'program_tv_avg_color': appended component 'v4l2-video'.
program: 'program_tv_avg_color': appended component 'avg-color'.
program: 'program_tv_avg_color': appended component 'led-frame'.
program: registered program 'program_tv_avg_color'.
program: 'program_audio_band': appended component 'audio-grab'.
program: 'program_audio_band': appended component 'audio-proc-spectrum'.
program: 'program_audio_band': appended component 'led-frame'.
program: registered program 'program_audio_band'.
program: 'program_audio_avg': appended component 'audio-grab'.
program: 'program_audio_avg': appended component 'audio-proc-average'.
program: 'program_audio_avg': appended component 'led-frame'.
program: registered program 'program_audio_avg'.
program: 'program_audio_lmeter': appended component 'audio-grab'.
program: 'program_audio_lmeter': appended component 'audio-proc-lmeter'.
program: 'program_audio_lmeter': appended component 'led-frame'.
program: registered program 'program_audio_lmeter'.
program: 'program_mood_light_180': appended component 'timer-30fps'.
program: 'program_mood_light_180': appended component 'mood-light-180'.
program: 'program_mood_light_180': appended component 'led-frame'.
program: registered program 'program_mood_light_180'.
program: 'program_mood_light_360': appended component 'timer-30fps'.
program: 'program_mood_light_360': appended component 'mood-light-360'.
program: 'program_mood_light_360': appended component 'led-frame'.
program: registered program 'program_mood_light_360'.
program: 'program_mood_light_full': appended component 'timer-10Hz'.
program: 'program_mood_light_full': appended component 'mood-light-full'.
program: 'program_mood_light_full': appended component 'led-frame'.
program: registered program 'program_mood_light_full'.
main: configuration finished, 11 programs available.
    program_tv_edge_color
    program_tv_edge_color_fast
    program_tv_sbs_color
    program_tv_ttb_color
    program_tv_avg_color
    program_audio_band
    program_audio_avg
    program_audio_lmeter
    program_mood_light_180
    program_mood_light_360
    program_mood_light_full
component: activating component 'v4l2-video'...
v4l2-grab: video format: 720x480 (YUYV 1440 bpl).
component: activating component 'edge-color'...
component: activating component 'led-frame'...
Segmentation fault

My ambi-tv.conf file:

# ambi-tv configuration file
#
# Please have a look at the included file README.md for information on
# how this file works.
#

v4l2-grab-source {
   name                          v4l2-video
   video-device                  /dev/video0
   video-norm                    NTSC    # alt. NTSC
   buffers                        8
   crop-left                     15
   crop-top                      20
   crop-right                    10
   crop-bottom                   15
   autocrop-luminance-threshold  15
}

audio-grab-source {
   name                          audio-grab
   audio-device                  hw:2,0
}

timer-source {
   name     timer-30fps
   millis   33
}

timer-source {
   name     timer-10Hz
   millis   100
}

ledstripe-sink {
   name              led-frame
   led-device        DMA5              # f.e. "DMA5" for DMA channel 5 for WS2811, /dev/spidev0.0 for other types
   dev-speed-hz      800000            # 800000 rsp. 400000 for dma device
   dev-type          WS281x            # LPD880x, WS280x or WS281x
   dev-pin           18                # PWM pin, unused for spi device 
   dev-inverse       0                 # inverter on PWM pin, unused for spi device
   dev-color-order   GRB               # byte order of colors in output stream (optional)
   leds-top          106-293           # left-to-right
   leds-bottom       587-400           # left-to-right
   leds-left         105-0             # top-to-bottom
   leds-right        294-399           # top-to-bottom
   led-inset-top     0
   led-inset-bottom  0
   led-inset-left    0
   led-inset-right   0
   blended-frames    8
   overall-brightness 100
   gamma-red         1.66
   gamma-green       1.6
   gamma-blue        1.65
   intensity-red      90
   intensity-green   100
   intensity-blue    100
   intensity-min-red  4
   intensity-min-green 4
   intensity-min-blue 4
}

ledstripe-sink {
   name              led-frame_fast
   led-device        DMA5              # f.e. "DMA5" for DMA channel 5 for WS2811, /dev/spidev0.0 for other types
   dev-speed-hz      800000            # 800000 rsp. 400000 for dma device
   dev-type          WS281x            # LPD880x, WS280x or WS281x
   dev-pin           18                # PWM pin, unused for spi device 
   dev-inverse       0                 # inverter on PWM pin, unused for spi device
   dev-color-order   GRB               # byte order of colors in output stream (optional)
   leds-top          106-293            # left-to-right
   leds-bottom       587-400      # left-to-right
   leds-left         105-0           # top-to-bottom
   leds-right        294-399             # top-to-bottom
   led-inset-top     0
   led-inset-bottom  0
   led-inset-left    0
   led-inset-right   0
   blended-frames    1
   overall-brightness 100
   gamma-red         1.66
   gamma-green       1.6
   gamma-blue        1.65
   intensity-red      90
   intensity-green   100
   intensity-blue    100
   intensity-min-red  4
   intensity-min-green 4
   intensity-min-blue 4
}

avg-color-processor {   
   name              avg-color
}

edge-color-processor {
   name              edge-color
   vtype              0
   box-width          8
   box-height         12                       
}

edge-color-processor {
   name              edge-color_fast
   vtype              0
   box-width          40
   box-height         60                       
}

edge-color-processor {
   name              sbs-color
   vtype              1
   box-width          4
   box-height         12
}

edge-color-processor {
   name              tob-color
   vtype              2
   box-width          8
   box-height         6
}

audio-processor {
   name              audio-proc-spectrum
   atype               0
   sensitivity        150
   smoothing           6
   levelcolor         000000
   linear              0
}

audio-processor {
   name              audio-proc-average
   atype               1
   sensitivity        150
   smoothing           6
   levelcolor         000000
   linear              0
}

audio-processor {
   name              audio-proc-lmeter
   atype               2
   sensitivity        150
   smoothing           6
   levelcolor         000000
   linear              0
}

mood-light-processor {
   name              mood-light-180
   speed             2
   mode              0
}

mood-light-processor {
   name              mood-light-360
   speed             1
   mode              1
}

mood-light-processor {
   name              mood-light-full
   speed             1
   mode              2
}

&program_tv_edge_color {    #Standardmodus
   activate          &v4l2-video
   activate          &edge-color
   activate          &led-frame
}

&program_tv_edge_color_fast {   #Schneller Modus
   activate          &v4l2-video
   activate          &edge-color_fast
   activate          &led-frame_fast
}

&program_tv_sbs_color {     #3D Side-by-Side
   activate          &v4l2-video
   activate          &sbs-color
   activate          &led-frame
}

&program_tv_ttb_color {     #3D Top-over-Bottom
   activate          &v4l2-video
   activate          &tob-color
   activate          &led-frame
}

&program_tv_avg_color {     #Bildmittelwert gesamt
   activate          &v4l2-video
   activate          &avg-color
   activate          &led-frame
}

&program_audio_band {       #Audio-Spektrum
   activate          &audio-grab
   activate          &audio-proc-spectrum
   activate          &led-frame
}

&program_audio_avg {        #Audio-Mittelwert
   activate          &audio-grab
   activate          &audio-proc-average
   activate          &led-frame
}

&program_audio_lmeter {     #Audio-Levelmeter
   activate          &audio-grab
   activate          &audio-proc-lmeter
   activate          &led-frame
}

&program_mood_light_180 {       #Mood-Light 180�
   activate          &timer-30fps
   activate          &mood-light-180
   activate          &led-frame
}

&program_mood_light_360 {       #Mood-Light 360�
   activate          &timer-30fps
   activate          &mood-light-360
   activate          &led-frame
}

&program_mood_light_full {       #Mood-Light Fullscreen
   activate          &timer-10Hz
   activate          &mood-light-full
   activate          &led-frame
}

Any help would be greatly appreciated!

xSnowHeadx commented 3 years ago

Unfortunately I own neither a Raspi3 nor a Raspi4. It seems that the DMA handling of the newer devices is different from the older ones. To verify this, select please another LED type using spi in the config. Even your LED will not work we can see if the segfault remains. Thanks.

patrickmollohan commented 3 years ago

It appears you are correct on this. While I didn't try selecting a different LED type, I did find a solution: updating rpihw.c and rpihw.h with https://raw.githubusercontent.com/jgarff/rpi_ws281x/master/rpihw.c https://raw.githubusercontent.com/jgarff/rpi_ws281x/master/rpihw.h

It so far works with my Pi 3B+. However, when attached to my Pi 4, the LED strip is unresponsive and the wires to the strip get extremely hot in seconds, as if something is shorting out. Perhaps that's a simple hardware defect with my Pi 4. I didn't risk looking at my terminal to see if it isn't segfaulting anymore, but I imagine the issue is fixed with the above files.

xSnowHeadx commented 3 years ago

Thank you for your hint and for sharing your solution. I successfully tested the new files an my Raspi2B and so updated the repository for all other users. Regarding your hardware issue it seems that you changed the positive with the negative power input on the LED stripe.

patrickmollohan commented 3 years ago

I'm glad to hear it works on your end as well! Thank you much for your time and efforts! Unfortunately not. The rest of the setup remains unchanged, just a Pi swap. The power and ground wires of the strip (as well as everything else) are connected to a 300W power supply, so the only wire going to the GPIO is the wire that goes to pin 18. Adding a ground wire between the Pi and strip doesn't help either, but would be redundant since the Pi is being powered by the power supply as well.

xSnowHeadx commented 3 years ago

It is weird that data problems should cause such a dramatic behaviour. I can't believe that the raspi should be the reason for that. What if you disconnect the data line from raspi to the stripe?