Issue trying to use NeoPixel Stick

Thanks for the info!

So im setting the frequency like this:

analogWriteFrequency(MOTOR_PWM_PIN, 20000);
analogWriteFrequency(MOTOR_DIR_PIN, 20000);

MOTOR_PWM_PIN = 9
MOTOR_DIR_PIN = 2

Will this change the pwm frequency to 20khz on those two pins?

Isn’t the DIR pin just a digital high or low? Not sure why you would want to set the frequency on that…

For pin 9 (Free3) calling anlogWriteFrequency() will affect TIM2, which is used for PWM on Free1, Free2, Free3 (and the status LED.)
For pin 2 (data2), calling analogWriteFrequency() will affect TIM1, which is normally used for WS2811 protocol generation. If you do that you can’t use neopixels anymore.

Im using a DRV8256P motor driver that has IN/IN interface which requires both pins to have pwm enabled. Do you think analogWrite would work? Or is it best to stick with LSanalogWrite?

I would recommend LSanalogWrite, but it will require a little coding to support 20kHz.
You can try it with analogWrite, just remember that you might get some glitching if you do it that way, should be fine for some basic testing though.

If at all possible, try using two of the Free* pins for this as that will not interfere with other timers.

I looked up the spec for this, and it also has a PH/EN interface which seems much easier to use. One digital line for direction and one PWM for the speed.

The IN1/IN2 interface seems to give direct control of the two outputs, but I’m not sure why anybody would want that.

Also, why 20kHz ? The chip says it supports 0 to 100kHz.

the DRV8256E has PH/EN Interface, but i am using the DRV8256P, with the DRV8256P i can introduce “braking” for instant stopping instead of coasting to a stop. So thats why i need both pins to have pwm

Funky, but ok.
I highly recommend the Free* pins for this.

Believe me, it’s weird to program as well lol. Im kinda stuck using data 2 for one of the pins unless i want to resolder some wires. I have free 3 and data 2. I see on the proffie mapping chart that data 2 has pwm when there are no pixels. What does that mean? When there are no pixel connected to the pin?

Edit: The motor direction is not working correctly. Here is the code im testing in the setup function

// Motor Setup
  pinMode(MOTOR_IN_1, OUTPUT);
  pinMode(MOTOR_IN_2, OUTPUT);
  pinMode(MOTOR_SLEEP_PIN, OUTPUT);
  digitalWrite(MOTOR_SLEEP_PIN, HIGH);  // Enable motor driver

  LSanalogWriteSetup(MOTOR_IN_1);
  LSanalogWriteSetup(MOTOR_IN_2);
  delay(1000);
 
  startMotor(true);
  delay(3000);
  startMotor(false);
  LSanalogWrite(MOTOR_IN_1, 0);
  LSanalogWrite(MOTOR_IN_2, 0);

and here is the startMotor function

void startMotor(bool direction) {
    if (direction) {
        LSanalogWrite(MOTOR_IN_1, slowDownPwm); // PWM to IN1
        LSanalogWrite(MOTOR_IN_2, 0);     // IN2 must be explicitly LOW
        Serial.println("running motor forward...");
    } else {
        LSanalogWrite(MOTOR_IN_1, 0); // PWM to IN1
        LSanalogWrite(MOTOR_IN_2, slowDownPwm);  // PWM to IN2
        Serial.println("running motor backward...");
    }
    motor_running = true;
}

when the program runs, the motor only turn one way then stops. However, if i was to test the startMotor with only one reference in the setup, it runs in both directions, meaning, if setup only has startMotor(true); or startMotor(false); it will run in that direction. But if i try to call the startMotor function multiple times it will not change directions, could this be an issue with the Proffie board and pwm?

No, when there are no pixels on ANY pin.

I don’t know what would cause that.
what is the value of slowDownPwm ?

Any pin?!? oh wow, ok that wont work then, i plan on having a battery indicator using the neo pixel strip, so ill try to free up Free 1 and work with that. Thanks for the info!

Its working now, i had to switch from using data 2 to free 1. So you were right, even though i had no pixels hooked up at all, data 2 pin was still not good for the pwm signal. the free pads as the way to go!

@profezzorn another question in regards to data 1 pin, can i use that one to control a mosfet module, this one in particular?

I currently have it connected to free 2 and it works fine however i need to use free 2 for the motor encode wire. Is data 1 ok to use to control the module? I see it says is resistored.

Yes, but why?
Do you need more than 6 FETs?

Note that if you need to PWM the FET, you’re back to having no neopixels again.

no, I need more Free pins, all the free pins are used up for the motor driver and encoder. I just need another pin for the mosfet module which controls my 12v LED cob strip. I tried hooking it up to the data 1 pin, but as soon as i turn on the board, the led on the mosfet module lights up dimly. I set data 1 to OUTPUT and LOW. Im controlling the LED strip on my own so i will not be using the proffie for lighting effects. I mainly want the proffie for the sound effects and and motion effects.

You don’t need a mosfet module to drive a 12v LED cob strip, just hook it up to one of the LED pads.

I need to trigger the mosfet module to turn the cob strip on and off, the mosfet is fed by a step up converter which provides a stable 12v. My strip only has two wires, pos and neg, so how would you control the strip through the LED pin alone? Aren’t the LED pins meant for a data line?

What i have right now is the trigger wire of the mosfet module connected to the LED 3 (22) pin. Currently this is not working:

//setup code
pinMode(MOSFET_CONTROL_PIN, OUTPUT);
digitalWrite(MOSFET_CONTROL_PIN, LOW);

Then later in the code im setting it high like this:

digitalWrite(MOSFET_CONTROL_PIN, HIGH);

When the pin is HIGH its reading 1.5v, i need at least 3.3v to turn on the module.

Do the LED pins work differently? If so, i have no more free pins left, so what could i use to control the module?

LED1-6 are meant to drive the negative side of a LED.
(I’m not sure where the confusion comes from here, LED* is for power, data* is for data…)
They have fairly powerful FETs already on them.
Normally we use these to drive things that run on battery voltage, but then can definitely handle 12v. (In most cases they can handle up to 30v, but it depends on what actual FETs the manufacturer used, so you would need to read the symbols on your FETs and find the datasheet to find the actual limit.)

To wire it up, you hook up the + of your (COB) led to 12v, and the negative to one of LED1/2/3/4/5/6, then you configure it with SimpleBlade and it should just work.[1]

[1] There is one assumption here, which is that the ground is the same for your 12v circuits and your 4.2 volt circuits, which is normally the case. If not, they would just need to be connected together to make that the case.

Thanks for clarifying! That would make my setup a bit less complex. One thing I’m doing currently is, i wrote a function to flicker the cob strip by setting the MOSFET module HIGH and LOW randomly. Since I’m a NOOB in the proffie world, can i assume the SimpleBlade method could handle this type of effect? If so, could please provide an example of this or point me to the documentation for it?
Thanks again!

There are several ways, depending on how much flicker you want.
Maybe:

StyleNormalPtr<AudioFlicker<White,White>,White,300,800>()

or

StyleNormalPtr<RandomFlicker<White, Black>, White, 300, 800>()

This looks promising. And this will work with a strip that just has power and gnd?
I wrote this function that runs when the saber is on

void bladeFlicker() {
    unsigned long currentMillis = millis();
    if (currentMillis - lastFlickerTime >= flickerInterval) {
        lastFlickerTime = currentMillis; // Reset flicker timer
        flickerInterval = random(3, 10); // Randomize next flicker interval

        // Toggle blade flicker
        if (isFlickerOn) {
            digitalWrite(MOSFET_CONTROL_PIN, LOW); // Turn off blade
            isFlickerOn = false;
        } else {
            digitalWrite(MOSFET_CONTROL_PIN, HIGH); // Turn on blade
            isFlickerOn = true;
        }
    }
}

so this would be added to the presets[]

StyleNormalPtr<AudioFlicker<White,White>,White,300,800>()

what should i add in the BladeConfig blades[]?

Apologies for not knowing much about these boards.

Yes. ProffieOS will set up a PWM counter @ 813 Hz to drive the fet, and it will repeatedly ask the style (which is the example in the previous post) to decide the PWM level.

The styles I posted might not look the same, but we have a number of random functions to choose from, so hopefully something with strike your fancy.

correct

SimpleBladePtr<CreeXPE2WhiteTemplate<10000>, NoLED, NoLED, NoLED, bladePowerPin1, -1, -1, -1>()

(replace bladePowerPin1 with whatever LED* pins you hook up the COB to.)

More information about SimpleBladePtr:

No worries, I’m just trying to save you some work. :slight_smile: