A few months ago I’d purchased a SainSmart 1.8 SPI LCD Module with MicroSD LED Backlight and it kind of just sat on my dresser waiting for a rainy day. Last weekend it was very rainy and I finally rolled up my sleeves and got it working. I’d gotten some new jumper cables (for arduino, not car) in the mail and made things a lot easier, as all mine were male-male. Now I have a variety of male-male, female-female, and male-female. Kind of sounds like porn categories.
There were a lot of good tutorials on how to get the LCD working, and I was able to get it “Option 1″ going in short order. It was, however, very slow. My next step was to stick in on a breadboard along with one of my Ping sensors so that I could have some data to output. For some reason, I struggled with converting the int value to a char in C++. I’m fairly new with C++ and it seemed to be a royal pain in the ass. What’s more, the Arduino seems to run a rather limitted version of C++.
My next road bump was getting the LCD set up in SPI mode – “Option 2″. It is certainly worth the hastle, as it is much faster. The documentation that I found on Sainsmart’s site gave very good instructions for setting it up in the “slow” mode, but not so much for the fast. It took a little bit of Googling, and some instructions on a German message board for me to get it working. The adafruit learning system site has a good tutorial on the slow mode.
This is the LCD configured for SPI mode. (The wires on the right can be disregarded; they are for the Ping sensor.) You don’t have to use the sensor shield, but if you actually want some data to output to the LCD, you might want some extra gizmos attached, and the breadboard can take up space and make things feel clunky. I’m not going to pretend that I know what these pins do, but this should help get it working if anyone (including me) needs a reference.
CS 10 RES 8 DC 9 SDA 11 SCL 13 # Pretty sure this has to be 13 for Arduino Uno R3 GND GND VCC 5v
And then you can use the code from the example.
#define cs 10 // for MEGAs you probably want this to be pin 53 #define dc 9 #define rst 8 // you can also connect this to the Arduino reset #include <ST7735.h> #include <SPI.h> // Option 1: use any pins but a little slower //ST7735 tft = ST7735(cs, dc, mosi, sclk, rst); // Option 2: must use the hardware SPI pins // (for UNO thats sclk = 13 and sid = 11) and pin 10 must be // an output. This is much faster - also required if you want // to use the microSD card (see the image drawing example) ST7735 tft = ST7735(cs, dc, rst);
That’s it. I did notice, however, that some of the pins seem to become unavailable once the tft is initialized. I tried using pin 12, for example, and it did not work well. Pin 2 did. That’s all I have to say about that.