Trouble using a bar graph as a transmitter throttle level guage

Hi there.
I'm new to arduino with very little knowledge about using it so I apologise in advance.
I'll try to provide as much information as I can.

I'm attempting to use the following 11 pin, 28 segment multiplexed bar graph, linked to a Max7219 IC and an arduino Uno in order to use the bar graph as a level gauge for a vintage analogue transmitter throttle stick, to display one segment at a time as the throttle stick is pushed up to full throttle where all segments plus a single LED will then be lit and turn off one at a time in reverse order on throttle down.

I have everything connected as follows:

The PWM signal from the receiver connected to pin A0 on the Arduino uno
The single LED connected to digital pin 8 and gnd on the arduino

⦁ Data In (DIN) pin 1 on MAX7219 to arduino digital pin 11,
⦁ Clock (CLK) pin 13 on MAX7219 to arduino digital pin 13
⦁ Chip Select (CS) pin 12 on MAX7219 to arduino digital pin 10.

⦁ max7219 V+ and iset connected to arduino 5v with a 10k resistor between iset and 5v
⦁ max7219 gnd pins 4 and 9 bridged then connected to arduino gnd
⦁ SEG A (pin 14) to L1
⦁ SEG B (pin 16) to L2
⦁ SEG C (pin 20) to L3
⦁ SEG D (pin 23) to L4
⦁ DIG 0 (pin 2) to C1
⦁ DIG 1 (pin 11) to C2
⦁ DIG 2 (pin 6) to C3
⦁ DIG 3 (pin 7) to C4
⦁ DIG 4 (pin 3) to C5
⦁ DIG 5 (pin 10) to C6
⦁ DIG 6 (pin 5) to C7

So far with the following code, I've managed to get to the point where all bar graph segments and single LED will light up at the full throttle range and turn off as I start to throttle down but the bar graph segments won't turn on one at a time as the throttle increases as I need them to and I can't seem to get my head around what could be causing the issue.

#include <SPI.h>

const int MAX7219_CS_PIN = 10;

const int RECEIVER_PIN = A0;
const int LED_PIN = 8;

void setup() {
  SPI.begin();
  pinMode(MAX7219_CS_PIN, OUTPUT);
  digitalWrite(MAX7219_CS_PIN, HIGH); // Disable MAX7219 temporarily

  // Initialize the MAX7219
  sendSPICommand(0x09, 0x00); // Decode Mode off
  sendSPICommand(0x0A, 0x0F); // Intensity (range: 0x00 to 0x0F)
  sendSPICommand(0x0B, 0x07); // Scan Limit: 8 LEDs
  sendSPICommand(0x0C, 0x01); // Power-down Mode: Normal operation

  pinMode(LED_PIN, OUTPUT);
  digitalWrite(LED_PIN, LOW);
}

void loop() {
  int throttleValue = pulseIn(RECEIVER_PIN, HIGH, 20000); // Adjust timeout based on your receiver's PWM range

  // Map the PWM value to control the single LED
  if (throttleValue >= 1923) {
    digitalWrite(LED_PIN, HIGH); // Turn on the single LED at full throttle
  } else {
    digitalWrite(LED_PIN, LOW); // Turn off the single LED otherwise
  }

  // Map the PWM value to control the bargraph (0 to 27, assuming 28 segments)
  int barGraphValue = map(throttleValue, 1362, 1923, 0, 27);

  // Update the bargraph display
  digitalWrite(MAX7219_CS_PIN, LOW); // Enable MAX7219
  for (int i = 0; i <= barGraphValue; i++) {
    sendSPICommand(i + 1, 0x01); // Turn on the LED at index i
  }
  for (int i = barGraphValue + 1; i < 28; i++) {
    sendSPICommand(i + 1, 0x00); // Turn off the LED at index i
  }
  digitalWrite(MAX7219_CS_PIN, HIGH); // Disable MAX7219
}

void sendSPICommand(byte address, byte data) {
  SPI.transfer(address);
  SPI.transfer(data);
}

More information about this product.
" following 11 pin, 28 segment multiplexed bar graph, "
Datasheet, link, etc...

Also post a schematic (even freehand) of your project.

Thanks for the quick reply.
I'll try to post a schematic as soon as possible.

Here are the data sheets for the bar graph and Max7219
It's the BL28Z-3005SA04Y bar graph, specifically.

I'd add a serial.println() here and monitor the value. Maybe constrain it if required. Let us know if the values are as expected on throttle up vs down.

https://www.arduino.cc/reference/en/language/functions/math/constrain/

I should have mentioned that in my initial post, those values were taken directly from a serial print of the throttle range as i was having an issue with the lights turning on full at 50% throttle range.
Those values fixed that particular issue

This may not be correct, I won't know until I see your schematic.

#include <SPI.h>

const int MAX7219_CS_PIN = 10;

const int RECEIVER_PIN = A0;
const int LED_PIN = 8;

void setup() {
  SPI.begin();
  pinMode(MAX7219_CS_PIN, OUTPUT);
  digitalWrite(MAX7219_CS_PIN, HIGH); // Disable MAX7219 temporarily

  // Initialize the MAX7219
  sendSPICommand(0x09, 0x00); // Decode Mode off
  sendSPICommand(0x0A, 0x0F); // Intensity (range: 0x00 to 0x0F)
  sendSPICommand(0x0B, 0x07); // Scan Limit: 8 LEDs
  sendSPICommand(0x0C, 0x01); // Power-down Mode: Normal operation

  pinMode(LED_PIN, OUTPUT);
  digitalWrite(LED_PIN, LOW);
}

void loop() {
  int throttleValue = pulseIn(RECEIVER_PIN, HIGH, 20000); // Adjust timeout based on your receiver's PWM range

  // Map the PWM value to control the single LED
  if (throttleValue >= 1923) {
    digitalWrite(LED_PIN, HIGH); // Turn on the single LED at full throttle
  } else {
    digitalWrite(LED_PIN, LOW); // Turn off the single LED otherwise
  }

  // Map the PWM value to control the bargraph (0 to 27, assuming 28 segments)
  int barGraphValue = map(throttleValue, 1362, 1923, 0, 27);

  // Update the bargraph display
  digitalWrite(MAX7219_CS_PIN, LOW); // Enable MAX7219
  for (int digit = 0; digit < 8; digit++) {
    byte segments = 0;
    for (int segment = 0; segment < 4; segment++) {
      if (barGraphValue > 0) {
        bitSet(segments, segment);
        barGraphValue--;
      }
    }
    sendSPICommand(digit + 1, segments); // Update the LEDs
  }
  digitalWrite(MAX7219_CS_PIN, HIGH); // Disable MAX7219
}

void sendSPICommand(byte address, byte data) {
  SPI.transfer(address);
  SPI.transfer(data);
}

If Paul's doesn't work you could try this.

#include <SPI.h>

const int MAX7219_CS_PIN = 10;

const int RECEIVER_PIN = A0;
const int LED_PIN = 8;

void setup() {
  SPI.begin();
  pinMode(MAX7219_CS_PIN, OUTPUT);
  digitalWrite(MAX7219_CS_PIN, HIGH); // Disable MAX7219 temporarily

  // Initialize the MAX7219
  sendSPICommand(0x09, 0x00); // Decode Mode off
  sendSPICommand(0x0A, 0x0F); // Intensity (range: 0x00 to 0x0F)
  sendSPICommand(0x0B, 0x07); // Scan Limit: 8 LEDs
  sendSPICommand(0x0C, 0x01); // Power-down Mode: Normal operation

  pinMode(LED_PIN, OUTPUT);
  digitalWrite(LED_PIN, LOW);
}

void loop() {
  int throttleValue = pulseIn(RECEIVER_PIN, HIGH, 20000); // Adjust timeout based on your receiver's PWM range

  // Map the PWM value to control the single LED
  if (throttleValue >= 1923) {
    digitalWrite(LED_PIN, HIGH); // Turn on the single LED at full throttle
  } else {
    digitalWrite(LED_PIN, LOW); // Turn off the single LED otherwise
  }

  // Map the PWM value to control the bargraph (0 to 27, assuming 28 segments)
  int barGraphValue = map(throttleValue, 1362, 1923, 0, 27);

  // Update the bargraph display
  digitalWrite(MAX7219_CS_PIN, LOW); // Enable MAX7219
  for (int i = 0; i < 28; i++) {
    if (i <= barGraphValue) {
      sendSPICommand(i + 1, 0x01);
    } else {
      sendSPICommand(i + 1, 0x00);
    }
  }
  digitalWrite(MAX7219_CS_PIN, HIGH); // Disable MAX7219
}



void sendSPICommand(byte address, byte data) {
  SPI.transfer(address);
  SPI.transfer(data);
}

@apf1979 your suggested code definitely will not work. The max chip has 8 internal registers each holding 8 bits that control an led segment, allowing it to control up to 64 led segments. Plus a few control registers for things like brightness. It does not have one register per segment, which is what @redspecialfx incorrectly assumed.

1 Like

Sorry for the late reply, I've had a busy time of things over the past week or so.

Thanks for everyone's input on this .
PaulRB is correct.
Infact after realising this a few days back, I removed the max chip from the circuit and managed to achieve the function that I was looking for via directly connecting the Bar graph to the Arduino Uno.

Sounds like a bad decision which could damage the Uno. If you share the circuit and code, the forum can check it's suitability for you. The max chip was a good option.

Would you mind sharing the code you used to get this working with just the arduino?

Thanks in advance.

We haven't seen the circuit that @redspecialfx used to connect the bar graph to the Arduino. It may be incorrect and damage the Arduino. This is a serious point, without appropriately calculated series resistors to limit the current, it could overload the Arduino pins.

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