Merge pull request #28245 from Return7g/translating

[提交译文][tech]: 20221126.2 ️ Create a holiday light display with your Raspberry Pi and ping pong balls.md
This commit is contained in:
Xingyu.Wang 2022-12-16 08:55:16 +08:00 committed by GitHub
commit 18aa0f6dd9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 129 additions and 130 deletions

View File

@ -1,130 +0,0 @@
[#]: subject: "Create a holiday light display with your Raspberry Pi and ping pong balls"
[#]: via: "https://opensource.com/article/22/11/raspberry-pi-holiday-light-display"
[#]: author: "Brian McCafferty https://opensource.com/users/bdm"
[#]: collector: "lkxed"
[#]: translator: "Return7g"
[#]: reviewer: " "
[#]: publisher: " "
[#]: url: " "
Create a holiday light display with your Raspberry Pi and ping pong balls
======
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][1].
### Shopping list
- [Raspberry Pi Zero][2]
- [Pibow Case][3]
- 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.][4]
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][5] 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.][6]
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.][7]
### Test the code
For the test code to ensure that everything was working, I used this [Adafruit guide][8] 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.][9]
![Reindeer painted with light.][10]
![An LED snowflake.][11]
### 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][12].
You can also see a video of it in action here: [XMas light display][13].
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!
--------------------------------------------------------------------------------
via: https://opensource.com/article/22/11/raspberry-pi-holiday-light-display
作者:[Brian McCafferty][a]
选题:[lkxed][b]
译者:[译者ID](https://github.com/译者ID)
校对:[校对者ID](https://github.com/校对者ID)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
[a]: https://opensource.com/users/bdm
[b]: https://github.com/lkxed
[1]: https://github.com/bmccafferty/ping-pong-led-wall
[2]: https://shop.pimoroni.com/products/raspberry-pi-zero-wh-with-pre-soldered-header
[3]: https://shop.pimoroni.com/products/pibow-zero-w
[4]: https://opensource.com/sites/default/files/2022-11/IMG_20201126_115520.jpeg
[5]: https://opensource.com#the-code
[6]: https://opensource.com/sites/default/files/2022-11/IMG_20201127_101409.webp
[7]: https://opensource.com/sites/default/files/2022-11/IMG_20201127_160500.webp
[8]: https://learn.adafruit.com/neopixels-on-raspberry-pi/python-usage
[9]: https://opensource.com/sites/default/files/2022-11/IMG_20201127_181931.webp
[10]: https://opensource.com/sites/default/files/2022-11/IMG_20201202_215902.webp
[11]: https://opensource.com/sites/default/files/2022-11/IMG_20201127_215314.webp
[12]: https://projects.bdm.scot/Xmas%20LED%20Wall%202020/
[13]: https://youtu.be/zc0501GzpMw

View File

@ -0,0 +1,129 @@
[#]: subject: "Create a holiday light display with your Raspberry Pi and ping pong balls"
[#]: via: "https://opensource.com/article/22/11/raspberry-pi-holiday-light-display"
[#]: author: "Brian McCafferty https://opensource.com/users/bdm"
[#]: collector: "lkxed"
[#]: translator: "Return7g"
[#]: reviewer: " "
[#]: publisher: " "
[#]: url: " "
利用树莓派和乒乓球制作一个假日彩灯
======
我喜欢圣诞装饰品和灯饰,因此很长一段时间以来我一直想做一个可编程的 LED 项目。最近,我制作了一个由 LED 灯、乒乓球和树莓派 Zero 组成的灯阵列。这个项目相对简单并且具有教学价值,因此我认为它非常值得分享。
整个彩灯由我设计,但其中一些灵感也来自 YouTube。你可以在我的 [Git 存储库][1] 中找到源代码和构建说明。
### 购物清单
- [树莓派 Zero][2]
- [树莓派保护壳][3]
- 5V 2A 的电源线
- 展架
- 255 个乒乓球
- 热熔胶枪和若干热熔胶棒
- 烙铁
- 焊锡丝
- 22 AWG 0.35mm 实芯线
- 10 米 WS2812(B) LED灯带每米 30 像素)
- 万用表
- 钢丝钳
- 剥线钳
### 设计树莓派的灯光效果
这个设计是由我展框的大小决定的。我在全球速卖通买到了每米 30 像素的灯带,它可以轻松地切成 0.5m 的长度,这样我就有了 15 个 LED。 乒乓球的直径是 40 毫米,所以我测量并放置了 40 毫米的线,每 40 毫米部分的中间都有 LED 灯条,这就产生了 17 行。 因此我的灯光阵列是 15×17。你可以根据实际情况来调整尺寸。
为了给灯带和树莓派供电,我在电路板底部设置了数据线和电源线。我的 LED 灯不需要很多电,所以我使用树莓派 Zero 的 5V 输出 GPIO 为它们供电。当我以 50% 的亮度运行时,这个亮度已经足以在白天和晚上透过我的窗户看到。
### 布线
我从电路板的底部以之字形开始布线,这使得焊接非常容易,因为每行的末尾不必返回到每行的开头。
我的线路大致像这样(为清楚起见,这里进行了简化,实际上它一共有 17 行):
```
<---------------\
                |
/---------------/
|
\---------------< # 这里连接树莓派
```
### 使用树莓派搭建显示屏
当设计和布线的工作完成后就可以开始搭建显示屏了。
我在展板上测量并绘制了线路。我的灯带背面有胶带,所以我只需要取下背衬并将其贴在展板上。我检查了每个灯带的位置和数据线的方向以确保灯带可以按照树莓派的指令正确运作。
连接好所有灯带后,我剪下三段长度相同的电线,并将每个灯带末端的电源线、数据线和接地线连接到其上方。
![Connect each light strip at the end of each line.][4]
在线路连接完成后,我检查了每条灯带之间的电源线和地线之间的连续性,以确保其连通性。我还检查了是否存在错误的桥接,所以我验证了电源线和地线之间的连续性。我还进行了一些测试以确保所有灯都正常点亮(参阅[测试代码][5]。)
完成上述工作后,我开始在乒乓球上剪洞,用剪刀刺入乒乓球的底部,然后剪一个小洞让 LED 灯穿进去。我每米使用 30 个像素的 LED 灯,所以每个 LED 之间有大约 30 毫米的空隙。
在 LED 灯上滴上热熔胶,然后在 LED 上放了一个乒乓球并按住大约五秒钟,就粘好了一个乒乓球。粘贴下一个乒乓球时我只需要挨着上一个乒乓球就能让所有乒乓球都变得整齐了
![It's a tight fit, but the 40mm ping pong balls fit in a 30mm space just fine.][6]
我继续为余下的乒乓球进行焊接。尽管这个过程中有几个乒乓球被压碎了,但最终还是顺利完成了制作。
![255 LEDs and 255 ping pong balls in an array.][7]
### 测试代码
测试代码需要确保所有部件都能正常工作,为此我使用了[Adafruit 指南][8],它以红、绿和蓝点亮每个 LED然后依次进行循环。我在测试时使用它来确保我连接无误并且焊接正常。
在此之后,我在电子表格中设计了一个网格,将每个像素映射到一个网格位置。由于我的像素编号呈之字形排列,因此很难跟踪每个 LED例如 A1 为 256B1 为 226。重新映射网格位置能使得我在构建图像时更容易。
在所有准备工作完成之后,我就可以在纸上和电子表格中设计图像,然后编码。于是我开始添加一些动画(使用循环并将像素变为一种颜色,然后变为另一种颜色)。
最终的结果还算顺利。
![A Christmas gift in LED.][9]
![Reindeer painted with light.][10]
![An LED snowflake.][11]
### 全年可用的树莓派彩灯
我不确定这是否已经完全完成了。自从把它摆放到橱窗里,几乎每个晚上我都会添加一些新的图像和动画。我已经在考虑除夕夜的时候要做成什么样了。它不会像圣诞装饰品一起在圣诞节后被放进储藏室。 我只需要在上面显示其它图案,就能使它成为一个全年可用的彩灯! 我的一个朋友推荐了像素马里奥,这听起来是个好主意!
我的代码仍然需要完善。 例如,我做了一些滚动文本,但当我为文本的每个位置重新绘制时却花了很多时间。我想我可以用循环做一些事情,或者图像库可以帮助更轻松地滚动字母,并使添加文本更容易,而不是在每一步打开和关闭每个像素。
这里有一张照片记录了我制作的全过程[LED 乒乓墙][12]。
可以在此处观看它的运行视频:[XMas 灯光展示][13]。
这个彩灯最终的效果我非常满意。以后我也会尝试更多利用 LED 彩灯完成的项目。我也鼓励大家亲自动手制作一个这样的彩灯,它会比你想象中更简单。
--------------------------------------------------------------------------------
via: https://opensource.com/article/22/11/raspberry-pi-holiday-light-display
作者:[Brian McCafferty][a]
选题:[lkxed][b]
译者:[Return7g](https://github.com/Return7g)
校对:[校对者ID](https://github.com/校对者ID)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
[a]: https://opensource.com/users/bdm
[b]: https://github.com/lkxed
[1]: https://github.com/bmccafferty/ping-pong-led-wall
[2]: https://shop.pimoroni.com/products/raspberry-pi-zero-wh-with-pre-soldered-header
[3]: https://shop.pimoroni.com/products/pibow-zero-w
[4]: https://opensource.com/sites/default/files/2022-11/IMG_20201126_115520.jpeg
[5]: https://opensource.com#the-code
[6]: https://opensource.com/sites/default/files/2022-11/IMG_20201127_101409.webp
[7]: https://opensource.com/sites/default/files/2022-11/IMG_20201127_160500.webp
[8]: https://learn.adafruit.com/neopixels-on-raspberry-pi/python-usage
[9]: https://opensource.com/sites/default/files/2022-11/IMG_20201127_181931.webp
[10]: https://opensource.com/sites/default/files/2022-11/IMG_20201202_215902.webp
[11]: https://opensource.com/sites/default/files/2022-11/IMG_20201127_215314.webp
[12]: https://projects.bdm.scot/Xmas%20LED%20Wall%202020/
[13]: https://youtu.be/zc0501GzpMw