HTMAAA Week 9 / Output Devices

I turned my PCB board around because I was using a bunch of headers and I wanted to make sure that I didn’t have to think about turning the orientation of the board around, it was just much harder when you needed to think about flipping everything.

milling

The worst thing happened when I was trying to make it work, the flipped board didnt work, but with the same code, the inverse board worked. I deduced that it must be a hardware issue, so I reached out to the TAs who had helped me late in to the hours of the night, showcasing some debugging techiniques, while also bashing on how I wasn’t doing the due diligence on some of the ways I was treating my board.

debug

It turns out that my pin numbers were wrong, and I was using the wrong pins, so I had to change them to the correct pins. I was using the pin number for digital pins, but it turns out that you needed to use the GPIO pins.

There also was a bunch of red flags including:

  • wiring my power cables so that they were tidy
  • using the correct jumper wires
  • using the correct voltage pass through for my stepper driver
  • using the correct software setup for my code (actually selecting esp32c6)
  • the different pins between esp32c6 and esp32s3
  • my powersupply was kind of dying

I finally got it working with me being able to send out OSC through Touchdesigner and being able to receive it through the ESP32 and move the motors.

The motors and the motor driver became exteremely hot, which was another problem but I hope to manage it through heatsinking.

I also made a small power board for my PCB that would be used to add some 12V DC power to my motor board.

The final code looked like

// #define ARDUINOOSC_DEBUGLOG_ENABLE
#include <ArduinoOSCWiFi.h>
#include "AccelStepper.h"

// for accelstepper
#define dirPin 19
#define stepPin 20
#define motorInterfaceType 1

// Create a new instance of the AccelStepper class:
AccelStepper stepper = AccelStepper(motorInterfaceType, stepPin, dirPin);

const char* ssid = "MLDEV";
const char* pwd = "Aysyw2ch?";

const char* host = "192.168.41.200";
const int recv_port = 54321;
const int bind_port = 54345;
const int send_port = 55555;
const int publish_port = 54445;

// Variable to track if the motor is running
bool isRunning = false;
int motorSpeed = 1000;  // Default speed

void onLeft(const OscMessage& m) {
    Serial.println("Received /left command");
    isRunning = true;
    motorSpeed = abs(motorSpeed);  // Ensure positive speed
    if (isRunning) {
        stepper.setSpeed(-motorSpeed);
    }
}

void onRight(const OscMessage& m) {
    Serial.println("Received /right command");
    isRunning = true;
    motorSpeed = abs(motorSpeed);  // Ensure positive speed
    if (isRunning) {
        stepper.setSpeed(motorSpeed);
    }
}

void onStart(const OscMessage& m) {
    Serial.println("Received /start command");
    isRunning = true;
    stepper.setSpeed(stepper.speed());  // Maintain current direction
}

void onStop(const OscMessage& m) {
    Serial.println("Received /stop command");
    isRunning = false;
    stepper.setSpeed(0);  // Stop the motor by setting speed to zero
}

void onSpeed(const OscMessage& m) {
    int newSpeed = m.arg<int>(0);  // Get the speed from the OSC message
    Serial.print("Received /speed command: ");
    Serial.println(newSpeed);

    motorSpeed = abs(newSpeed);  // Update the motor speed, make sure it's positive
    if (isRunning) {
        // Set speed while maintaining current direction
        stepper.setSpeed(stepper.speed() < 0 ? -motorSpeed : motorSpeed);
    }
}

void setup() {
    Serial.begin(115200);
    delay(2000);

#if defined(ESP_PLATFORM) || defined(ARDUINO_ARCH_RP2040)
#ifdef ESP_PLATFORM
    WiFi.disconnect(true, true);  // disable wifi, erase ap info
#else
    WiFi.disconnect(true);  // disable wifi
#endif
    delay(1000);
    WiFi.mode(WIFI_STA);
#endif

    WiFi.begin(ssid, pwd);

    while (WiFi.status() != WL_CONNECTED) {
        Serial.print(".");
        delay(500);
    }

    Serial.print("WiFi connected, IP = ");
    Serial.println(WiFi.localIP());

    // Subscribe to the OSC addresses for control
    OscWiFi.subscribe(recv_port, "/left", onLeft);
    OscWiFi.subscribe(recv_port, "/right", onRight);
    OscWiFi.subscribe(recv_port, "/start", onStart);
    OscWiFi.subscribe(recv_port, "/stop", onStop);
    OscWiFi.subscribe(recv_port, "/speed", onSpeed);

    // Set the maximum speed in steps per second
    stepper.setMaxSpeed(5000);
}

void loop() {
    // Continuously update OSC messages
    OscWiFi.update();

    // Run the motor at the current speed if running
    if (isRunning) {
        stepper.runSpeed();
    }
}

Group project

We looked into Marcello’s robots and saw that he was using a dual battery pack to power his robots, and we were ablt to look into how much power he was using. It turns out that the power fluctuated when he was idle, only powering one of the motors, and when he was active, he would power both motors.

The power delivery system was really handy because you could see just how much power was being actually pulled, and I always had this thought that power was something that was being delivered, not pulled.

group
Publish on 2024-10-30,Update on 2024-12-11