Double multiplexer clock

Hwello, I hope everyone is having a wonderful holiday. I am trying to create a clock using four 7-segment displays connected to two 16-channel Arduino multiplexers. I have used one multiplexer to control the top and another to control the bottom of the displays. When I run the code separately through each multiplexer, all their respective LEDs light up, but when I try to run both multiplexers simultaneously, it does not work. I think it either has something to do with the multiplexers conflicting or the code. Because when I connect to a jumper cable from the power and touch the pins on the multiplexers, the LEDs work. The codes are:
multiplexer 1-

// Define multiplexer control pins
const int S0 = 8;
const int S1 = 9;
const int S2 = 10;
const int S3 = 11;
const int SIG = 12; // Signal pin to control LEDs

// Variable to hold the binary code for the number to display
byte binaryCode = 0b11111111; // Example: binary code for "0"

void setup() {
  // Set multiplexer control pins as outputs
  pinMode(S0, OUTPUT);
  pinMode(S1, OUTPUT);
  pinMode(S2, OUTPUT);
  pinMode(S3, OUTPUT);

  // Set SIG pin as output
  pinMode(SIG, OUTPUT);
}

void loop() {
  // Continuously display the binary code on all channels
  for (int channel = 0; channel < 15; channel++) { // Loop through all 16 channels
    selectMultiplexerChannel(channel);              // Select the appropriate channel
    digitalWrite(SIG, bitRead(binaryCode, channel % 8)); // Send the appropriate binary signal
  }
}

// Function to select a channel on the multiplexer
void selectMultiplexerChannel(int channel) {
  digitalWrite(S0, bitRead(channel, 0)); // Set S0 based on bit 0 of the channel
  digitalWrite(S1, bitRead(channel, 1)); // Set S1 based on bit 1 of the channel
  digitalWrite(S2, bitRead(channel, 2)); // Set S2 based on bit 2 of the channel
  digitalWrite(S3, bitRead(channel, 3)); // Set S3 based on bit 3 of the channel
}

multiplexer 2-

// Define multiplexer control pins
const int S0 = 7;
const int S1 = 6;
const int S2 = 5;
const int S3 = 4;
const int SIG = 3; // Signal pin to control LEDs

// Variable to hold the binary code for the number to display
byte binaryCode = 0b11111111; // Example: binary code for "0"

void setup() {
  // Set multiplexer control pins as outputs
  pinMode(S0, OUTPUT);
  pinMode(S1, OUTPUT);
  pinMode(S2, OUTPUT);
  pinMode(S3, OUTPUT);

  // Set SIG pin as output
  pinMode(SIG, OUTPUT);
}

void loop() {
  // Continuously display the binary code on all channels
  for (int channel = 0; channel < 15; channel++) { // Loop through all 16 channels
    selectMultiplexerChannel(channel);              // Select the appropriate channel
    digitalWrite(SIG, bitRead(binaryCode, channel % 8)); // Send the appropriate binary signal
  }
}

// Function to select a channel on the multiplexer
void selectMultiplexerChannel(int channel) {
  digitalWrite(S0, bitRead(channel, 0)); // Set S0 based on bit 0 of the channel
  digitalWrite(S1, bitRead(channel, 1)); // Set S1 based on bit 1 of the channel
  digitalWrite(S2, bitRead(channel, 2)); // Set S2 based on bit 2 of the channel
  digitalWrite(S3, bitRead(channel, 3)); // Set S3 based on bit 3 of the channel
}

Multiplexer 1 + 2-

// Define multiplexer 1 control pins
const int S0_1 = 7;
const int S1_1 = 6;
const int S2_1 = 5;
const int S3_1 = 4;
const int SIG_1 = 3; // Signal pin to control LEDs for multiplexer 1

// Define multiplexer 2 control pins
const int S0_2 = 8;
const int S1_2 = 9;
const int S2_2 = 10;
const int S3_2 = 11;
const int SIG_2 = 12; // Signal pin to control LEDs for multiplexer 2

// Variable to hold the binary code for the number to display
byte binaryCode = 0b11111111; // Example: binary code for "0"

// Define which channels to activate (can be 0-7 for multiplexer 1, 0-7 for multiplexer 2)
int channel1 = 0; // Example: Channel 0 for multiplexer 1
int channel2 = 8; // Example: Channel 8 for multiplexer 2

void setup() {
  // Set multiplexer 1 control pins as outputs
  pinMode(S0_1, OUTPUT);
  pinMode(S1_1, OUTPUT);
  pinMode(S2_1, OUTPUT);
  pinMode(S3_1, OUTPUT);
  pinMode(SIG_1, OUTPUT);

  // Set multiplexer 2 control pins as outputs
  pinMode(S0_2, OUTPUT);
  pinMode(S1_2, OUTPUT);
  pinMode(S2_2, OUTPUT);
  pinMode(S3_2, OUTPUT);
  pinMode(SIG_2, OUTPUT);
}

void loop() {
  // Manually turn on channel 0 of multiplexer 1
  selectMultiplexerChannel(channel1, 1);
  digitalWrite(SIG_1, bitRead(binaryCode, channel1)); // Send the appropriate binary signal for channel1
  delay(10); // Wait for 1 second

  // Manually turn off channel 0 of multiplexer 1 (optional, if you want to turn it off before switching)
  digitalWrite(SIG_1, LOW);
  delay(50); // Wait for 500 ms

  // Manually turn on channel 8 of multiplexer 2
  selectMultiplexerChannel(channel2 - 8, 2); // Adjust channel number for multiplexer 2 (0-7)
  digitalWrite(SIG_2, bitRead(binaryCode, channel2)); // Send the appropriate binary signal for channel2
  delay(10); // Wait for 1 second

  // Manually turn off channel 8 of multiplexer 2 (optional)
  digitalWrite(SIG_2, LOW);
  delay(500); // Wait for 500 ms
}

// Function to select a channel on the specified multiplexer
void selectMultiplexerChannel(int channel, int multiplexer) {
  if (multiplexer == 1) {
    // Set control pins for multiplexer 1
    digitalWrite(S0_1, bitRead(channel, 0));
    digitalWrite(S1_1, bitRead(channel, 1));
    digitalWrite(S2_1, bitRead(channel, 2));
    digitalWrite(S3_1, bitRead(channel, 3));
  } else if (multiplexer == 2) {
    // Set control pins for multiplexer 2
    digitalWrite(S0_2, bitRead(channel, 0));
    digitalWrite(S1_2, bitRead(channel, 1));
    digitalWrite(S2_2, bitRead(channel, 2));
    digitalWrite(S3_2, bitRead(channel, 3));
  }
}

Any help is much apprepricated thx

Lots of Information is Missing

Your code looks great but I did not take the time to analyze it as I do not have a circuit for reference. Your wiring may be the root cause. Since hardware is involved, it’s crucial to provide an accurate, annotated schematic of your circuit as it is currently wired. Please note that Fritzing diagrams are not considered proper schematics; they are wiring diagrams and are often not helpful for troubleshooting.

What You Need to Include:

  1. Annotated Schematic: Show all connections, including power, ground, and power sources. This helps us understand how your circuit is set up and identify any potential issues.
  2. Technical Information Links: Provide links to technical documentation for each hardware device used in your setup. Avoid links to sales sites like Amazon, as they usually lack the necessary technical details. We need complete specifications to help you effectively.
  3. Additional Information Needed: If the above details are incorrect, more information is required. Tell us what hardware and software you are using. For example, if your project involves a robot, describe how it navigates and what computers are involved.
  4. Bill of Materials:
  5. A schematic provides a visual representation of the electrical connections and components in a circuit, showing how they interact and function together, while a Bill of Materials (BOM) is simply a list of components with part numbers and quantities needed for assembly. Unlike a BOM, a schematic illustrates the design’s logic and allows for troubleshooting and understanding circuit behavior. A BOM is useful for sourcing parts but doesn’t convey how they connect or operate in the circuit, which is critical information for understanding and working with electronics.

Why This Matters:

We have no way of knowing the specifics of your setup unless you provide that information. Clear and detailed descriptions enable us to offer the most accurate help possible. Without these details, it’s difficult to diagnose and solve the issues you're experiencing.

You only need twelve pins (DIO 2 - 13). No mux needed for Uno/Nano.

1 Like

I'm a bit confused by the Code. What's the deal with channel1? Should it be changed at some point?

For multiplexing I suggest some chip like HT16K33 or similar.

Please provide a wiring diagram.

1 Like

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.