利用树莓派和乒乓球制作一个假日彩灯
LED 树莓派
![](/data/attachment/album/202212/20/095754r7q0z001lvx6p600.jpg)



> 
> 这个树莓派教程用于制作一个可编程的 LED 灯光显示器，非常适合各种技能水平的人。
> 
> 
> 


我喜欢圣诞装饰品和灯饰，因此很长一段时间以来我一直想做一个可编程的 LED 项目。最近，我制作了一个由 LED 灯、乒乓球和树莓派 Zero 组成的灯阵列。这个项目相对简单并且具有教学价值，因此我认为它非常值得分享。


整个彩灯由我设计，但其中一些灵感也来自 YouTube。你可以在我的 [Git 存储库](https://github.com/bmccafferty/ping-pong-led-wall) 中找到源代码和制作说明。


### 购物清单


* [树莓派 Zero](https://shop.pimoroni.com/products/raspberry-pi-zero-wh-with-pre-soldered-header)
* [树莓派保护壳](https://shop.pimoroni.com/products/pibow-zero-w)
* 5V 2A 的电源线
* 展架
* 255 个乒乓球
* 热熔胶枪和若干热熔胶棒
* 烙铁
* 焊锡丝
* 22 AWG 0.35mm 实芯线
* 10 米 WS2812(B) LED 灯带（每米 30 像素）
* 万用表
* 钢丝钳
* 剥线钳


### 设计树莓派的灯光效果


这个设计是根据我展框的大小决定的。我在全球速卖通买到了每米 30 像素的灯带，它可以轻松地切成 0.5 米的长度，每条有 15 个 LED 灯。乒乓球的直径是 40 毫米，所以我测量并隔开 40 毫米划了线，LED 灯条放在每隔 40 毫米的中间部分，这就产生了 17 条线。因此我的灯光阵列是 15×17。你可以根据实际情况来调整尺寸。


为了给灯带和树莓派供电，我在电路板底部设置了数据线和电源线。我的 LED 灯不需要很多电，所以我使用树莓派 Zero 的 5V 输出 GPIO 为它们供电。当我以 50% 的亮度运行时，这个亮度已经足以在白天和晚上透过我的窗户看到。


### 布线


我从电路板的底部以之字形开始布线，这使得焊接非常容易，因为每行的末尾不必返回到每行的开头。


我的线路大致像这样（为清楚起见，这里进行了简化，实际上它一共有 17 行）：



```
<---------------\
                |
/---------------/
|
\---------------< # 这里连接树莓派

```

### 使用树莓派制作显示屏


当设计和布线的工作完成后就可以开始制作显示屏了。


我在展板上测量并绘制了线路。我的灯带背面有胶带，所以我只需要取下背衬并将其贴在展板上。我检查了每个灯带的位置和数据线的方向，以确保灯带可以按照树莓派的指令正确串联起来。


连接好所有灯带后，我剪下三段长度相同的电线，并将每个灯带末端的电源线、数据线和接地线连接到其上方。


![Connect each light strip at the end of each line.](/data/attachment/album/202212/20/100354tlulluxeuclluhpm.jpg)


在线路连接完成后，我检查了每条灯带之间的电源线和地线之间的连接，以确保其连通性。我还检查了是否存在错误的桥接，所以我验证了电源线和地线之间的连接。我还进行了一些测试以确保所有灯都正常点亮（链路测试参阅 [测试代码](https://opensource.com#the-code)）。


完成上述工作后，我开始在乒乓球上剪洞，用剪刀刺入乒乓球的底部，然后剪一个小洞让 LED 灯穿进去。手工不太行，每个球都不太一样，但效果真的很好。我使用的每米 30 个像素的 LED 灯，所以每个 LED 之间有大约 30 毫米的空隙。一个乒乓球是 40 毫米宽，但我不打算开始单独焊接每一个 LED！我想，这是很重要的。首先，我并不擅长焊接（正如我的照片所显示的），而且无论如何，我想“好吧，它们是乒乓球。我可以把它们压在一起！”


我是这样做的：


在 LED 灯上滴上热熔胶，然后在 LED 上放了一个乒乓球并按住大约五秒钟，就粘好了一个乒乓球。粘贴下一个乒乓球时我只需要挤着上一个乒乓球，就能让所有乒乓球都变得整齐了。我对它的外观很满意。它还有一个很好的好处，就是掩盖了我糟糕的焊接工作；)


![It's a tight fit, but the 40mm ping pong balls fit in a 30mm space just fine.](/data/attachment/album/202212/20/100410arrfbthgvdjw4te9.jpg)


我继续为余下的乒乓球进行焊接。尽管这个过程中有几个乒乓球被压碎了，但最终还是顺利完成了制作。


![255 LEDs and 255 ping pong balls in an array.](/data/attachment/album/202212/20/100419er37eu6neeatmetu.jpg)


### 测试代码


测试代码需要确保所有部件都能正常工作，为此我使用了这个 [Adafruit 指南](https://learn.adafruit.com/neopixels-on-raspberry-pi/python-usage)，它以红、绿和蓝点亮每个 LED，然后依次进行循环。我在测试时使用它来确保我连接无误并且焊接正常。


在此之后，我在电子表格中设计了一个网格，将每个像素映射到一个网格位置。由于我的像素编号呈之字形排列，因此很难跟踪每个 LED（例如 A1 为 256，B1 为 226）。重新映射网格位置能使得我在构建图像时更容易。


在所有准备工作完成之后，我就可以在纸上和电子表格中设计图像，然后编码。于是我开始添加一些动画（使用循环并将像素变为一种颜色，然后变为另一种颜色）。


最终的结果还算顺利。


![A Christmas gift in LED.](/data/attachment/album/202212/20/100430ofhhsq7dw4h37bdz.jpg)


![Reindeer painted with light.](/data/attachment/album/202212/20/100438hwczghif9v01qr5b.jpg)


![An LED snowflake.](/data/attachment/album/202212/20/100445jhhgkds0kcups7zk.jpg)


### 能玩一年的树莓派彩灯


我不确定这是否已经完全完成了。自从把它摆放到橱窗里，几乎每个晚上我都会添加一些新的图像和动画。我已经在考虑除夕夜的时候要做成什么样了。它不会像圣诞装饰品一起在圣诞节后被放进储藏室。我只需要在上面显示其它图案，就能使它成为一个能玩一年的彩灯！我的一个朋友推荐了像素版马里奥，这听起来是个好主意！


我的代码仍然需要完善。例如，我做了一些滚动文本，但当我为文本的每个位置重新绘制时却花了很多时间。我想我可以用循环做一些事情，或者图像库可以帮助更轻松地滚动字母，并使添加文本更容易，而不是在每一步打开和关闭每个像素。


这里有一张照片记录了我制作的全过程：[LED 乒乓墙](https://projects.bdm.scot/Xmas%20LED%20Wall%202020/)。


可以在此处观看它的运行视频：[XMas 灯光展示](https://youtu.be/zc0501GzpMw)。


这个彩灯最终的效果我非常满意。以后我也会尝试更多利用 LED 彩灯完成的项目。我也鼓励大家亲自动手制作一个这样的彩灯，它会比你想象中更简单。




---


via: <https://opensource.com/article/22/11/raspberry-pi-holiday-light-display>


作者：[Brian McCafferty](https://opensource.com/users/bdm) 选题：[lkxed](https://github.com/lkxed) 译者：[Return7g](https://github.com/Return7g) 校对：[wxy](https://github.com/wxy)


本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译，[Linux中国](https://linux.cn/) 荣誉推出


OK
I love Christmas decorations and lights, and I'd been wanting to do an programmable LED project for a long time. Recently, I built a light array made of LED lights, ping pong balls, and a Raspberry Pi Zero. I thought it was worth sharing, because it ended up being relatively easy but also educational.

It's mostly my own design, with some inspiration from YouTube videos. You can find the source code and build instructions in my [Git repository](https://github.com/bmccafferty/ping-pong-led-wall).

## Shopping list

[Raspberry Pi Zero](https://shop.pimoroni.com/products/raspberry-pi-zero-wh-with-pre-soldered-header)[Pibow Case](https://shop.pimoroni.com/products/pibow-zero-w)- 5v 2A USB power supply
- Poster frame
- 255 ping pong balls
- Hot glue gun and LOTS of hot glue sticks
- Soldering iron
- Solder
- 22 AWG 0.35mm solid core wiring
- 10 meters of WS2812(B) LED strip lights (30 pixels per meter)
- Multimeter
- Wire cutters
- Wire strippers

## Design the Raspberry Pi light display

My design was driven by the size of the poster frame I happened to have available. I got 30 pixel per meter tape from Ali Express, which cut nicely into 0.5m sections, so that gave me 15 LEDs across. Ping pong balls are 40mm, so I measured and placed the lines 40mm apart, with the LED Strip in the middle of each 40mm section. This gave me 17 lines down in total. My array was therefore 15×17. If you try this yourself, yours can be a different size.

To get power to the array and the Raspberry Pi, I placed the open connections for both data and power at the bottom of the board. I didn't have that many LEDs needing power, so I was able to use the 5v out GPIO from the Raspberry Pi Zero to power them. I run them at 50% brightness, which is easily bright enough to see in the day and at night through my window.

## Wiring

In my design, I started at the bottom of the board and wired up in an S-curve. This made soldering easier because loops at the end of each row didn't have to return all the way back to the start of each line. The WS2812 data lines do require you to wire the data the correct way: power can be fed from either side of the strip, but data must be fed from the side with the arrows pointing away.

My wiring looks like this (this is abbreviated for clarity, in real life it's 17 lines deep):

```
``````
<---------------\
|
/---------------/
|
\---------------< # Pi connected here
```


## Build the display with your Raspberry Pi

Once the design and wiring plan was sorted, it was time to get started on the build.

I measured and drew my lines in pencil on the poster backboard. The WS2812 strips I got came with sticky tape on the back, so I just removed the backing and attached that directly to the backboard. I was sure to position each strip so that the data arrows went one way, then back the other, to ensure that the lights could be daisy-chained correctly for the Pi's instructions.

Once all light strips were attached, I cut three similar lengths of wire and connected the 5v, data, and ground lines from the end of each light section to the one above it.

![Connect each light strip at the end of each line.](https://opensource.com/sites/default/files/2022-11/IMG_20201126_115520.jpeg)

(Brian McCafferty, CC BY-SA 4.0)


After completing each row, I checked continuity between the 5v and ground lines between each strip to ensure my joins were correct. I also checked that I had not accidentally bridged any connections, so I verified that there was no continuity between the 5v and ground lines (in other words, a 5v wire on one line didn't bridge to the ground on the next line.) I also ran some tests to ensure everything was lighting up correctly (see [the code](#the-code) section for my strand tests.)

Once this was complete, I started to cut holes in the ping pong balls by stabbing scissors into the bottom of them, and cutting a small hole for the LED to shine into. There was no exact science to this, and each one was different, but the effect really worked. I was working with 30 pixels per meter, so my lighting had about 30mm between each LED. A ping pong ball is 40mm across, but I wasn't about to start soldering each LED individually! First of all, I'm not that good at soldering (as my photos show), and anyway, I thought "Well, they're ping pong balls. I can just squash them together!"

And that's what I did.

I placed a hot glue blob around each LED and then placed a ping pong ball onto the LED, held it for about five seconds, and moved on to the next one. I held onto the previous ping pong ball as I slid the next one in, pushing it against the first before "folding" it into its neighbor. The effect worked really well. I was happy with what it was looking like straight away. It also had the nice bonus of hiding my bad soldering job ;)

![It's a tight fit, but the 40mm ping pong balls fit in a 30mm space just fine.](https://opensource.com/sites/default/files/2022-11/IMG_20201127_101409.webp)

(Brian McCafferty, CC BY-SA 4.0)

I continued doing this for 255 LEDs and ping pong balls. There were a few crushed ping pong balls in the process, but in the end, I got there.

![255 LEDs and 255 ping pong balls in an array.](https://opensource.com/sites/default/files/2022-11/IMG_20201127_160500.webp)

(Brian McCafferty, CC BY-SA 4.0)

## Test the code

For the test code to ensure that everything was working, I used this [Adafruit guide](https://learn.adafruit.com/neopixels-on-raspberry-pi/python-usage) which lights each LED in red, green, and blue, and then does a rainbow cycle. I used this when I was building to ensure my connections were correct and that everything was soldered correctly.

After that, I designed a grid in a spreadsheet to map each pixel to a grid position. This helped to make building the images easier. Since my pixel numbers run in a zig-zag pattern, it would have been hard to keep track of each LED (e.g. LED A1 was 256 and B1 was 226).

Once this was all set, it was time to design some images on paper and in the spreadsheet. Then it was time to code! It got a bit addictive and I started adding some animation (using loops and turning pixels onto one color and then another color).

The end result was everything I'd hoped it would be.

![A Christmas gift in LED.](https://opensource.com/sites/default/files/2022-11/IMG_20201127_181931.webp)

(Brian McCafferty, CC BY-SA 4.0)

![Reindeer painted with light.](https://opensource.com/sites/default/files/2022-11/IMG_20201202_215902.webp)

(Brian McCafferty, CC BY-SA 4.0)

![An LED snowflake.](https://opensource.com/sites/default/files/2022-11/IMG_20201127_215314.webp)

(Brian McCafferty, CC BY-SA 4.0)

## A Raspberry Pi light display all year

I am not sure this will ever be truly finished. Nearly every night since it's been up in the window, I've added some new images and animations. I'm already thinking about what to do for New Year's Eve. I also won't be putting this back in storage with my Christmas decorations in January. I just need to think of other things to draw on it to make it a year-round project! A friend of mine suggested a pixel Mario and I love that idea!

My code also needs a little work. For example, I do some scrolling text, but I redraw the whole board for each position of the text, so it took quite a bit of time to do. I think I can do something with loops, or perhaps the image library can help scroll the letters easier, and make it easier to add text rather than turning each pixel on and off at every step.

I've got a photo record of my progress from start to finish: [LED Ping Pong Wall](https://projects.bdm.scot/Xmas%20LED%20Wall%202020/).

You can also see a video of it in action here: [XMas light display](https://youtu.be/zc0501GzpMw).

I'm really pleased with how this turned out, and I think it looks amazing. I'm very excited to try some other LED projects in the future. I encourage you to try a light array of your own even as your first project. It's easier than it looks!

## 1 Comment