• AI Experimentation

    Krockwell07/26/2025 at 02:56 0 comments

    I've been playing around with a AI tools lately.

    AI use-case #1: CAD using OpenSCAD (Google Gemini Pro 2.5)

    This technique uses OpenSCAD (thanks to Richard my coworker for introducing me to this tool). I put a single prompt into Gemini Canvas and had a 3D model of a basic egg shape in seconds. The image below is the first iteration of an empty egg shape with ~5in diameter. The first attempt looks more like a pear or avocado than an egg but it has the M3 hardware placement and platform for the Nema-17 motor. Time to print this and see how it turns out!

    AI use-case #2: Programming Arduino (Goose, Gemini Pro 2.5)

    I also installed block/goose and played around with some auto-generated arduino code using Google Gemini model 2.5 pro. This setup is a lot of fun as you get to command an AI agent directly in the console to do things for you. It created the code copied below.

    #include <Wire.h>
    #include <AccelStepper.h>
    #include <Adafruit_BMA400.h>
    
    // --- Configuration Constants (TUNE THESE!) ---
    
    // Define stepper motor connections
    #define DIR_PIN 2
    #define STEP_PIN 3
    #define ENABLE_PIN 4
    
    // The number of steps your motor takes for one full revolution.
    // Common values are 200 or 400.
    #define MOTOR_STEPS_PER_REV 200
    
    // The microstepping setting on your DRV8825 driver. 1 is full step, 16 is common.
    #define MICROSTEPS 8
    
    // Calculated total steps per revolution
    const int STEPS_PER_REV = MOTOR_STEPS_PER_REV * MICROSTEPS;
    
    // Motor speed and acceleration. These are critical for tuning.
    // Start slow and increase until you get good movement.
    #define MAX_SPEED 1500.0   // Steps per second
    #define ACCELERATION 3000.0 // Steps per second^2
    
    // Accelerometer sensitivity threshold.
    // This determines how much tilt is needed to trigger the motor "kick".
    // You will need to find the right value by watching the Serial Monitor.
    #define TILT_THRESHOLD_X 2.5 // m/s^2
    
    // --- Global Objects ---
    
    // Initialize the stepper library
    // The first argument is the interface type (1 = Driver: STEP/DIR pins)
    AccelStepper stepper = AccelStepper(AccelStepper::DRIVER, STEP_PIN, DIR_PIN);
    
    // Initialize the accelerometer
    Adafruit_BMA400 bma = Adafruit_BMA400();
    
    void setup() {
      Serial.begin(115200);
      while (!Serial) {
        delay(10); // Wait for serial connection
      }
      Serial.println("Wobble Egg Initializing...");
    
      // --- Initialize Accelerometer ---
      if (!bma.begin()) {
        Serial.println("Could not find a valid BMA400 sensor, check wiring!");
        while (1);
      }
      Serial.println("BMA400 Found!");
      bma.setRange(BMA400_RANGE_4G);
      bma.setDataRate(BMA400_DATA_RATE_100_HZ);
    
      // --- Initialize Stepper Motor ---
      pinMode(ENABLE_PIN, OUTPUT);
      digitalWrite(ENABLE_PIN, LOW); // Pull low to enable the DRV8825
    
      stepper.setMaxSpeed(MAX_SPEED);
      stepper.setAcceleration(ACCELERATION);
    
      // Set the motor to be "at rest" pointing straight down initially.
      // You may need to manually position the weight down the first time.
      stepper.setCurrentPosition(0);
    
      Serial.println("Initialization complete. Starting main loop.");
    }
    
    void loop() {
      // --- 1. SENSE: Read the accelerometer ---
      sensors_event_t accel;
      bma.getEvent(&accel);
    
      // Print the X-axis acceleration for tuning purposes.
      // Orient your egg so the X-axis points in the forward/backward direction.
      Serial.print("Accel X: ");
      Serial.println(accel.acceleration.x);
    
      // --- 2. DECIDE: Check if we need to "kick" ---
    
      // The logic: if the egg has tilted backward past our threshold,
      // it's time to propel it forward.
      if (accel.acceleration.x < -TILT_THRESHOLD_X) {
        Serial.println("Backward tilt detected! Kicking forward.");
    
        // We command the motor to spin one full revolution.
        // The AccelStepper library is non-blocking, so we set a target
        // and let run() handle the movement.
        // The direction of the "kick" depends on motor wiring.
        // If it moves the wrong way, change this to `-STEPS_PER_REV`.
        stepper.move(STEPS_PER_REV);
      }
    
      // --- 3. ACT: Run the motor ---
    
      // This function must be called as often as possible....
    Read more »

  • Motor Fun

    Krockwell03/31/2024 at 01:09 0 comments

    The motor drive circuit is working! Here's a snapshot of the setup. I can easily control the speed using the arduino sketch. The DRV8825 gets very hot during operation so I'll need to make sure I am heatsinking that properly. 

    I also created a small lever arm for the motor and installed it in the egg with some weights (quarters). The egg did wobble when I ran the motor which is a good sign but I need to make some adjustments to improve it:

    • Decrease weight and thickness of egg vessel. I'd like to go down to 3mm for the walls. 
    • Eliminate the threads of the egg vessel and move to fasteners to reduce weight.
    • Decrease motor weight or increase weight on the lever. I need to do some more research here to figure this part out. The nema-17 motor is pretty heavy and makes it difficult to shift the center of gravity of the egg without a massive counter weight.

    Next Steps: 

    • Improve 3D printed egg
    • Add boost converter to breadboard so I can power everything with a single voltage supply (4.7V).

  • Breadboarding

    Krockwell03/24/2024 at 04:38 0 comments

    Round 2 of the egg is currently printing. I've got the schematics in KiCad started and I am starting to breadboard the electronics. I am still waiting on various parts to arrive from Mouser but I should have a working demo of the stepper motor by the end of the week. Below are some progress shots.

    Here is the breadboard setup. I'm waiting on a power supply I ordered on Ebay before I can fire up the stepper motor. Here I am using the DRV8825 breakout by Pololu to test out the motor driver chip. 

    I continue to learn with each new 3D print. The threads need some work as they get damaged easily when threading the two halves together. The 20% in-fill is likely not helping. The side walls are still too thick at 7mm so I'll decrease by half again.

  • First egg print!

    Krockwell03/16/2024 at 19:00 0 comments

    The first full size egg finished printing after 40 hours. This was a fun first attempt and my son loves to kick it around the house. I ordered some rainbow colored filament for the next attempt.

    Things to change:

    • Decrease wall thickness to no more than 7mm
    • Increase diameter of threaded region to at least 5mm
    • Increase the weight of the bottom half to help shift the center of gravity. The egg topples over easily.
    • Increase the internal dimensions to better fit electronics.

    New features for next iteration:

    • Add an internal platform to hold the circuit board and motor. This platform should be skeletonized to reduce weight as I want most of the weigh to be near the bottom of the egg.

  • Development boards and wobbling madness!

    Krockwell03/16/2024 at 02:33 0 comments

    I started writing some programs to control the DRV8825 using a few small embedded boards I had lying around - the Metro by Adafruit and Arduino Uno both of which are based on the ATMEGA328P processor.  I went with these because I wanted something simple, low cost, and low power.

    Getting started on the Arduino IDE was effortless. I also found an awesome tutorial showing how to map an existing stepper motor Arduino library to the DRV8825. Within minutes I've got a working example driving the LED (instead of the DRV8825 STEP pin) on my demo board. Pretty neat!

    Checkout this guide! 

    https://www.makerguides.com/drv8825-stepper-motor-driver-arduino-tutorial/

    Also, here's a fun video for some wobble inspiration:

  • Block Diagram

    Krockwell03/15/2024 at 02:30 0 comments

    The system block diagram is relatively simple. The egg moves using a stepper motor and there is a microcontroller and motor controller used to generate the PWM signals for the stepper. A USB interface allows for re-programming of the microcontroller.

  • Egg #1

    Krockwell03/14/2024 at 05:05 0 comments

    I used this great tutorial to make a threaded egg in Fusion360. I made mine about 5 inches around with an egg-shaped volume inside rather than the cylindrical volume in the video. The 50% scaled test print turned out great and looks like an egg.

  • What is an egg?

    Krockwell03/12/2024 at 03:54 0 comments

    Starting project by learning more about eggs..

    I'd like to figure out how to create a nice 3D printed egg shape that can hold a circuit board, battery, and motor assembly. I'll start by printing off some free variants from thingiverse. Ultimately I want the egg to be quite large and at least 6 inches tall.

    I also need to understand how to use a motor to cause the egg to spin and wobble. The first thought is a motor with off-center weight much like how cell phones vibrate. However this may not create an actual wobble motion. It would be useful if I could shift the center of gravity of the egg using the motor.

    Features I'd like:

    1. Ability to charge with a port like USB

    2. Ability to re-program the motion. This will drive need for microcontroller

    3. Ability to play with egg for atleast 1 hour

    4. Ability to take the egg apart by unscrewing the halves

    5. Total cost under $50 (circuit board, battery, motor, egg vessel)

    Initial components considered:

    1. ATMega328P - simple 8 bit microcontroller that could handle PWM outputs. Low power at 2.4mA@3V

    2. DRV8833 - simple stepper motor controller

    3. NEMA-17 (or similar) small stepper. Power draw is roughly 5W / phase (600mA max current, 7 ohm per winding) The stepper's holding torque will be useful if the egg stops moving and stays in one position. Some more calculation needed to understand if there is enough torque.

    Next Steps:

    1. 3D print a representative egg. Once I have a decent shape I can tape weights to it to understand how moving weight around the egg can change the center of gravity to cause it to wobble. I can use this to back out torque requirements for motor selection.

    2. Pick components and breadboard stepper driver circuit

    3. Design circuit board and refine egg CAD.

    4. Put it all together!