Help with SPI code for a display

Hello,

I am trying to display the number 1234 on the display in the link below:

I am converting the value into 4 separate bytes and send them one at a time. Also I am getting an error on where I am shifting the bytes in the transfer. The display does not display the number.

What part am I missing?

Thanks

// Segment labelling:
//        A
//       ----
//     F |  | B
//       ---- G
//     E |  | C
//  .DP  ---- 
//        D


#include <SPI.h>                                                            // include the SPI library

byte valuetobyte();                                                         // function valuetobyte

int num=0;                                                                  // set value to be initial zero
int value;
int dig1 = 0;
int dig2 = 0;
int dig3 = 0;
int dig4 = 0;
  
  //G F A B C D E DP
  byte zero  = 0b01111110;                                                    // every value on display to binary
  byte one   = 0b00011000;
  byte two   = 0b10110110;
  byte three = 0b10111100;
  byte four  = 0b11011000;
  byte five  = 0b11101100;
  byte six   = 0b11101110;
  byte seven = 0b00111000;
  byte eight = 0b11111110;
  byte nine  = 0b11111100;
  byte dash  = 0b10000000;
  byte blank = 0b00000000;

 const int SlaveSelectPin = 10;                                             // set pin 10 as the slave select pin (SS)
 

void setup() {

  pinMode(SS, OUTPUT);                                                      // set SS as an output
  digitalWrite(SS, HIGH);                                                   // set the SS pin to high
  SPI.begin ();                                                             // start the SPI
  SPI.beginTransaction(SPISettings (1500000, LSBFIRST, SPI_MODE1));
  
}

void loop()
{

  int num;                                                                  // define variables
  byte displaydigit1;
  byte displaydigit2;
  byte displaydigit3;
  byte displaydigit4;

  num = 1234;
  
  dig1 = num / 1000;                                                        // the thousandths digit
  num = num - (dig1 * 1000);
  dig2 = num / 100;                                                         // the hundredths digit
  num = num - (dig2 * 100);
  dig3 = num / 10;                                                          // the tenths digit
  dig4 = num - (dig3 *10);                                                  // the ones digit

  Serial.begin (9600);
  
  displaydigit1 = Serial.println(valuetobyte(dig1), BIN);
  
  displaydigit2 = Serial.println(valuetobyte(dig2), BIN);
  
  displaydigit3 = Serial.println(valuetobyte(dig3), BIN);

  displaydigit4 = Serial.println(valuetobyte(dig4), BIN);
  
 digitalWrite(SS, LOW);                                                   // set SS low to send data

  SPI.transfer(displaydigit1>>24);                                       // transfer the highest 8 bits
  SPI.transfer(displaydigit2>>16);
  SPI.transfer(displaydigit3>>8);
  SPI.transfer(displaydigit4);

 digitalWrite(SS, HIGH);

 delay(1000);

 //return(0);
  
  }

byte valuetobyte(int value) {                                             // function that takes a value and converts it into a byte

  byte bytevalue;
  //int value;
  
  switch (value) {
    case 0:                                                               // if the value is 0, then return the byte value of zero defined above
      if(value == 0){
        bytevalue = zero;
        return(bytevalue);
        break; }

    case 1:
      if(value == 1) {
        bytevalue = one;
        return(bytevalue);
        break; }

    case 2:
      if(value == 2) {
        bytevalue = two;
        return(bytevalue);
        break; }

    case 3:
      if(value == 3) {
          bytevalue = three;
          return(bytevalue);
          break; }

    case 4:
      if(value == 4) {
          bytevalue = four;
          return(bytevalue);
          break; }

    case 5:
      if(value == 5) {
          bytevalue = five;
          return(bytevalue);
          break; }

    case 6:
      if(value == 6) {
          bytevalue = six;
          return(bytevalue);
          break; }

    case 7:
      if(value == 7) {
          bytevalue = seven;
          return(bytevalue);
          break; }

    case 8:
      if(value == 8) {
          bytevalue = eight;
          return(bytevalue);
          break; }

    case 9:
      if(value == 9) {
          bytevalue = nine;
          return(bytevalue);
          break; }

    default:
      bytevalue = blank;
      return(bytevalue);
      break;

  }

}

How did you wire everything up?

That is a seriously expensive display! It better be worth it!

Not sure what

//return(0);

is supposed to do or whether it simply fouls things up.

Rintin:
How did you wire everything up?

Wired:

Arduino Uno Display
5V VPOS
GND VNEG
Pin 10 LOAD
Pin 11 DI
Pin 13 CK

Paul__B:
That is a seriously expensive display! It better be worth it!

Not sure what

//return(0);

is supposed to do or whether it simply fouls things up.

It was purchased for mounting purposes. It is expensive though. Also if the return(0) is not commented out, then there is an error. I originally had it, but commented it out. Am I doing the transferring correctly?

You are defining SlaveSelectPin and using SS. Might be a problem.

Have you tried to pull LOAD to high?

Hello,

just an update. When transferring the bytes, the ">>" are not needed. The working code is below:

digitalWrite(SS, LOW);                                                   // set SS low to send data

  
  SPI.transfer(valuetobyte(dig4));                                       // transfer the highest 8 bits
  SPI.transfer(valuetobyte(dig3));
  SPI.transfer(valuetobyte(dig2));
  SPI.transfer(valuetobyte(dig1));
  
 digitalWrite(SS, HIGH);

 delay(100);

Also the "return(0)" does not make a difference in the code.

alexpolyanskiy:
Also the "return(0)" does not make a difference in the code.

Not of course, if it is commented out, but it is simply nonsensical in loop() because you never return.

Paul__B:
Not of course, if it is commented out, but it is simply nonsensical in loop() because you never return.

That is not correct. Of course the loop() returns.

void loop() is a void function. It can return. But it can not return a value e.g. return(0)

David.