examples/LorenzAttractor/README.md
This project demonstrates how to simulate and visualize the Lorenz attractor, a chaotic system of differential equations, using an Arduino board and Serial Studio. The Arduino program calculates the Lorenz system's chaotic trajectory in real-time and sends the resulting data ($x$, $y$, $z$) to Serial Studio for plotting.
The Lorenz system, introduced by Edward Lorenz in 1963, is a set of three coupled differential equations commonly used to model atmospheric convection. Its iconic "butterfly-shaped" attractor has become a symbol of chaos theory. For more information on the Lorenz system, visit this article.
Note: This project makes use of features that are only available under a paid license. Please visit serial-studio.com for more information.
The system is governed by the following equations:
$$ \frac{dx}{dt} = \sigma (y - x) $$ $$ \frac{dy}{dt} = x (\rho - z) - y $$ $$ \frac{dz}{dt} = x y - \beta z $$
Where:
The Arduino program uses the Euler method for numerical integration to calculate the system's state over time.
No additional hardware is required beyond the Arduino. Ensure the Arduino is connected to your computer via USB.
The provided Arduino code simulates the Lorenz attractor and transmits the calculated values $x$, $y$ and $z$ to Serial Studio. Here's the complete code:
//
// Lorenz Attractor Data Generator
//
// Author: Alex Spataru
//
// Parameters for the Lorenz system
float sigma = 10.0; // σ: rate of rotation
float rho = 28.0; // ρ: height of attractor
float beta = 8.0 / 3.0; // β: damping factor
// Initial conditions
float x = 0.1; // Initial X value
float y = 0.0; // Initial Y value
float z = 0.0; // Initial Z value
// Time step
float dt = 0.01; // Time increment for numerical integration
// Interval between data transmissions (milliseconds)
unsigned long transmissionInterval = 1;
unsigned long lastTransmissionTime = 0;
void setup() {
Serial.begin(115200);
while (!Serial)
;
}
void loop() {
// Calculate the derivatives
float dx = sigma * (y - x) * dt;
float dy = (x * (rho - z) - y) * dt;
float dz = (x * y - beta * z) * dt;
// Update the state
x += dx;
y += dy;
z += dz;
// Transmit data at regular intervals
if (millis() - lastTransmissionTime >= transmissionInterval) {
lastTransmissionTime = millis();
Serial.print(x, 6);
Serial.print(",");
Serial.print(y, 6);
Serial.print(",");
Serial.println(z, 6);
}
}
LorenzAttractor.ssproj file.Here’s how your project editor should look:
With Serial Studio's new custom X-axis feature, you can map any dataset to serve as the X-axis source for plots. This is particularly useful for:
For testing without Arduino hardware, a Python script (lorenz_udp.py) is provided that sends Lorenz attractor data via UDP.
Run the Python script:
python3 lorenz_udp.py
In Serial Studio:
LorenzAttractor.ssproj project fileThe script will continuously generate and send Lorenz attractor data to 127.0.0.1:9000.
transmissionInterval in the Arduino sketch is suitable for your system.transmission_interval parameter in the Python script if needed.