Multiple Seedstudio grove 4-digit displays on Teensy 3.6

Status
Not open for further replies.
Hi experts! I am building a submarine simulator for my son and am capturing the build process. I am hooking up 5 or more Seed 7-seg LCD displays and am trying to minimize on wiring. I noticed that when Seed sells their grove Arduino base shield they are reusing pins, see here:

http://wiki.seeed.cc/Base_Shield_V2/

so line D2 uses pins D2 and D3
line D3 connector uses pins D3 and D4
line D4 connector uses pins D4 and D5

The way these get hooked up to the grove displays is that one pin is used for CLK and the other for DIO using the TM1637 driver.

Am I reading this correctly? Is this allowed? Here's an example code I am having trouble with:

Code:
#include <TM1637Display.h>
#include <Grove_LED_Bar.h>

#define fourdigits1_CLK_pin 33
#define fourdigits1_DIO_pin 34

#define fourdigits2_CLK_pin 34
#define fourdigits2_DIO_pin 35

#define fourdigits3_CLK_pin 35
#define fourdigits3_DIO_pin 36

#define displayBrightness 2 //BRIGHT_TYPICAL = 2,BRIGHT_DARKEST = 0,BRIGHTEST = 7;

int8_t fourdigits_Disp[] = {0x00,0x00,0x00,0x00};
TM1637Display fourdigits1(fourdigits1_CLK_pin, fourdigits1_DIO_pin);
TM1637Display fourdigits2(fourdigits2_CLK_pin, fourdigits2_DIO_pin);
TM1637Display fourdigits3(fourdigits3_CLK_pin, fourdigits3_DIO_pin);

So I am directly connecting the pins on the Teensy 3.6 in the same fashion that Seedstudio is handling this pin sharing. I am running into problems: it doesn't completely fail, but when I "daisy chain" pins this way more than once then the display doesn't work properly.

For example:
The display titled "fourdigits1" and "fourdigits3" work fine but "fourdigits2" gets corrupted:

Question:

1. Can this daisy chaining work? Is it a matter of adding delays? Or other modification to the code?
2. Is Seed doing some hardware manipulation here?
 
Not sure: Where are you getting your libraries from? Is it this one? https://github.com/avishorp/TM1637

I am not sure how well this one works? Looks like it works with trying to use the internal Pull UP resistors on IO pins....

Although not quite sure if Pulled up or down?...

That is if you look in the code:
Code:
TM1637Display::TM1637Display(uint8_t pinClk, uint8_t pinDIO)
{
	// Copy the pin numbers
	m_pinClk = pinClk;
	m_pinDIO = pinDIO;

	// Set the pin direction and default value.
	// Both pins are set as inputs, allowing the pull-up resistors to pull them up
    pinMode(m_pinClk, INPUT);
    pinMode(m_pinDIO,INPUT);
	digitalWrite(m_pinClk, LOW);
	digitalWrite(m_pinDIO, LOW);
}
...
bool TM1637Display::writeByte(uint8_t b)
{
  uint8_t data = b;

  // 8 Data Bits
  for(uint8_t i = 0; i < 8; i++) {
    // CLK low
    pinMode(m_pinClk, OUTPUT);
    bitDelay();

	// Set data bit
    if (data & 0x01)
      pinMode(m_pinDIO, INPUT);
    else
      pinMode(m_pinDIO, OUTPUT);

    bitDelay();

	// CLK high
    pinMode(m_pinClk, INPUT);
    bitDelay();
    data = data >> 1;
  }

  // Wait for acknowledge
  // CLK to zero
  pinMode(m_pinClk, OUTPUT);
  pinMode(m_pinDIO, INPUT);
  bitDelay();

  // CLK to high
  pinMode(m_pinClk, INPUT);
  bitDelay();
  uint8_t ack = digitalRead(m_pinDIO);
  if (ack == 0)
    pinMode(m_pinDIO, OUTPUT);


  bitDelay();
  pinMode(m_pinClk, OUTPUT);
  bitDelay();

  return ack;
}
As you can see it plays around with changing pin from input to output for 0, 1... Again may work...

But as for daisy chaining from one to the next where the same IO pin on one display is the clock and on another is a data pin. Not sure how well that works... That is if the data to one segment is something like 101010 bits, will it look like 4 clocks to the other segment?

Again sorry not much help here
 
Thank you for such an incredibly quick reply. Indeed you are right about the library I am using. I also tried Digital tube and the same results. Quite by accident I tried powering the board with an external power supply and....shockingly it works. I have tried to use bothUSB and external power supply but this behavior still occurs so I might not be separating the power sources properly. I will try to get a diagram of the wiring but essentially I feed the external 6v through a 7805 voltage regulator. Conenct the ground for the regulator with the teensy's ground and then plug it into the USB. That doesn't work. But if I remove the USB and add the 5v also into the Vin then the circuit and teensy power up and the displays work. Any quick ideas what's hapenning? I dont want to cut the pads on the teensy yet, if I don't have to. I remember to remove the cable connecting Vin to the external power supply so I dont have a double feed but am puuzzled it is not working...
 
Any quick ideas what's hapenning?

Very likely something not connected as intended. Maybe try showing us some photos of how you've actually connected all the parts & wires?

Or maybe use a DC voltmeter to measure the power actually arriving at those displays?
 
Thank you PaulStoffregen. Sorry it took me so long to get back - I had a tremendous amount of difficulty getting this into Fritzing - those RatsNest lines kept on creeping in places unexpected. Finally have a PDF generated. Take a look at the way I am powering the circuit: Instead of a 9v I am actually using a switching brick 6v through the 5v regulator. I probably should put a capacitor between the output voltage pins but that doesnt seem to be the problem:

If I power ONLY from the external power source (depicted as a 9v battery here) then the circuit works well. If I remove the purple jumper cable - the display gets corrupted. I thought I figured out the mixed power sources: USB gets powered by the USB and the displays share a common ground with the USB but get power from the external supply. What am I doing wrong here?

Wiring Diagram v4_bb.jpg

Notice how I alternate clock and DIO on the displays. Looks like this is how Grove set up their breakout board (sharing clock and data across displays). BTW - by "corrupt" I mean one display works fine, another one (sharing clock/dio) shows 1 of the four digits sent to it, but in the wrong position, and a third seems fine.
 
Is sharing the CLK & DIO pin a valid way to connect these products? I do not know the details of how these work, but this seems suspicious...

Teensy 3.6 has plenty of digital pins. Maybe giving each Grove its own pair of pins, not shared with any others, would be a good thing to try?
 
I wondered the same as maybe the data pins by one display will confuse the other display thinking that it has a clock signal going... Maybe works on slower processors as maybe a gap in time where maybe the one displays processor times out the logical partial byte...
 
Folks - I made it work. You can actually share pairs of pins CLK/DATA. Here is a picture of my setup:

7segs.jpg

As you can see I have six 7-segment displays connected. I printed my own PCB but the wiring is as follows:

pin 33 = Display #1 DIO
pin 34 = Display #1 DIO / Display #2 CLK
pin 36 = Display #2 DIO / Display #3 CLK
pin 37 = Display #3 DIO / Display #4 CLK
pin 38 = Display #4 DIO / Display #5 CLK
pin 38 = Display #5 DIO / Display #6 CLK
pin 39 = Display #6 DIO

This way I am using 7 pins to operate 6 displays (instead of 12 pins or 6 pairs of CLK/DIO)

My board makes the connections and uses Grove-style connections for the 7segments and a 5x2 connector to the arduino.

If you want to purchase the breakout board let me know.
 
Status
Not open for further replies.
Back
Top