Author Topic: RFduino with Adafruit 1.8" 18-bit color TFT LCD display (ST7735R)  (Read 12191 times)

program114

  • RFduino Newbie
  • *
  • Posts: 3
  • Karma: +1/-0
    • View Profile
I had some fun getting the Adafruit 1.8" 18-bit color TFT LCD display https://www.adafruit.com/products/358 driver working w/ RFduino. This required a few changes to their ST7735R driver to use the RFduino NRF_GPIO registers.

If there's any interest I'd be happy to share the code (or maybe do a pull request to their github source).

Their graphics demo runs really well on the RFduino's M0. Much faster than on my UNO.


The SD card on the breakout board doesn't work out of the box, so the next step will be looking into that. Anyone know how this differs from the RFduino MicroSD shield?

RFadmin

  • Administrator
  • *****
  • Posts: 77
  • Karma: +9/-2
    • View Profile
Re: RFduino with Adafruit 1.8" 18-bit color TFT LCD display (ST7735R)
« Reply #1 on: December 05, 2013, 05:20:42 PM »
Very cool! Feel free to share your code here  :)

matsk

  • RFduino Jr. Member
  • **
  • Posts: 59
  • Karma: +1/-0
    • View Profile
    • Tinnio IT Konsulting
Re: RFduino with Adafruit 1.8" 18-bit color TFT LCD display (ST7735R)
« Reply #2 on: December 06, 2013, 01:14:43 AM »
RFduino and Adafruit uses SPI.

The Adafruit TFT/SD card uses different pins for CS for the TFT and a different for the SD card.

I Hope that clarified it?!

/Mats



RFduino SD card shield schematic:

PDFs: http://forum.rfduino.com/index.php?topic=15.0

Adafruits:


Original: http://learn.adafruit.com/system/assets/assets/000/001/903/medium800/18tftback.jpeg
« Last Edit: December 06, 2013, 01:20:13 AM by matsk »

edorphy

  • RFduino Full Member
  • ***
  • Posts: 86
  • Karma: +0/-0
    • View Profile
Re: RFduino with Adafruit 1.8" 18-bit color TFT LCD display (ST7735R)
« Reply #3 on: December 29, 2013, 12:13:39 PM »
Program114, I would love to get a copy of your modified driver as I was about to buy one of these handy displays.  :D

RF admins: Is there a repository for user contributed code or is the code examples forum section the best place to share code?

AKA

  • RFduino Jr. Member
  • **
  • Posts: 49
  • Karma: +2/-0
    • View Profile
Re: RFduino with Adafruit 1.8" 18-bit color TFT LCD display (ST7735R)
« Reply #4 on: January 30, 2014, 02:23:21 PM »
I'd also love to see your modified driver, would it be possible just to attach it to this thread?

Thanks so much for sharing your work!

AKA

fortolano

  • RFduino Newbie
  • *
  • Posts: 6
  • Karma: +0/-0
    • View Profile
Re: RFduino with Adafruit 1.8" 18-bit color TFT LCD display (ST7735R)
« Reply #5 on: May 29, 2014, 06:09:04 PM »
Hi Program114,

Just received my Adafruit TFT display and I'd like to test it with my RFduino.  Just wondering if you'd be kind enough to share your code and drivers, etc.

Thanks in advance

Flavio

program114

  • RFduino Newbie
  • *
  • Posts: 3
  • Karma: +1/-0
    • View Profile
Re: RFduino with Adafruit 1.8" 18-bit color TFT LCD display (ST7735R)
« Reply #6 on: May 30, 2014, 01:16:25 PM »
Sorry for the ridiculous delay in my response.... I put this project on the back burner while I was in the process of moving. I haven't had a chance to look closer at the SD card, but attached is the original patched code. Hopefully this will be useful to someone.

This is the patch (based on the Adafruit github code https://github.com/adafruit/Adafruit-ST7735-Library) for those that want to manually apply it:

Code: [Select]
diff U3 Adafruit_ST7735.cpp Adafruit_ST7735.cpp
--- Adafruit_ST7735.cpp Mon Jan 19 14:26:36 1970
+++ Adafruit_ST7735.cpp Mon Jan 19 14:26:36 1970
@@ -134,6 +134,46 @@
 }
 #endif //#if defined(__SAM3X8E__)
 
+#if defined(RFDUINO)
+inline void Adafruit_ST7735::spiwrite(uint8_t c) {
+
+//  Serial.println(c, HEX);
+
+  if (hwSPI) {
+      SPI.transfer(c);
+  } else {
+    // Fast SPI bitbang swiped from LPD8806 library
+    for(uint8_t bit = 0x80; bit; bit >>= 1) {
+      if(c & bit) NRF_GPIO->OUTSET = datapinmask;
+      else        NRF_GPIO->OUTCLR = datapinmask;
+      NRF_GPIO->OUTSET = clkpinmask;
+      NRF_GPIO->OUTCLR = clkpinmask;
+    }
+  }
+}
+
+void Adafruit_ST7735::writecommand(uint8_t c) {
+  NRF_GPIO->OUTCLR =  rspinmask;
+  NRF_GPIO->OUTCLR  =  cspinmask;

+// Serial.print("C ");
+  spiwrite(c);

+  NRF_GPIO->OUTSET  =  cspinmask;
+}
+
+
+void Adafruit_ST7735::writedata(uint8_t c) {
+  NRF_GPIO->OUTSET =  rspinmask;
+  NRF_GPIO->OUTCLR  =  cspinmask;

+//  Serial.print("D ");
+  spiwrite(c);

+  NRF_GPIO->OUTSET  =  cspinmask;
+}
+#endif //#if defined(RFDUINO)
+
 
 // Rather than a bazillion writecommand() and writedata() calls, screen
 // initialization commands and arguments are organized in these tables
@@ -325,8 +365,12 @@
 #if defined(__SAM3X8E__)
     SPI.setClockDivider(21); // 4 MHz
     //Due defaults to 4mHz (clock divider setting of 21), but we'll set it anyway
-#endif    SPI.setBitOrder(MSBFIRST);
+#endif
+#if defined(RFDUINO)
+#else
+    SPI.setBitOrder(MSBFIRST);
     SPI.setDataMode(SPI_MODE0);
+#endif
   } else {
     pinMode(_sclk, OUTPUT);
     pinMode(_sid , OUTPUT);
@@ -348,6 +392,10 @@
     clkport ->PIO_CODR  |=  clkpinmask; // Set control bits to LOW (idle)
     dataport->PIO_CODR  |=  datapinmask; // Signals are ACTIVE HIGH
 #endif
+#if defined(RFDUINO)
+   NRF_GPIO->OUTCLR |= clkpinmask;
+   NRF_GPIO->OUTCLR |= datapinmask;
+#endif
   }
 
   // toggle RST low to reset; CS low so it'll listen to us
@@ -357,6 +405,9 @@
 #if defined(__SAM3X8E__)
   csport ->PIO_CODR  |=  cspinmask; // Set control bits to LOW (idle)
 #endif
+#if defined(RFDUINO)
+   NRF_GPIO->OUTCLR |= cspinmask;
+#endif
   if (_rst) {
     pinMode(_rst, OUTPUT);
     digitalWrite(_rst, HIGH);
@@ -428,7 +479,11 @@
   rsport->PIO_SODR |=  rspinmask;
   csport->PIO_CODR  |=  cspinmask;
 #endif

+#if defined(RFDUINO)
+  NRF_GPIO->OUTSET =  rspinmask;
+  NRF_GPIO->OUTCLR  =  cspinmask;
+#endif
+
   spiwrite(color >> 8);
   spiwrite(color);
 
@@ -438,6 +493,9 @@
 #if defined(__SAM3X8E__)
   csport->PIO_SODR  |=  cspinmask;
 #endif
+#if defined(RFDUINO)
+  NRF_GPIO->OUTSET  =  cspinmask;
+#endif
 }
 
 void Adafruit_ST7735::drawPixel(int16_t x, int16_t y, uint16_t color) {
@@ -454,7 +512,11 @@
   rsport->PIO_SODR |=  rspinmask;
   csport->PIO_CODR  |=  cspinmask;
 #endif

+#if defined(RFDUINO)
+  NRF_GPIO->OUTSET =  rspinmask;
+  NRF_GPIO->OUTCLR  =  cspinmask;
+#endif
+
   spiwrite(color >> 8);
   spiwrite(color);
 
@@ -464,6 +526,9 @@
 #if defined(__SAM3X8E__)
   csport->PIO_SODR  |=  cspinmask;
 #endif
+#if defined(RFDUINO)
+  NRF_GPIO->OUTSET  =  cspinmask;
+#endif
 }
 
 
@@ -484,16 +549,25 @@
   rsport->PIO_SODR |=  rspinmask;
   csport->PIO_CODR  |=  cspinmask;
 #endif
+#if defined(RFDUINO)
+  NRF_GPIO->OUTSET =  rspinmask;
+  NRF_GPIO->OUTCLR  =  cspinmask;
+#endif
+
   while (h--) {
     spiwrite(hi);
     spiwrite(lo);
   }
+
 #ifdef __AVR__
   *csport |= cspinmask;
 #endif
 #if defined(__SAM3X8E__)
   csport->PIO_SODR  |=  cspinmask;
 #endif
+#if defined(RFDUINO)
+  NRF_GPIO->OUTSET  =  cspinmask;
+#endif
 }
 
 
@@ -514,6 +588,10 @@
   rsport->PIO_SODR |=  rspinmask;
   csport->PIO_CODR  |=  cspinmask;
 #endif
+#if defined(RFDUINO)
+  NRF_GPIO->OUTSET =  rspinmask;
+  NRF_GPIO->OUTCLR  =  cspinmask;
+#endif
   while (w--) {
     spiwrite(hi);
     spiwrite(lo);
@@ -524,6 +602,9 @@
 #if defined(__SAM3X8E__)
   csport->PIO_SODR  |=  cspinmask;
 #endif
+#if defined(RFDUINO)
+  NRF_GPIO->OUTSET  =  cspinmask;
+#endif
 }
 
 
@@ -554,6 +635,11 @@
   rsport->PIO_SODR |=  rspinmask;
   csport->PIO_CODR  |=  cspinmask;
 #endif
+#if defined(RFDUINO)
+  NRF_GPIO->OUTSET =  rspinmask;
+  NRF_GPIO->OUTCLR  =  cspinmask;
+#endif
+
   for(y=h; y>0; y--) {
     for(x=w; x>0; x--) {
       spiwrite(hi);
@@ -566,6 +652,9 @@
 #endif
 #if defined(__SAM3X8E__)
   csport->PIO_SODR  |=  cspinmask;
+#endif
+#if defined(RFDUINO)
+  NRF_GPIO->OUTSET  =  cspinmask;
 #endif
 }
 
diff U3 Adafruit_ST7735.h Adafruit_ST7735.h
--- Adafruit_ST7735.h Mon Jan 19 14:26:36 1970
+++ Adafruit_ST7735.h Mon Jan 19 14:26:36 1970
@@ -38,6 +38,13 @@
 #ifdef __AVR__
   #include <avr/pgmspace.h>
 #endif
+#if defined(RFDUINO)
+  #define digitalPinToBitMask(P)     ( 1UL << P )
+  #define PROGMEM
+  #define pgm_read_byte(addr) (*(const unsigned char *)(addr))
+  #define pgm_read_word(addr) (*(const unsigned short *)(addr))
+  typedef unsigned char prog_uchar;
+#endif
 
 // some flags for initR() :(
 #define INITR_GREENTAB 0x0
@@ -159,6 +166,12 @@
             datapinmask, clkpinmask, cspinmask, rspinmask,
             colstart, rowstart; // some displays need this changed
 #endif //  #if defined(__SAM3X8E__)
+
+#if defined(RFDUINO)
+  uint32_t  _cs, _rs, _rst, _sid, _sclk,
+           datapinmask, clkpinmask, cspinmask, rspinmask,
+           colstart, rowstart; // some displays need this changed
+#endif
   
 };

Nephilim

  • RFduino Newbie
  • *
  • Posts: 1
  • Karma: +0/-0
    • View Profile
Re: RFduino with Adafruit 1.8" 18-bit color TFT LCD display (ST7735R)
« Reply #7 on: June 02, 2014, 12:13:59 AM »
I just connected up the sainsmart st7735/TFT LCD using this method and realized that this screen and adding the SD Card would take up all of the GPIO pins. That doesn't leave the device able to do anything useful.  Am I missing something?  Why are there so few GPIO pins on this device?  I would at least want a few inputs to connect to some fairly fast ADCs. 

I guess I could connect the CS from the LCD to an an inverter gate and use it to drive the SD card CS but that still leaves me with very little GPIO.  What is the normal way to open this up?  An analog multiplexer? That adds another device to the eventual footprint that seems unnecessary.  Is this a device limitation or am I not seeing something?

program114

  • RFduino Newbie
  • *
  • Posts: 3
  • Karma: +1/-0
    • View Profile
Re: RFduino with Adafruit 1.8" 18-bit color TFT LCD display (ST7735R)
« Reply #8 on: June 05, 2014, 12:29:47 PM »
Maybe others have already figured this out... but here's how I got the SD card on the Adafruit board working. Hopefully this helps w/ Nephilim's issue too.

RFduino uses GPIO 0&1 for the UART RX/TX. Since we are limited on the number of GPIO's available, we need to disable the serial connection and repurpose a GPIO for our SD_CS.

To do this you can simply comment out the Serial.begin(9600) call in the source. I also added a call to UART0_Stop() for safety.

After this change I set the SD_CS = 1 in the Adafruit bitmap example code (along with copying TFT pins from the graphics test code), wired the SD_CS pin to GPIO1, and was rewarded with a nice parrot image on the display.



This leaves GPIO0 free for whatever. (Obviously it's possible to make library modifications to enable the use of a mux/inverter/etc. to expand the number of GPIO's... but I'm not going to experiment with this.)

On an unrelated note, I found that the RFduino library has changed since I implemented my patch. It will compile with RFduino library 2.0.2 if you comment out the include of wiring_private.h near the top of Adafruit_ST7735.cpp.

keithtzs

  • RFduino Newbie
  • *
  • Posts: 1
  • Karma: +0/-0
    • View Profile
Re: RFduino with Adafruit 1.8" 18-bit color TFT LCD display (ST7735R)
« Reply #9 on: November 17, 2014, 07:45:07 PM »
When i upload the sketch to the Arduino IDE, my board just keep repeating failure
This is the error message, something to do with the C++ code
Arduino: 1.5.8 (Windows 7), Board: "RFduino"

C:\Users\keith\Documents\Arduino\libraries\Adafruit_ST7735\Adafruit_ST7735.cpp:22:28: fatal error: wiring_private.h: No such file or directory
 #include "wiring_private.h"
                            ^
compilation terminated.
Error compiling.

Can someone help me with this. Im like stuck at this step and i cant start up the screen either.

Help will be greatly appreciated. Thanks

SuperJonotron

  • RFduino Newbie
  • *
  • Posts: 9
  • Karma: +0/-0
    • View Profile
Re: RFduino with Adafruit 1.8" 18-bit color TFT LCD display (ST7735R)
« Reply #10 on: January 12, 2015, 09:48:36 PM »
I am also experiencing the wiring_private.h issue.  I downloaded your modified library and also added the GFX library to my arduino directory.  I tried to load the example graphicstest_highspeed sketch but get that error.  Is it possible you can upload your sketch that also includes accessing the SD card and image?  You've definitely managed to figure something out other than just a patched library that isn't as straight forward as it seems for at least a few of us.

GunnarRacing

  • RFduino Newbie
  • *
  • Posts: 19
  • Karma: +0/-0
    • View Profile
Re: RFduino with Adafruit 1.8" 18-bit color TFT LCD display (ST7735R)
« Reply #11 on: January 13, 2015, 12:19:12 AM »
Quote
...\Arduino\libraries\Adafruit_ST7735\Adafruit_ST7735.cpp:22:28: fatal error: wiring_private.h: No such file or directory
 #include "wiring_private.h"
                            ^
compilation terminated.
Error compiling.

+1

Looks really cool! Would love to get past the "wiring_private.h" error.

Rick In (Plano) Texas

SuperJonotron

  • RFduino Newbie
  • *
  • Posts: 9
  • Karma: +0/-0
    • View Profile
Re: RFduino with Adafruit 1.8" 18-bit color TFT LCD display (ST7735R)
« Reply #12 on: January 14, 2015, 06:40:37 PM »
On an unrelated note, I found that the RFduino library has changed since I implemented my patch. It will compile with RFduino library 2.0.2 if you comment out the include of wiring_private.h near the top of Adafruit_ST7735.cpp.

I found this to also fixed my error. 

Not sure how to associate the RFDuino pins to the display so if anybody can update with that info that would be very helpful.  Supporting code would be great.  Was looking at the spitftbitmap example that draws the parrot picture that comes in the unpatched AdrafruitSt7735 library download since that accesses the SD card to draw the image.

u00mem9

  • RFduino Newbie
  • *
  • Posts: 2
  • Karma: +0/-0
    • View Profile
Re: RFduino with Adafruit 1.8" 18-bit color TFT LCD display (ST7735R)
« Reply #13 on: April 26, 2016, 03:42:50 PM »
Bringing this back...because Simblee also needs a patch of some sort to work with this library...Is this trivial for someone more expert than me?

astrodidge

  • RFduino Newbie
  • *
  • Posts: 1
  • Karma: +0/-0
    • View Profile
Re: RFduino with Adafruit 1.8" 18-bit color TFT LCD display (ST7735R)
« Reply #14 on: February 23, 2017, 01:20:20 AM »
Thanks! That helped a lot used this example to attach a OLED with the SSD1351 driver to RFduino