Here is one of my more complex projects.

(Marlon Graeber) #1

Here is one of my more complex projects.
Its a so called RGB Flowerstick / Devilstick wich uses a Teensy 3.2 and very small WS2812B MINI 3535( on a 144 LED / meter) strip
it can load simple bitmaps from a microSD card to project them by rotating. Similar to a POV Display (Persistence of Vision).
To avoid a gymbal lock I did the maths with quaternions… ( took damn long to understand… weeks of confusion and pure desperation!!! )
The rotation is measured by a gyroscope (MPU 6050 Module)
To supply some power, I took two LiPOs wich are used in quadrocopters and a simple step up converter.
I added a few simple animations wich are not influenced by rotating speed.

(Yves BAZIN) #2

@Marlon_Graeber where did you buy those leds?

(Marc Miller) #3

That’s a very cool project. Thanks for sharing.

(Ken White) #4

@Marlon_Graeber - Great project. Now if only I could do something similar to a pair of nunchucks.

(Ashley M. Kirchner [Norym]) #5

Similar to my POV poi sticks ( But you took it to a whole different level with the gyro. Awesome work. At some point I was going to try to do that as well but stopped when my brain realized that the stick will be rotating around its own axis as well, and the performer is also changing the axis of rotation … and my brain exploded. I stopped.

(Marlon Graeber) #6


I used these … I needed them as small as possible to fit them in a tube wich still can be rotated in my hand easily :slight_smile:

(Marlon Graeber) #7

@Ashley_M_Kirchner_No @Ken_White
I can remember the struggle. this was by far the hardest task in the whole project… i watched youtube videos tutorials and everything related to quaternions just to get an idea what this is. Weeks of starring apathetic into my laptop… pure desperation!
Maybe it could help you if i lead you through my problems and solutions throughout the development process.
At first I used Euler angles to get the angle around the vertical axis (the gravity axis or vector). The math would be easy if the rotation would be around one axis. You could use Euler angles and that’s it. But I had to find out (via serial output of the main rotation angle) that while I do a full rotation with the stick, the equation with the Euler angles is just within the first and the third quarter of the rotation correct. To find that out I made a 3D model of the stick in processing and send the X/Y/Z data to the 3D model. On a certain point the model flipped upside down instantly.
That was caused by something called gymbal lock. That is a problem, when using euler angles to describe an object moving around more than one axis.
When you take a look at the picture that I had been drawing you see the Z axis. While rotating the stick, the Z axis is moving towards the x axis and back (in other words: rotating +/- 180 degrees around the y axis) . This rolling back and forth is caused by the way hold the stick while playing.
So I had to find another solution. Finding the name of the method to avoid this problem was relatively easy. It’s called Quaternion. The matter of quaternions is absolutely NOT.
At least for me (not been to a university & learning higher mathematics in a foreign language)
But I’ll try to explain it to you as good as I can 
A quaternion contains information how a vector ( in our case the axis of the stick) changed in 3D space. It’s just a bunch of instructions.
So when you get frequently quaternions from a gyroscope they can tell you how the position of the gyro changed. A change is always relative to something. So we need a vector to start with. And because we are just interested in the angle between two vectors, we can ignore the length.
Imagine drawing the letter “V” from two lines… the angle between these lines will not change when you’re making the lines longer.
We just need to begin with a vector that is rotating horizontally but not influenced by the back and forth movement around the Y axis. And that is possible!
We need to know two things (mathematical operations) to work with vectors
The vector dot product : To calculate the angle between two vectors
The vector cross product: To create a new vector that is perpendicular to the both input vectors. Imagine drawing the letter “V” in 3D space. Now imagine a sheet it would be written on. When you’re a fly landing on that sheet, the new Vector would go upright like a pole.
Let’s go back to the gyroscope and use the “cross product” to create an awesome vector that can only rotate on horizontal plane.
The gyroscope gives us the opportunity to obtain the gravity vector!
And with this vector and the vector of the Y-Axis, wich is (X 0 /Y 1 /Z 0), we can create a plane and on this plane, a new cross product vector. That vector is always 90 degrees to the gravity vector ( for us as outside observers “horizontal”) . Let’s call this new vector “vStart” .
As we rotating the stick the next incoming quaternion (let’s call the quaternion package “deltaQ”) tells us as outside observers where vStart is now.
With vStart and the quaternion instructions we can create a new vector (named “vNow” )
And in the last step we got to find out the angle between vStart and VNow and this is the rotation angle on our (outside observers) horizontal plane, no matter how we rotate the stick on other axis.

Here is my favorite webpage for cross and dot product:
I recommend a quick search for cross and dot product so you get to know the math behind it.
I will attach a link to the code soon. But now I hope you can follow my steps in the code
Here is a library that I used to communicate with the gyro and also doing the math’s with vectors and quaternions: MPU6050_6Axis_MotionApps20.h (Great library by the way)

Here is the link:

I hope I didn’t made millions of spelling errors. But if I did sorry! :smiley:

missing/deleted image from Google+

(Ashley M. Kirchner [Norym]) #8

Thank you, there’s smoke coming out of my ears now … good thing I keep a fire extinguisher in my office.

(Tommy Sciano) #9

@Marlon_Graeber great writeup and post. love it. Are these leds smaller than the apa102-2020?

I’d love to check out the code. My friend was just asking me to build one of these, but I thought that it would be difficult to make the center piece with LEDS.

Do you have a write-up or pictures of the construction? I was meaning to make one of these for my friend. she likes playing with these, and goes to a few meetups for them to learn.