A few years ago, my curiousity sparked from a YouTube video that showcased someone skillfully orchestrating a Christmas tree’s lights using Python, crafting a stunning three-dimensional spectacle (which is displayed below). My initial fascination lingered, and now, armed with knowledge from my first semester in a Master’s in Data Science program, I believe I have the skills to bring a similar vision to life.
Despite a solid foundation in math and coding, my foray into the world of computer hardware presented unforeseen challenges. An absence of comprehensive guidance on what to purchase, how to wire the lights, and much more quickly became a formidable task. I hope this documentation serves a dual purpose: a roadmap for those embarking on a similar venture and a narrative detailing my data science journey.
I want to express my sincere gratitude to my friend Kangheng Liu, who provided invaluable support throughout this project. Together, we faced challenges head-on, persevered through difficulties, and shared in the triumphs. You can explore Kang’s work on his website here.
Join me on this technical adventure, from mastering coding to navigating the intricacies of hardware challenges. Together, let’s not only illuminate Christmas trees but also explore the fascinating intersection of technology, creativity, and the spirit of celebration.
Materials
Disclaimer: Acknowledging my novice status in this domain, I recognize that more cost-effective alternatives may exist for these components. The choices outlined below are specific to my project, and prices are based on my purchases in the fall of 2023, subject to fluctuations.
Now that all the materials have been acquired, demonstrating the feasibility of this project is the next crucial step. This phase involves testing fundamental functionalities to ensure that the project can progress successfully.
Proof of concepts serves as a critical checkpoint in any project, offering a preliminary validation of its viability. By addressing key questions such as turning lights on/off, changing colors, or controlling individual lights, we lay the foundation for the broader implementation. This step helps identify potential challenges early on and ensures that subsequent development is built on a solid framework.
Flashing the Raspberry Pi
Before diving into the light control, the Raspberry Pi needs to be set up with an operating system. Use the provided micro SD card and adapter to flash the Raspberry Pi using the Raspberry Pi Imager. During the flashing process, input the Wi-Fi information for future SSH access.
SSHing into the Raspberry Pi
After flashing, insert the SD card into the Raspberry Pi and power it on. This step initiates the device and prepares it for further configuration.
Mapping the Lights in 3D Space
Code
import plotly.graph_objects as go# Read data from the text filewithopen('lights500.txt', 'r') asfile: data = [eval(line.strip()) for line infile]# Extract coordinatesx, y, z =zip(*data)# Create a 3D scatter plotfig = go.Figure(data=[go.Scatter3d(x=x, y=y, z=z, mode='markers', marker=dict(size=3, color='green'))])# Set labelsfig.update_layout(scene=dict(xaxis_title='X Label', yaxis_title='Y Label', zaxis_title='Z Label'))# Show the plotfig.show()
the below code checks to see if there are any big changes that could cause problems with our data
Code
# Check for changes greater than or equal to 7for i inrange(1, len(data)): diff_x =abs(data[i][0] - data[i-1][0]) diff_y =abs(data[i][1] - data[i-1][1]) diff_z =abs(data[i][2] - data[i-1][2])if diff_x >=7or diff_y >=7or diff_z >=7:print(f"Change detected at index {i}: {diff_x=}, {diff_y=}, {diff_z=}")
Change detected at index 200: diff_x=8, diff_y=2, diff_z=5
Change detected at index 250: diff_x=9, diff_y=2, diff_z=0
Change detected at index 300: diff_x=0, diff_y=3, diff_z=7
the above output is what we want. the only changes detected occured when one strip changed into another… there were not fauly measurements or inputs of data