CAN-BUS Shield interface with 7 segment display

Good Evening, I Hope everyone is well.

I am currently building an external gear display based on reading CAN IDs from the vehicle using an Arduino UNO board as well as a AZL Can-bus shield. Now i have isolated the IDs I need, however 1 segment (Segment C) in my common cathode 7 segment display remains on and i cannot seem to turn it off. I change pins from previously it being on pin2 to pin10.

The code i am using is listed below:

int pina = 6;
int pinb = 5;
int pinc = 10;
int pind = 3;
int pine = 4;
int pinf = 7;
int ping = 8;
int pindp = 9;

#include <Canbus.h>
#include <defaults.h>
#include <global.h>
#include <mcp2515.h>
#include <mcp2515_defs.h>

void setup()
{
if(Canbus.init(CANSPEED_500)); //Initialise MCP2515 CAN controller at the specified speed

  pinMode(pina ,OUTPUT); 
  pinMode(pinb ,OUTPUT);
  pinMode(pinc ,OUTPUT);
  pinMode(pind ,OUTPUT);
  pinMode(pine ,OUTPUT);
  pinMode(pinf ,OUTPUT);
  pinMode(ping ,OUTPUT);
  pinMode(pindp ,OUTPUT);

}

void loop() { tCAN message;
if (mcp2515_check_message())
{
if (mcp2515_get_message(&message))
{
if(message.id == 0x540 and message.data[0] == 0xB5 and message.data[2] == 0xFF and message.data[7] == 0x26) //Park=26; Reverse=36; Neutral=46; Drive=56; Sports=66 (1st=2F; 2nd=3F; 3rd=4F; 4th=5F; 6th=7F)
{

              digitalWrite(pina, HIGH); 
              digitalWrite(pinb, HIGH);
              digitalWrite(pinc, LOW);
              digitalWrite(pind, LOW);
              digitalWrite(pine, HIGH);
              digitalWrite(pinf, HIGH);
              digitalWrite(ping, HIGH);
              delay(50); 
          }

    if(message.id == 0x540 and message.data[0] == 0xB5 and message.data[2] == 0xFF and message.data[7] == 0x36)  //Park=26; Reverse=36; Neutral=46; Drive=56; Sports=66 (1st=2F; 2nd=3F; 3rd=4F; 4th=5F; 6th=7F)
         {
            
              digitalWrite(pina, HIGH); 
              digitalWrite(pinb, HIGH);
              digitalWrite(pinc, LOW);
              digitalWrite(pind, LOW);
              digitalWrite(pine, HIGH);
              digitalWrite(pinf, HIGH);
              digitalWrite(ping, LOW);
              delay(50);
          }

     if(message.id == 0x540 and message.data[0] == 0xB5 and message.data[2] == 0xFF and message.data[7] == 0x46)  //Park=26; Reverse=36; Neutral=46; Drive=56; Sports=66 (1st=2F; 2nd=3F; 3rd=4F; 4th=5F; 6th=7F)
         {
            
                digitalWrite(pina, LOW); 
                digitalWrite(pinb, LOW);
                digitalWrite(pinc, HIGH);
                digitalWrite(pind, LOW);
                digitalWrite(pine, HIGH);
                digitalWrite(pinf, LOW);
                digitalWrite(ping, HIGH);
                delay(50); 
          }

    if(message.id == 0x540 and message.data[0] == 0xB5 and message.data[2] == 0xFF and message.data[7] == 0x56)  //Park=26; Reverse=36; Neutral=46; Drive=56; Sports=66 (1st=2F; 2nd=3F; 3rd=4F; 4th=5F; 6th=7F)
         {
            
                digitalWrite(pina, LOW); 
                digitalWrite(pinb, HIGH);
                digitalWrite(pinc, HIGH);
                digitalWrite(pind, HIGH);
                digitalWrite(pine, HIGH);
                digitalWrite(pinf, LOW);
                digitalWrite(ping, HIGH);
                delay(50);
          }
          
    if(message.id == 0x540 and message.data[0] == 0xB5 and message.data[2] == 0xFF and message.data[7] == 0x66)  //Park=26; Reverse=36; Neutral=46; Drive=56; Sports=66 (1st=2F; 2nd=3F; 3rd=4F; 4th=5F; 6th=7F)
         {
            
                digitalWrite(pina, HIGH); 
                digitalWrite(pinb, LOW);
                digitalWrite(pinc, HIGH);
                digitalWrite(pind, HIGH);
                digitalWrite(pine, LOW);
                digitalWrite(pinf, HIGH);
                digitalWrite(ping, HIGH);
                delay(50);
          }

}
}
}

I would really appreciate any help on this matter. I am not a programmer by profession and everything I have learnt has been through tutorials and YouTube videos.

Many Thanks

Your post was MOVED to its current location as it is more suitable.

Could you also take a few moments to Learn How To Use The Forum.

Other general help and troubleshooting advice can be found here.
It will help you get the best out of the forum in the future.

Please read How to get the best out of this forum and follow the advice on posting code properly formatted and in code tags

On an Uno board, pins 10-12 are used for SPI so you can't use them with other things

Hi, @azharmahomet
Welcome to the forum.

Please read the post at the start of any forum , entitled "How to use this Forum".

Can you please post a copy of your circuit, in CAD or a picture of a hand drawn circuit in jpg, png?

Thanks.. Tom... :smiley: :+1: :coffee: :australia:

Hi Tom, thank you very much for the link.

I have tried to get the CAD software however i am struggling a little with it. I have however attempted something which i hope is clear enough as to how the circuit is wired. Please refer below to the diagram

Hi,
You will need current limit resistors on each of the segment connections.
Unfortunately that is not really a circuit diagram, what CAD is that?

Tom... :smiley: :+1: :coffee: :australia:

:sweat_smile: Well this was done in MS Paint and not in CAD, apologies.

I do have a resistor from the ground wire to the 7 segment display.

Thanks

Hi,
Better to draw in pen(cil) and paper and include all hardware.
A single resistor in the common cathode will result in changing brightness of your display depending on the number of segments displayed.
A resistor for each segment will give you better brightness.

Tom... :smiley: :+1: :coffee: :australia:

Hi,

Please find drawn circuit diagram below

I have also included actual pictures of how the components look to better illustrate the wiring diagram in the posts below

I've read for a common cathode a single resistor is needed on the ground wire. If I am wrong I shall change that.

Thanks

IMG_20210621_131747

Did you not see reply #3 from me? pin 10 is used by SPI which you are using for the CAN bus so you can not use it for your display

Hi,

Yes I did and i have changed it, I swapped it out with the DP which is no longer needed.

I think there might be an issue with the code as the refresh when going down the gear selector i.e. P, R, N, D updates but when you switch back it doesnt really take.

I will be making some adjustments to the delay and code this evening and will test.

Thanks

You can refactor your code a bit so you can see if any other codes come along

const int pina = 6;
const int pinb = 5;
const int pinc = 2;
const int pind = 3;
const int pine = 4;
const int pinf = 7;
const int ping = 8;
//int pindp = 9;

#include <Canbus.h>
#include <defaults.h>
#include <global.h>
#include <mcp2515.h>
#include <mcp2515_defs.h>

void setup()
{
  Canbus.init(CANSPEED_500); //Initialise MCP2515 CAN controller at the specified speed
  pinMode(pina , OUTPUT);
  pinMode(pinb , OUTPUT);
  pinMode(pinc , OUTPUT);
  pinMode(pind , OUTPUT);
  pinMode(pine , OUTPUT);
  pinMode(pinf , OUTPUT);
  pinMode(ping , OUTPUT);
//  pinMode(pindp , OUTPUT);
}

//Park=26; Reverse=36; Neutral=46; Drive=56; Sports=66 (1st=2F; 2nd=3F; 3rd=4F; 4th=5F; 6th=7F)
enum { PARK = 0x26, REVERSE = 0x36, NEUTRAL = 0x46, DRIVE = 0x56, SPORTS = 0x66 }

void loop() {
  tCAN message;
  if (mcp2515_check_message()) {
    if (mcp2515_get_message(&message))  {
      if (message.id == 0x540 and message.data[0] == 0xB5 and message.data[2] == 0xFF) {
        switch (message.data[7]) {
          case PARK:
            digitalWrite(pina, HIGH);
            digitalWrite(pinb, HIGH);
            digitalWrite(pinc, LOW);
            digitalWrite(pind, LOW);
            digitalWrite(pine, HIGH);
            digitalWrite(pinf, HIGH);
            digitalWrite(ping, HIGH);
            break;

          case REVERSE:
            digitalWrite(pina, HIGH);
            digitalWrite(pinb, HIGH);
            digitalWrite(pinc, LOW);
            digitalWrite(pind, LOW);
            digitalWrite(pine, HIGH);
            digitalWrite(pinf, HIGH);
            digitalWrite(ping, LOW);
            break;

          case NEUTRAL:
            digitalWrite(pina, LOW);
            digitalWrite(pinb, LOW);
            digitalWrite(pinc, HIGH);
            digitalWrite(pind, LOW);
            digitalWrite(pine, HIGH);
            digitalWrite(pinf, LOW);
            digitalWrite(ping, HIGH);
            break;

          case DRIVE:
            digitalWrite(pina, LOW);
            digitalWrite(pinb, HIGH);
            digitalWrite(pinc, HIGH);
            digitalWrite(pind, HIGH);
            digitalWrite(pine, HIGH);
            digitalWrite(pinf, LOW);
            digitalWrite(ping, HIGH);
            break;

          case SPORTS:
            digitalWrite(pina, HIGH);
            digitalWrite(pinb, LOW);
            digitalWrite(pinc, HIGH);
            digitalWrite(pind, HIGH);
            digitalWrite(pine, LOW);
            digitalWrite(pinf, HIGH);
            digitalWrite(ping, HIGH);
            break;

          default:  // something else
            digitalWrite(pina, HIGH);
            digitalWrite(pinb, HIGH);
            digitalWrite(pinc, HIGH);
            digitalWrite(pind, HIGH);
            digitalWrite(pine, HIGH);
            digitalWrite(pinf, HIGH);
            digitalWrite(ping, HIGH);
            break;
        }
        delay(50);
      }
    }
  }
}

This is awesome, thank you so much for this

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