1
\$\begingroup\$

enter image description hereI'm attempting to multiplex Neopixel data with weird readings on my Oscilloscope (I'm very novice to Electrical Engineering, so maybe it's a simple fix?). Here's my set up; I have a ring of 16 Neopixels, a rotary encoder, an Arduino Nano, and a 74LVC1G157 multiplexer (single, 2-input MUX). The two data inputs I'm using for the MUX are pins D6 and D5; in which pin D6 displays a continuous rainbow, D5 shows a solid color when someone turns the rotary encoder, and pin D4 will switch that input from D6 to D5 when the rotary encoder is turned, with the output pin on the MUX connected to the Data-In pin on the Neopixel ring. I'm also attaching my code for all of this, although the code is working just fine when I manually connect pins D5 and D6 to the Neopixel's Data In pin and turn the rotary encoder. What I can't understand is why the MUX signal is off by around 480mV, when comparing the signal from D6 and D5 before it passes through the MUX (i.e., the purple line on the oscilloscope) to the signal at the output of the MUX (i.e., the yellow line on the oscilloscope). The purple line on the oscilloscope is a perfect Neopixel signal, and the yellow line also has the correct timing, but not the correct triggering voltage??? Link to the Neopixel Uberguide is here. From the picture of my set-up, I also have a 0.1uF capacitor across 5volt and GND and all the components are being powered by 5volts, which is the only thing I could find when searching for this....I am at a loss, please helpenter image description here enter image description here


#define ENCODER_PIN_A 2       // Quadrature encoder pin A
#define ENCODER_PIN_B 3       // Quadrature encoder pin B
#define MULTIPLEXER_PIN 4     // Pin to control the multiplexer (High/Low)
#define SOLID_COLOR_PIN 5     // Pin to output solid color mode
#define RAINBOW_PIN 6         // Pin to output continuous rainbow mode
#define NUM_LEDS 16           // Number of LEDs in the NeoPixel ring
#define INACTIVITY_TIMEOUT 5000  // 5-second timeout for inactivity

Adafruit_NeoPixel solidRing(NUM_LEDS, SOLID_COLOR_PIN, NEO_GRB + NEO_KHZ800);
Adafruit_NeoPixel rainbowRing(NUM_LEDS, RAINBOW_PIN, NEO_GRB + NEO_KHZ800);

volatile int16_t encoderPosition = 0;
unsigned long lastEncoderMoveTime = 0;
bool encoderMoved = false;

void setup() {
  pinMode(ENCODER_PIN_A, INPUT_PULLUP);
  pinMode(ENCODER_PIN_B, INPUT_PULLUP);
  pinMode(MULTIPLEXER_PIN, OUTPUT);

  Serial.begin(115200);
  Serial.println("Setup complete!");

  attachInterrupt(digitalPinToInterrupt(ENCODER_PIN_A), readEncoder, CHANGE);
  attachInterrupt(digitalPinToInterrupt(ENCODER_PIN_B), readEncoder, CHANGE);

  solidRing.begin();
  rainbowRing.begin();
  solidRing.setBrightness(80);
  rainbowRing.setBrightness(80);
  solidRing.show();  // Initialize all LEDs to off
  rainbowRing.show();  // Initialize all LEDs to off
}

void loop() {
  unsigned long currentTime = millis();

  if (encoderMoved) {
    encoderMoved = false;
    lastEncoderMoveTime = currentTime;

    // Drive the multiplexer pin high for solid color mode
    digitalWrite(MULTIPLEXER_PIN, HIGH);

    // Handle counter logic
    if (encoderPosition > 255) encoderPosition = 1;
    if (encoderPosition < 0) encoderPosition = 0;

    if (encoderPosition == 0) {
      solidRing.clear();
    } else {
      uint32_t color = Wheel(encoderPosition & 255);
      for (int i = 0; i < NUM_LEDS; i++) {
        solidRing.setPixelColor(i, color);
      }
      solidRing.show();
    }

    Serial.print("Encoder Position: ");
    Serial.print(encoderPosition);
    Serial.println(" | Solid Color Mode Active");
  } 
  else if (currentTime - lastEncoderMoveTime > INACTIVITY_TIMEOUT) {
    digitalWrite(MULTIPLEXER_PIN, LOW);
    displayRainbowEffect();
    delay(100);  // Delay to ensure smooth transition and prevent rapid switching
  }
}

void displayRainbowEffect() {
  for (int i = 0; i < NUM_LEDS; i++) {
    rainbowRing.setPixelColor(i, Wheel((i + millis() / 10) & 255));
  }
  rainbowRing.show();
  Serial.println("Displaying Rainbow Effect...");
}

void readEncoder() {
  int MSB = digitalRead(ENCODER_PIN_A);
  int LSB = digitalRead(ENCODER_PIN_B);
  int encoded = (MSB << 1) | LSB;
  static int lastEncoded = 0;
  int sum = (lastEncoded << 2) | encoded;

  if (sum == 0b1101 || sum == 0b0100 || sum == 0b0010 || sum == 0b1011) encoderPosition++;
  if (sum == 0b1110 || sum == 0b0111 || sum == 0b0001 || sum == 0b1000) encoderPosition--;

  lastEncoded = encoded;
  encoderMoved = true;
}

uint32_t Wheel(uint8_t WheelPos) {
  WheelPos = 255 - WheelPos;
  if (WheelPos < 85) {
    return solidRing.Color(WheelPos * 3, 255 - WheelPos * 3, 0);
  } else if (WheelPos < 170) {
    WheelPos -= 85;
    return solidRing.Color(255 - WheelPos * 3, 0, WheelPos * 3);
  } else {
    WheelPos -= 170;
    return solidRing.Color(0, WheelPos * 3, 255 - WheelPos * 3);
  }
}
\$\endgroup\$
3
  • 1
    \$\begingroup\$ Draw a schematic please. \$\endgroup\$ Commented Feb 17 at 9:08
  • \$\begingroup\$ Try swapping the scope probes. \$\endgroup\$ Commented Feb 17 at 13:42
  • \$\begingroup\$ I swapped the scope probes...but it didn't do anything except change the colors lol. However, I also added a schematic. \$\endgroup\$ Commented Feb 17 at 22:56

1 Answer 1

3
\$\begingroup\$

It looks like you have some wiring or power supply error around your 74LVC1G157, or the 74LVC1G157 is already dead/burned occasionally. Recheck everything thoroughly, the setup you described should show either rainbow or solid color, even if your D4 control logic with encoder in the code is wrong. Also you can try to disconnect the MUX's S input (pin 6) from Arduino's D4 and connect it manually to GND (making logic 0) and then to +5V (making logic 1) to verify if the MUX works at all.

\$\endgroup\$
3
  • 1
    \$\begingroup\$ So you were right that the MUX was dead or something. I switched it out for one that was working, but the reason why I thought that this wasn't the case is because it was the 4th one that I tried. So I guess for anyone viewing this in the future, be careful about Nexperia 74LVC1G157 MUXs. \$\endgroup\$ Commented Feb 18 at 2:17
  • \$\begingroup\$ You could perform the same operation in code and not need the external mux. Why should we be careful of nexperia chips? It seems like something you are doing is killing them.p0 \$\endgroup\$ Commented Feb 18 at 14:34
  • \$\begingroup\$ Their footprint is super tiny (TSSOP), so maybe my soldering iron fried them? In any case, how could I perform the same operation in code? \$\endgroup\$ Commented Feb 18 at 17:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.