8bitsandabyte
Published © CC BY-NC-SA

The Mesmerizer

A project that's nice to look at, nothing more, nothing less.

BeginnerFull instructions provided15 hours760
The Mesmerizer

Things used in this project

Hardware components

Raspberry Pi 4 Model B
Raspberry Pi 4 Model B
×1
Adafruit Servo Driver - PCA9685
×1
MG90S digital servo
×4

Software apps and online services

Raspbian
Raspberry Pi Raspbian

Hand tools and fabrication machines

3D Printer (generic)
3D Printer (generic)

Story

Read more

Custom parts and enclosures

Arrow

Bottom Plate

Servo Plate

Side Plate

Code

mesmiCode.py

Python
# imports
import board
from board import SCL, SDA
import busio
import adafruit_pca9685
from adafruit_motor import servo
import time
import random

# Setup the servo driver an initiale the connected servos
i2c = busio.I2C(SCL, SDA)
pca = adafruit_pca9685.PCA9685(i2c)
pca.frequency = 50

servos = []

servo0 = servo.Servo(pca.channels[0])
servo1 = servo.Servo(pca.channels[1])
servo2 = servo.Servo(pca.channels[2])
servo3 = servo.Servo(pca.channels[3])

# Add each servo to our list of servos
servos.append(servo0)
servos.append(servo1)
servos.append(servo2)
servos.append(servo3)

# Loop over this list and set the starting position
for servo in servos:
    servo.angle = 45

# A variable to set speed of servo movements
steps = 5

while True:

    # For eternity keep looping over the servos
    for servo in servos:

        # Based on chance and their current position move either left or right.
        if random.randint(0,1) == 0:
            if servo.angle < steps:
                servo.angle += steps
            else:
                servo.angle -= steps
        else:
            if servo.angle > (180-steps):
                servo.angle -= steps
            else:
                servo.angle += steps

    time.sleep(0.15)

Credits

8bitsandabyte

8bitsandabyte

65 projects • 48 followers
We’re Dane & Nicole, two makers that create tremendously terrible tech, which we happily share with you!

Comments