DIY compact projecters: Difference between revisions

From PD Research Wiki
Jump to navigation Jump to search
 
Line 48: Line 48:


  A0 Projector 1 --pulse interval / master interval
  A0 Projector 1 --pulse interval / master interval
A1
A1 Projector 1 --pulse ON duration / master ON duration
Projector 1 pulse ON duration / master ON
A2 Projector 2 --pulse interval
duration
A3 Projector 2 --pulse ON duration
A2
A4 Projector 3 --pulse interval
Projector 2 pulse interval
A5 Projector 3 --pulse ON duration
A3
 
Projector 2 pulse ON duration
A6(D4) --Linear motor 1 reverse duration
A4
A7(D6) --Linear motor 2 reverse duration
Projector 3 pulse interval
A5
Projector 3 pulse ON duration
A6
(D4)
Linear motor 1 reverse duration
A7
(D6)
Linear motor 2 reverse duration


Remaining pins
Remaining pins
D12 and D13 are free.
D12 and D13 are free.
That means we can use these for two manual enable switches, one for each linear motor. When an enable switch is OFF, the Arduino stops that actuator and suppresses its MIDI events.
 
Maybe for two manual enable switches, one for each linear motor. When an enable switch is OFF, the Arduino stops that actuator and suppresses its MIDI events.
 
Sync behaviour
Sync behaviour
When the sync switch is OFF, each projector's pulsed motor uses its own interval and ON-duration pots.
When the sync switch is OFF, each projector's pulsed motor uses its own interval and ON-duration pots.
When the sync switch is ON, all three pulsed motors use A0 and A1, with their pulse cycles aligned.
When the sync switch is ON, all three pulsed motors use A0 and A1, with their pulse cycles aligned.
The two linear actuators remain independent of pulse synchronization.
The two linear actuators remain independent of pulse synchronization.
This is the pin mapping I recommend proceeding with. It fits on a single Leonardo without expansion boards, and gives you two additional inputs for the actuator enable switches.
One safety detail: a motor enable switch connected to the Arduino is a software control, not a physical emergency stop. A separate motor-power cutoff and travel timeout are still advisable.


===code and softwares===
===code and softwares===

Latest revision as of 14:49, 16 November 2026

DIY compact projectors

Designing a new version of compact and modular projectors that can easily fit into a suitcase.

To establish communication and synchronisation of the images and the sound, I used an Arduino Leonardo with some motor drivers and sensors to control the motor movements as well as sending MIDI signals to sound software. So that my control box, made with DIY electronics and the Arduino Leonard, works as a tangible interface to control the motor movements of my projectors as well as a MIDI instrument to control. the audio effects and notes on and off.


Hardware

Mircocontroller:

Currently using:

Arduino Leonardo,

5v power supply for the linear motor driver

5v power supply for the stepper motor driver

12v linear motor.

5v stepper motor.


Alternative boards (varies on the number of I/O pins):

Pin out:

Digital I/O — 10 pins

DO --Linear motor 1 IN1
D1 --Linear motor 1 IN2
D2 --Linear motor 2 IN1
D3 --Linear motor 2 IN2
D5 --Projector 1 pulsed motor
D9 --Projector 2 pulsed motor
D10 --Projector 3 pulsed motor
D7 --Projector 1 lever switch
D8 --Projector 2 lever switch
D11 --Sync switch

Analog inputs — 8 pins

PinFunction

A0 Projector 1 --pulse interval / master interval
A1 Projector 1 --pulse ON duration / master ON duration
A2 Projector 2 --pulse interval
A3 Projector 2 --pulse ON duration
A4 Projector 3 --pulse interval
A5 Projector 3 --pulse ON duration
A6(D4) --Linear motor 1 reverse duration
A7(D6) --Linear motor 2 reverse duration

Remaining pins

D12 and D13 are free.

Maybe for two manual enable switches, one for each linear motor. When an enable switch is OFF, the Arduino stops that actuator and suppresses its MIDI events.

Sync behaviour

When the sync switch is OFF, each projector's pulsed motor uses its own interval and ON-duration pots.

When the sync switch is ON, all three pulsed motors use A0 and A1, with their pulse cycles aligned.

The two linear actuators remain independent of pulse synchronization.

code and softwares

Arduino code

31 October 2026

#include <MIDIUSB.h>

// =====================================
// PIN DEFINITIONS
// =====================================

// Linear actuator 1
const byte IN1 = 0;
const byte IN2 = 1;
const byte LIMIT1 = 7;
const byte ENABLE1 = 12;
const byte POT_REVERSE1 = A2;

// Linear actuator 2
const byte IN3 = 2;
const byte IN4 = 3;
const byte LIMIT2 = 8;
const byte ENABLE2 = 13;
const byte POT_REVERSE2 = A3;

// Three spinning motors (shared pulse)
const byte SPIN_MOTORS = 5;
const byte POT_SPIN_INTERVAL = A0;
const byte POT_SPIN_DURATION = A1;

// Three XHP50 LED drivers
const byte LED1 = 9;
const byte LED2 = 10;
const byte LED3 = 11;

const byte POT_LED1 = A4;
const byte POT_LED2 = A5;
const byte POT_LED3 = A6;

// =====================================
// SETTINGS
// =====================================

const unsigned long REVERSE_MIN = 200;
const unsigned long REVERSE_MAX = 3000;
const unsigned long PAUSE_TIME = 50;

// Motor states:
// 0 = forward
// 1 = pause before reverse
// 2 = reverse
// 3 = pause before forward

byte state1 = 0;
byte state2 = 0;

unsigned long motorTime1 = 0;
unsigned long motorTime2 = 0;

unsigned long reverseTime1 = 0;
unsigned long reverseTime2 = 0;

// Used to pause and resume the timers
bool wasEnabled1 = false;
bool wasEnabled2 = false;

unsigned long stoppedAt1 = 0;
unsigned long stoppedAt2 = 0;

// Spinning motor timer
unsigned long spinStart = 0;

// =====================================
// MOTOR DIRECTION FUNCTIONS
// =====================================

void forward1() {
  digitalWrite(IN1, HIGH);
  digitalWrite(IN2, LOW);
}

void backward1() {
  digitalWrite(IN1, LOW);
  digitalWrite(IN2, HIGH);
}

void stop1() {
  digitalWrite(IN1, LOW);
  digitalWrite(IN2, LOW);
}

void forward2() {
  digitalWrite(IN3, HIGH);
  digitalWrite(IN4, LOW);
}

void backward2() {
  digitalWrite(IN3, LOW);
  digitalWrite(IN4, HIGH);
}

void stop2() {
  digitalWrite(IN3, LOW);
  digitalWrite(IN4, LOW);
}

// =====================================
// USB MIDI
// =====================================

void sendMidiNote(byte note) {

  midiEventPacket_t noteOn = {
    0x09, 0x90, note, 127
  };

  midiEventPacket_t noteOff = {
    0x08, 0x80, note, 0
  };

  MidiUSB.sendMIDI(noteOn);
  MidiUSB.sendMIDI(noteOff);
  MidiUSB.flush();
}

// =====================================
// LINEAR ACTUATOR 1
// =====================================

void updateMotor1(unsigned long now) {

  bool enabled = digitalRead(ENABLE1) == LOW;

  // Switch OFF: stop and remember time
  if (!enabled) {

    if (wasEnabled1) {
      stoppedAt1 = now;
    }

    stop1();
    wasEnabled1 = false;
    return;
  }

  // Switch ON: resume timer
  if (!wasEnabled1) {

    if (stoppedAt1 != 0) {
      motorTime1 += now - stoppedAt1;
      stoppedAt1 = 0;
    }

    wasEnabled1 = true;
  }

  switch (state1) {

    case 0: // FORWARD

      forward1();

      if (digitalRead(LIMIT1) == LOW) {

        stop1();
        sendMidiNote(60);

        reverseTime1 = map(
          analogRead(POT_REVERSE1),
          0, 1023,
          REVERSE_MIN, REVERSE_MAX
        );

        motorTime1 = now;
        state1 = 1;
      }
      break;

    case 1: // PAUSE BEFORE REVERSE

      if (now - motorTime1 >= PAUSE_TIME) {
        backward1();
        motorTime1 = now;
        state1 = 2;
      }
      break;

    case 2: // REVERSE

      backward1();

      if (now - motorTime1 >= reverseTime1) {
        stop1();
        sendMidiNote(61);

        motorTime1 = now;
        state1 = 3;
      }
      break;

    case 3: // PAUSE BEFORE FORWARD

      if (now - motorTime1 >= PAUSE_TIME) {
        forward1();
        state1 = 0;
      }
      break;
  }
}

// =====================================
// LINEAR ACTUATOR 2
// =====================================

void updateMotor2(unsigned long now) {

  bool enabled = digitalRead(ENABLE2) == LOW;

  // Switch OFF: stop and remember time
  if (!enabled) {

    if (wasEnabled2) {
      stoppedAt2 = now;
    }

    stop2();
    wasEnabled2 = false;
    return;
  }

  // Switch ON: resume timer
  if (!wasEnabled2) {

    if (stoppedAt2 != 0) {
      motorTime2 += now - stoppedAt2;
      stoppedAt2 = 0;
    }

    wasEnabled2 = true;
  }

  switch (state2) {

    case 0: // FORWARD

      forward2();

      if (digitalRead(LIMIT2) == LOW) {

        stop2();
        sendMidiNote(62);

        reverseTime2 = map(
          analogRead(POT_REVERSE2),
          0, 1023,
          REVERSE_MIN, REVERSE_MAX
        );

        motorTime2 = now;
        state2 = 1;
      }
      break;

    case 1: // PAUSE BEFORE REVERSE

      if (now - motorTime2 >= PAUSE_TIME) {
        backward2();
        motorTime2 = now;
        state2 = 2;
      }
      break;

    case 2: // REVERSE

      backward2();

      if (now - motorTime2 >= reverseTime2) {
        stop2();
        sendMidiNote(63);

        motorTime2 = now;
        state2 = 3;
      }
      break;

    case 3: // PAUSE BEFORE FORWARD

      if (now - motorTime2 >= PAUSE_TIME) {
        forward2();
        state2 = 0;
      }
      break;
  }
}

// =====================================
// THREE SPINNING MOTORS
// =====================================

void updateSpinningMotors(unsigned long now) {

 int intervalPot = analogRead(POT_SPIN_INTERVAL);
  int durationPot = analogRead(POT_SPIN_DURATION);

  // Minimum position = OFF
  if (durationPot< 2) {
    digitalWrite(SPIN_MOTORS, LOW);
    spinStart = now;
    return;
  }

  unsigned long interval = map(
    intervalPot,
    0, 1023,
    10, 1200
  );

  unsigned long duration = map(
    durationPot,
    0, 1023,
    2, 600
  );

  duration = min(duration, interval);

  unsigned long phase =
    (now - spinStart) % interval;

  digitalWrite(
    SPIN_MOTORS,
    phase < duration ? HIGH : LOW
  );
  }


// =====================================
// THREE LED BLINK CONTROLS
// =====================================

void updateLED(
  byte ledPin,
  byte potPin,
  unsigned long now
) {

  int pot = analogRead(potPin);

  // Minimum position = OFF
  if (pot < 10) {
    digitalWrite(ledPin, LOW);
    return;
  }

  unsigned long interval = map(
    pot,
    10, 1023,
    100, 10000
  );

  unsigned long phase = now % interval;

  // 50% ON / 50% OFF
  digitalWrite(
    ledPin,
    phase < interval / 2 ? HIGH : LOW
  );
}

// =====================================
// SETUP
// =====================================

void setup() {

  // Linear actuator outputs
  pinMode(IN1, OUTPUT);
  pinMode(IN2, OUTPUT);
  pinMode(IN3, OUTPUT);
  pinMode(IN4, OUTPUT);

  // Lever switches
  pinMode(LIMIT1, INPUT_PULLUP);
  pinMode(LIMIT2, INPUT_PULLUP);

  // Manual ON/OFF switches
  pinMode(ENABLE1, INPUT_PULLUP);
  pinMode(ENABLE2, INPUT_PULLUP);

  // Spinning motors
  pinMode(SPIN_MOTORS, OUTPUT);

  // LED driver PWM inputs
  pinMode(LED1, OUTPUT);
  pinMode(LED2, OUTPUT);
  pinMode(LED3, OUTPUT);

  // Everything initially stopped
  stop1();
  stop2();

  digitalWrite(SPIN_MOTORS, LOW);
  digitalWrite(LED1, LOW);
  digitalWrite(LED2, LOW);
  digitalWrite(LED3, LOW);
}

// =====================================
// MAIN LOOP
// =====================================

void loop() {

  unsigned long now = millis();

  // Independent linear actuators
  updateMotor1(now);
  updateMotor2(now);

  // Shared spinning motor pulse
  updateSpinningMotors(now);

  // Independent LED blinking
  updateLED(LED1, POT_LED1, now);
  updateLED(LED2, POT_LED2, now);
  updateLED(LED3, POT_LED3, now);
}

Turn table arduino code

It seems that the turntable needs to run at a rather fast speed to have a clear image.

So far, the speed is 120 µs between steps.



// 200-step NEMA 17 with EasyDriver
// EasyDriver defaults to 1/8 microstepping
// 1600 STEP pulses per motor revolution
//
// Motor pulley: 60T
// Turntable effective pulley: approximately 314T
// Gear ratio: 314 / 60 = 5.233
//
// Current pulse method:
// STEP HIGH for stepDelay
// STEP LOW  for stepDelay
//
// Theoretical:
// RPM_motor = 18750 / stepDelay
// RPM_table = 3582.8 / stepDelay
//
// Approximate 16 mm lens theoretical neutral:
// table ~9.1 RPM
// motor ~47.6 RPM
// stepDelay ~394 us
//
// Real RPM still needs mechanical calibration.

const int stepPin   = 12;
const int dirPin    = 11;
const int potPin    = A0;

const int switch01  = 2;
const int switch02  = 3;

void setup() {
  pinMode(stepPin, OUTPUT);
  pinMode(dirPin, OUTPUT);

  pinMode(switch01, INPUT_PULLUP);
  pinMode(switch02, INPUT_PULLUP);

  digitalWrite(stepPin, LOW);

  Serial.begin(115200);
}

void loop() {

  // Read the 3-position direction switch
  bool switch1On = (digitalRead(switch01) == LOW);
  bool switch2On = (digitalRead(switch02) == LOW);

  // Read potentiometer
  int potValue = analogRead(potPin);

  // About 1.2 to 17.9 theoretical table RPM
 // int stepDelay = map(potValue, 0, 1023, 3000, 200);
  int stepDelay = map(potValue, 0, 1023, 3000, 120);

  // Theoretical RPM only
  float motorRPM = 18750.0 / stepDelay;
  float tableRPM = 3582.8 / stepDelay;

  bool motorRunning = false;

  // Switch position 1
  if (switch1On && !switch2On) {
    digitalWrite(dirPin, LOW);
    motorRunning = true;
  }

  // Switch position 2
  else if (switch2On && !switch1On) {
    digitalWrite(dirPin, HIGH);
    motorRunning = true;
  }

  // Middle position:
  // both inputs HIGH -> stop
  else {
    motorRunning = false;
  }

  // Generate a step only when one direction is selected
  if (motorRunning) {

    digitalWrite(stepPin, HIGH);
    delayMicroseconds(stepDelay);

    digitalWrite(stepPin, LOW);
    delayMicroseconds(stepDelay);
  }

  // Serial output
  static unsigned long lastPrint = 0;

  if (millis() - lastPrint >= 500) {
    lastPrint = millis();

    Serial.print("Pot: ");
    Serial.print(potValue);

    Serial.print("   Delay: ");
    Serial.print(stepDelay);

    if (!motorRunning) {
      Serial.println(" us   STOP");
    }
    else {
      Serial.print(" us   Motor RPM: ");
      Serial.print(motorRPM, 2);

      Serial.print("   Table RPM: ");
      Serial.print(tableRPM, 2);

      Serial.print("   DIR: ");

      if (switch1On) {
        Serial.println("LOW");
      } else {
        Serial.println("HIGH");
      }
    }
  }
}