[ad_1]
Embedded developer Kenny Peng has turned a Raspberry Pi single-board pc right into a toy filled with digital sloshing enjoyable, working a stay fluid simulator that responds to motion — and is displayed on a compact OLED panel.
“This challenge makes use of an SSD1306 OLED module, a [TDK InvenSense] MPU6050 accelerometer, and a Raspberry Pi 4 to comprehend a fluid simulation toy that allows you to toss round an ocean of water in your hand,” Peng explains of the just-for-fun creation. “That’s, it simulates fluid dynamics at a scale bigger than the precise display screen. This may be regarded as a ‘free-surface move’ downside, and it is solved by a ‘smoothed-particle hydrodynamics’ (SPH) method.”
Not like extra sophisticated physics simulations and their want for high-end general-purpose graphics processing unit (GPGPU) or devoted acceleration {hardware}, Peng’s toy ocean runs on the Raspberry Pi’s CPU — “the outcomes can solely be higher if somebody leveraged extra fashionable SPH strategies or the Raspberry Pi 4’s GPU,” Peng notes, referring to the power to dump massively-parallel computation to the graphics processor so as to enhance efficiency.
The key to the challenge’s fluid motion, pun fully meant, is, as Peng says, smoothed-particle hydrodynamics — a computational strategy to strong and fluid simulation which makes use of a mesh-free simulation methodology to higher simulate complicated boundary dynamics with out requiring an excessive amount of CPU or GPU energy, permitting it to run completely in real-time on the Raspberry Pi 4’s comparatively modest CPU. The efficiency is additional boosted by utilizing OpenMP to unfold the workload throughout all 4 CPU cores.
Peng’s challenge is written in lower than 750 traces of C, excluding the show driver code. (📷: Kenny Peng)
“In addition to the SSD1306 driver,” Peng says, “this challenge is just below 750 traces of C!” In that small chunk of code, although, Peng has carried out extra simulated physics than you’d anticipate of what’s usually a easy approximation for leisure — together with synthetic viscosity, strange advection, and floor stress results well faked utilizing synthetic stress.
Peng has printed the supply code for the challenge on GitHub below the permissive MIT license.
[ad_2]