Freetronics DMD Library Porting Struggles

I’m trying to pair my new Spark with a Freetronics Dot Matrix Display: http://www.freetronics.com/products/dot-matrix-display-32x16-red which requires porting the library (online here: https://github.com/freetronics/DMD2). I didn’t realize it would be so difficult, but shows what I know! I’ve been playing around in the online compiler, trying to get it to even verify. Right now it seems the hardest part is dealing with SPI. The compiler is currently choking on this code in DMD2.cpp:

void SoftDMD::writeSPIData(volatile uint8_t *rows[4], const int rowsize)
{
  volatile port_reg_t *port_clk = (volatile port_reg_t *)portOutputRegister(digitalPinToPort(pin_clk));
  port_reg_t mask_clk = digitalPinToBitMask(pin_clk);
  volatile port_reg_t *port_r_data = (volatile port_reg_t *) portOutputRegister(digitalPinToPort(pin_r_data));
  port_reg_t mask_r_data = digitalPinToBitMask(pin_r_data);

  for(int i = 0; i < rowsize; i++) {
    softSPITransfer(*(rows[3]++), port_r_data, mask_r_data, port_clk, mask_clk);
    softSPITransfer(*(rows[2]++), port_r_data, mask_r_data, port_clk, mask_clk);
    softSPITransfer(*(rows[1]++), port_r_data, mask_r_data, port_clk, mask_clk);
    softSPITransfer(*(rows[0]++), port_r_data, mask_r_data, port_clk, mask_clk);
  }
}

I’m hoping someone with more experience than me can help with the steps needed to get this to work with Spark - from reading around it seems that the direct pin manipulation should be replaced with digitalWrite() commands, but I have know idea where to start.

Can anyone provide me with any pointers?

Thanks!

archimag0, I am at the Maker Faire with the Spark Team but when I get back home Monday I will port the library for you if you don’t mind waiting. :smile:

2 Likes

That’s so kind of you to offer peekay - thank you so much. I can of course wait as long as you need!

archimag​0, I am reviewing the code and I need to know if you wish to use hardware SPI instead of the software SPI? Are you trying to run a specific example that I can look at?

Hi peekay123; at this point I’m just trying to get the examples ( https://github.com/freetronics/DMD2/tree/master/examples ) to run to see that it actually works - once I have those going I plan to start developing my own project. What would the advantages/disadvantages be to hardware vs software?

Ok, so it seems all the examples use “SoftDMD” which is the software SPI. I will switch the examples to hardware SPI and port the library to the Spark so you can test. Stay tuned! :smile:

2 Likes

You rock! Thank you.

@archimag0, I have the library ported and compiling. I find parts to be “sloppy” but I believe we can get it working. I have to go over a couple of items and I will post it on my github later so you can test it. :smile:

UPDATE: I posted the (untested) library on my github. I used the Spark CLI to compile it as a single folder. Easy Peasy.

Things to know: I setup the example to use hadware SPI. The pins connect as follows:

Spark     DMD
 A5        R   (MOSI)
 A3       CLK  (SCK)
 A0       nOE  (A0 supports PWM for brightness other than 255)
 D4        A
 D3        B
 D2       SCK

The SPI clock is set to 4.5MHz. Let me know how it goes!

1 Like

Thanks peekay!! I’ll try and test it tonight or tomorrow. Fingers crossed!

1 Like

@peekay123 I just tested it and… I get a handful of LEDs turning on, but definitely not what was expected: http://imgur.com/7zSrbkV. Ahhhh!

It’s a start! The library is setup to NOT use the hardware timer. Perhaps this is the problem. I may need to put a logic analyzer on the outputs to see what it’s doing. It just means more work :wink:

Yay, work! Well let me know what you need from me…

Just a quick thought–the old software SPI is going to be a lot slower than 4.5MHz. Maybe you should try SPI_CLOCK_DIV64 for 1.125 MHz.

Good luck!

@bko I just tried that - no change unfortunately.

I also just realized that this DMD library is version 2 of the original library here, https://github.com/freetronics/DMD - perhaps the older version will provide some clues?

DMD2 is in beta so that may be an issue. @archimag0 did you check your wiring against the pins I set the defaults to? I will look at porting the older library and perhaps we can go from there. Stand by :wink:

UPDATE: I have the DMD library ported (using the IntervalTimer library to boot!). I will have it on github in the morning… I need sleep!

1 Like

Wow, you work fast! I’ll test it tonight. I did check my wiring several times.

Thanks again!!

@archimag0, the [DMD library][1] is on my github.

!!! NOTE: DMD reads the default SPI CS pin (A2) to see if another device is using the SPI bus. If the value read is not HIGH, the DMD will NOT refresh. This may need to be modified or the CS pin pulled HIGH for the code to function correctly. Keep me posted! :smile:

I just tested the DMD1 library and I get the same result. Hmm…

EDIT: Not sure if this is relevant, but I was playing with the wiring to see if that had anything to do with it, and if I pull the A and B wires and start playing with them it makes different LEDs light up. Something is happening…

@archimag0, I just realized that these are 5V displays! You will need to use level shifters (3.3v to 5V) between the Spark and the Freetronics unit. Are you using level shifters?

Oh shoot! How did I miss that. Good catch! I hope that’s it…