Issue with 7-segment display connected to Arduino MKR-1010 on SPI

I am having issues getting the 4-character 7-segment display correctly. I double checked the SPI connections, used the code on your tutorials page. The code writes “1234” to display but it shows “0234”. I tried many combinations, cleared display, used commands to reset cursor position each time but it behaves weird. It is frustrating…

Appreciate any pointers.

Update from further testing:

The display seems to have a mind of it’s own! Gives inconsistent results uploading same code twice - numbers shown on the display every time make no sense. It seems to be shifting characters in different ways. All I am doing is initializing and sending ‘8’,‘7’,‘6’,‘5’ followed by ‘1’,‘2’,‘3’,‘4’. Tried the steps given in the updated tutorial in comments section:

https://learn.sparkfun.com/tutorials/us … ay/discuss

That makes it do even weirder things. Connecting the RESET of Arduino to RST of display changes the behavior completely. It appears the display stores the data sent in some form of buffer that is read in a cyclic manner but uses some logic that’s incomprehensible. Please help!

It’s unfortunate that figuring out the display has taken 3 days with no success but the rest of the project (quite complex) took only 2 days.

Hello kulkarnisrini,

Have you tried using the I2C port or Serial? I’m not familiar with the MKR-1010 so I just want to check if there are quirks with its SPI bus.

Unfortunately I don’t have an MKR1010 to test with and it could be a connection issue. The MKR1010 appears to have it’s SPI pins in different places than the Uno does.

What happens when you run the code in the zip below on An Arduino Uno with the connections in this photo?

7_Segment_Serial_Display_SPI_test.zip (1.79 KB)

https://cdn.sparkfun.com/r/600-600/asse … 000001.png

Also, the display wraps around as you write to it so if you’re not resetting the cursor, the digits you write may not be where you expect them to be. Resetting the Arduino doesn’t change where the cursor is on the display.

Hello,

Thanks for your response and pointers.

I believe I have used the SPI pins on the MKR board correctly: Vcc, GND, RST, SCK to matching pins on display; “MOSI” on MKR to “SDI” on display; digital pin 6 to “SS” on display → code changed to reflect this pin; pin pulled low to write to display SPI and then pulled high. The display turns on and displays numbers - indicating connections are good. Just the sequence of numbers displayed does not match with code - even with the code as-is from tutorials (ex. the “-HI-” from tutorial displays as “HI-.”, shifted left) . I also tried the instructions in comments of the tutorials page.

It seems to randomly shift one digit left or right, sometimes blanks out one digit making it hard to decipher the internal logic. I understand the display logic expects command bytes in pairs and digits in sets of 4 from the instructions; but when the two are interspersed (ex. to display a colon “:” when displaying time) it starts shifting again.

PS: Connecting Serial1 on MKR (pins 13, 14) to display RX, TX works perfectly fine. But I had to allocate that port to a MP3 player needed for the project and hence switched to SPI for this display. I have not tried the I2C connection

Appreciate your help.

Added pictures of connections.

IMG_0650.JPG

Try the display with an Arduino Uno and the code and hookup above as a sanity test to see if things work OK there.

I’ve tried the display and our code on a MKR1000 and I’m getting strange results as well. I don’t know if this is a timing issue, or if there is some sort of incompatibility with our example code and the MKR1000/1010. Good news is I2C appears to be working just fine and uses less pins. You might consider switching to I2C.

After a bit of messing around with the SPI code, it looks like the MKR1000 (and likely the MKR1010) are both executing code too quickly for the display to keep up and it occasionally will miss an instruction, causing the display to shift.

By adding in some small delays to the SS pin code, I was able to get things running more smoothly. I’d recommend adding a small delay when toggling the SS line and see if that helps.

Thank you for the suggestion. I will try that.

PS: I tried attaching my code in TXT format as well as just pasting here. It gave me a “Forbidden” error.

I added a 100ms delay after each toggle of the SS pin; will try lowering it later.

I also changed the SPI clock to :

SPI.setClockDivider(SPI_CLOCK_DIV128); // Slow down SPI clock

I also set cursor position to 0 each time.

Unfortunately it didn’t help. Is there anything else I could try. Appreciate any pointers.

Attaching code.

Unable to attach code …it says HTTP Error when I do:

Upload Attachment->Add Files->Select a “.txt” file from my laptop.

Update: I tested with I2C connections and it works perfectly fine.

PS: The address (I2C) provided in the tutorial was not applicable so I had to scan and find the correct address.

I have already tested for Serial interface (using Serial1 on MKR using pins 13 & 14) - works fine.

So SPI is the issue - needs to be looked into further. Perhaps the clock speed incompatibility or the code on the display unit isn’t reading SPI correctly.

Appreciate if you can please help crack it.