Driving 2 7-segment displays from an Arduino MKR1000

Hi there,

First off - thank you in advance for any help I might receive. SparkFun and the forums are a great sense of knowledge.

Okay, here’s my hardware:

  1. Arduino MKR1000 powered by the SparkFun ATX Power Connector Breakout Kit (Part 15701)

  2. 2x SparkFun 4-character 7 digit displays, blue, Part 11441

Connections:

  1. 5V from the MKR1000 is connected to both “VCC” terminals on the displays (this is all done via Protoboard 12699)

  2. GND from the MKR1000 is connected to both “GND” terminals on the displays

  3. The “RX” pin on the displays is connected to pin 0 and pin 4, respectively, on the MKR1000

Software:

I am trying to use Serial to communicate with both displays.

The problem is that both displays show weird behavior - sometimes all 0s , e.g. “0000” or don’t come on at all.

I’m using the SERCOM functionality on the MKR1000 to utilize additional Serial interfaces.

I will attach my code to this post.

I have tried:

  1. Connecting to computer via USB Serial

  2. Powering with a power source that produces more power (could power up to 2.4A) worried it was a power problem

  3. I have swapped out one of the 7 segments for another one, that still didn’t work

  4. I’ve looped over all baud rates and written the 0x81 reset byte

  5. I’ve tried clearing the displays first via 0x76

I suspect it’s a problem in my code.

I saw the 7 segment post about firmware - it seems odd to me that I would have to re-flash firmware because I just ordered 4x of the units directly from Sparkfun - the correct firmware would be on them already, right?

Thank you in advance!

Matt

#include <ArduinoHttpClient.h>
#include <WiFi101.h>
#include <SPI.h>
#include <Arduino.h>
#include <wiring_private.h>

/*
    This sketch has the following serial interfaces:
    Serial  - Native USB interface
    Serial1 - Default serial port on D13, D14 (Sercom 5)
    Serial2 - Extra serial port on D0, D1 (Sercom 3)
    Serial3 - Extra serial port on D4, D5 (Sercom 4)
*/

// Serial2 pin and pad definitions (in Arduino files Variant.h & Variant.cpp)
#define PIN_SERIAL2_RX       (1ul)                // Pin description number for PIO_SERCOM on D1
#define PIN_SERIAL2_TX       (0ul)                // Pin description number for PIO_SERCOM on D0
#define PAD_SERIAL2_TX       (UART_TX_PAD_0)      // SERCOM pad 0 TX
#define PAD_SERIAL2_RX       (SERCOM_RX_PAD_1)    // SERCOM pad 1 RX

// Serial3 pin and pad definitions (in Arduino files Variant.h & Variant.cpp)
#define PIN_SERIAL3_RX       (5ul)                // Pin description number for PIO_SERCOM on D5
#define PIN_SERIAL3_TX       (4ul)                // Pin description number for PIO_SERCOM on D4
#define PAD_SERIAL3_TX       (UART_TX_PAD_2)      // SERCOM pad 2 TX
#define PAD_SERIAL3_RX       (SERCOM_RX_PAD_3)    // SERCOM pad 3 RX

// Instantiate the extra Serial classes
Uart Serial2(&sercom3, PIN_SERIAL2_RX, PIN_SERIAL2_TX, PAD_SERIAL2_RX, PAD_SERIAL2_TX);
Uart Serial3(&sercom4, PIN_SERIAL3_RX, PIN_SERIAL3_TX, PAD_SERIAL3_RX, PAD_SERIAL3_TX);

void SERCOM3_Handler()    // Interrupt handler for SERCOM3
{
  Serial2.IrqHandler();
}

void SERCOM4_Handler()    // Interrupt handler for SERCOM4
{
  Serial3.IrqHandler();
}

void setup()
{
  Serial1.begin(9600);
  
  Serial.begin(9600);

  Serial.println("Booting");
  
  pinPeripheral(0, PIO_SERCOM);   // Assign pins 0 & 1 SERCOM functionality
  pinPeripheral(1, PIO_SERCOM);
  Serial2.begin(9600);           // Begin Serial2 

  pinPeripheral(4, PIO_SERCOM_ALT);   // Assign pins 4 & 5 SERCOM functionality
  pinPeripheral(5, PIO_SERCOM_ALT);
  Serial3.begin(9600);               // Begin Serial3
  
  Serial2.write(0x76).
  Serial3.write(0x76);
  Serial2.print("----");
  Serial3.print("----");
}

void loop()
{
}

Hi Matt.

You shouldn’t need to change the firmware at all on the displays, the most current version should be what’s shipping.

SparkFun can’t help debug your code, but the data you’re trying to send in your code looks OK and should blank each screen and display “----” on each one.

Have you tried connecting a logic analyzer or something like an FTDI up to each TX pin to see if what you believe is being sent is actually what’s being transmitted?

Chris,

Thank you for your prompt reply! I haven’t but that sounds like a great next step. What should I purchase from SparkFun? FTDI cable only or would I need anything else? I have headers etc from you guys already.

Matt

Chris - I had a thought.

Do you think I could monitor what is being sent with a second arduino, hooked up to each of the TX pins (0 and 4, during two different trial runs), that reads and prints to Serial? Would that achieve the same thing without me having to wait for an FTDI or logic analyzer to get shipped from you guys?

Thanks!

Matt

Hi Matt.

The FTDI cable works as well but I’d try the Beefy 3 FTDI Basic as it is capable of supplying more current (for later projects) than the FTDI cable. By connecting the pin you’re using for TX on your Arduino to the RX pin on the Beefy, you can spy on what’s being transmitted to make sure it’s what you expect.

There’s a terminal program called RealTerm that can display hex as well as ASCII to aid in your debugging. I think you will find a FTDI board very useful for debugging or just communicating with other serial devices.

Update:

You could use an Arduino to do the monitoring as well if you happen to have one. A [serial pass through sketch would emulate a FTDI.](https://www.arduino.cc/en/Tutorial/SerialPassthrough)

Chris,

Thank you sir, really appreciate it! I will try the second Arduino method tonight, and report back here on what I find. Even if it is an error on my side, it would be good for me to report back to you so that if someone else has this question you might direct them to this thread.

I will also purchase the Beefy FTDI you mention for the future.

I can also attach pictures of my hardware setup as well, once I’m home, that might help.

Thank you for all your help!

Matt

Chris,

I got home and uploaded the test program I sent to you on this thread earlier.

I’ve attached 2 pictures - one shows you what I am seeing on the 7 segment displays and the other one shows you my wiring. Note that while I have physical buttons mounted on the wood, they are not yet connected at all (no wires) so those aren’t a factor. I am trying to get the 7 segments to work first.

I’ll try the second Arduino thing to monitor the TX port tonight too I just thought I would upload the pictures in case it helps you think of anything!

Matt

Chris,

If you can glean anything from the images I attached or have a hunch, that would be awesome.

If my tests with the second Arduino result in me seeing the correct data being sent over to the RX pin on the display, I suppose I don’t really have anywhere else to go, since I’ve already tried replacing the display with a new one (I need 2 but I bought 4 from you guys).

Thank you so much for all your help. I’ve just been banging my head against the wall for 2-3 days on this and am perplexed as to why it doesn’t work, being so simple.

Matt

Chris,

Okay, I connected another Arduino. I see some of this printed out:

08:24:42.053 → ⸮

(I had “show timestamp” checked, so that weird question mark is really the only character it printed out).

I think I might try with another Arduino. Wondering if this MKR1000 is messed up somehow.

Matt

Hi Matt.

The serial monitor in the Arduino IDE can only show you printable characters so you can’t easily see what’s being transferred in hex if it’s not a printable character.

What I’d recommend trying is using an Arduino Uno and seeing if you can get a display working correctly with that. Once you have things running, then switch back to the MKR and see if you can get it working there too.

There is a possibility something could be wrong with the MKR, but it’s more likely to be an issue somewhere in your code than the hardware.

Chris,

Thank you for the reply. The Uno doesn’t support additional SERCOM instances, does it? I would use the SoftwareSerial library or something, right?

Yes, the Uno doesn’t support SERCOM so you would need software serial.

Hi Chris,

The plot thickens here. I purchased a MKR 1010 from you guys with next-day-air shipping last night to try out if the board was the problem.

I just hooked that up bare-bones to a 7 segment display:

5V => VCC

GND => GND

14 => RX

(Left hand side is the Arduino, RHS is the segmented display).

With this bare-bones code:

#include <Arduino.h>
#include <wiring_private.h>


void setup()
{  
  Serial.begin(9600);

  while (!Serial) delay(10);

  Serial1.begin(9600);

  while (!Serial1)delay(10);

  pinPeripheral(0, PIO_SERCOM);
  pinPeripheral(1, PIO_SERCOM);
  
  Serial.println("Booting");

  Serial1.write(0x76);  // Clear the display
  Serial1.print("test");
}

void loop()
{
  
}

It still didn’t work. Showed all zeros.

Any chance that I can’t drive the display right from the Arduino? Due to the 5V and 3.3V differences? Could that be it? I’m running out of ideas.

Matt

Hey team,

Wow - finally, I think I figured it out. It was indeed the 3.3v vs. 5v.

Chris - do you think you guys could update documentation to help future engineers trying to solve this? I spent a lot of time on it. The root cause was that I was supplying the board 5v power-wise but sending serial commands at 3.3v, the voltage of the MKR1000. I know that the data sheet and tutorials for the 7 segment display say that it can be powered from 3v-6v so I didn’t think this would be a problem, but the behavior appears indeterministic if you power it with 5v but supply serial data over 3.3v.

Hope that makes sense…

Matt

Hi Matt.

Generally the 3.3 volt to 5 volt miss match isn’t an issue but for some reason it sounds like it gave you trouble. I’ll put in a ticket for the tutorials team to have a look at this for you though. Glad it’s working!

Chris,

Thank you! Yes. I really banged my head on it for days. I was a little bit frustrated because I triple checked my wiring and software, which was indeed correct.

I also ordered multiple displays and multiple MKR1000s (and a 1010) to debug if it was a hardware issue, which it wasn’t.

You were very helpful on this thread (thanks again!) and eventually after a lot of research I figured it out. As soon as I switched both to 3.3v it all worked as expected.

It’s worth a sentence or two - I combed your guys’ tutorial reading every word and trying everything, so if it was there, I would have saw it.

Just a note for others who hit things like this!

Thanks again!

Matt