using 2 spi devices together - tft display + shift registers

OK. But shiftPWM never "finishes" once it's started. It always runs. You can't turn it off.

Use different pins for the shift register.

MorganS:
Use different pins for the shift register.

I did. and it still not working! that whats weird. even when I am not using spi for the shift registers by defining SHIFTPWM_NOSPI, there is still something in the shiftPWM.start() calling that makes problems with the display. and now I think that thing is the timer because as you said - it can't stop. so I just need to find a way to detect when the library is between to cycles of shifting out and in that window print stuff on the display.

Show your current code.

MorganS:
Show your current code.

You can find it in the first page, in the third post.

Reply #2 is using SPI, not any other pins.

MorganS:
Reply #2 is using SPI, not any other pins.

Correct, sorry.
I just uncomment these three lines in the code and all the other stuff is the same:

//#define SHIFTPWM_NOSPI
//const int ShiftPWM_dataPin = 8;
//const int ShiftPWM_clockPin = 13;

13 is one of the SPI pins. You can't use that pin for both.

Edit: 13 is not SPI on a MEGA but I don't think you're using a MEGA.

MorganS:
13 is one of the SPI pins. You can’t use that pin for both.

oh is it 13? in my code it’s 5… well maybe I forgot about few edits and changes…
Here is the current code, most of it is the same as before(and again, ignore the shift in part…):

//int inLatchPin = 3;
//int inDataPin = 4;
//int inClockPin = 2;

int colorData[8][3] = {
  {0, 0, 255},
  {0, 255, 0},
  {255, 0, 0},
  {255, 0, 255},
  {255, 255, 0},
  {0, 255, 255},
  {155, 155, 155},
  {255, 255, 255}
};

byte switchVar1 = 72;

//Main Display Stuff
#include <SPI.h>
#include <Adafruit_GFX.h>
#include <TFT_ILI9163C.h>
#define white 0xFFFF
#define displayCS 10
#define displayRST 8
#define displayDC 9
TFT_ILI9163C mainDisplay = TFT_ILI9163C(displayCS, displayRST, displayDC);

//ShiftPWM Library Stuff
const int ShiftPWM_latchPin = 5;
#define SHIFTPWM_NOSPI
const int ShiftPWM_dataPin = 7;
const int ShiftPWM_clockPin = 8;
const bool ShiftPWM_invertOutputs = true;
const bool ShiftPWM_balanceLoad = false;
#include <ShiftPWM.h>
unsigned char maxBrightness = 255;
unsigned char pwmFrequency = 75;
int numRegisters = 3;
int numRGBleds = numRegisters*8/3;

void setup() {
  Serial.begin(9600);
  /*
  pinMode(inLatchPin, OUTPUT);
  pinMode(inClockPin, OUTPUT); 
  pinMode(inDataPin, INPUT);
  */
  mainDisplay.begin();
  mainDisplay.fillScreen();
  
  ShiftPWM.SetAmountOfRegisters(numRegisters);
  ShiftPWM.SetPinGrouping(1);
  ShiftPWM.Start(pwmFrequency,maxBrightness);
}

void loop() {
  /*
  //shift in
  digitalWrite(inLatchPin, HIGH);
  digitalWrite(inLatchPin, LOW);

  switchVar1 = shiftIn(inDataPin, inClockPin);
  Serial.println(switchVar1, BIN);
  Serial.println("-------------------");
  */

  //Display Drawing
  testText();
  delay(50);
  
  //LED control
  
  if(tempColorDifference > 0){
    for(int i = 0; i < numRGBleds; i++){
      ShiftPWM.SetRGB(i, colorData[i][0], colorData[i][1], colorData[i][2]);
    }
  }
}

byte shiftIn(int myDataPin, int myClockPin) { 
  int i;
  int temp = 0;
  int pinState;
  byte myDataIn = 0;

  pinMode(myClockPin, OUTPUT);
  pinMode(myDataPin, INPUT);

  for (i=7; i>=0; i--) {
    digitalWrite(myClockPin, 0);
    temp = digitalRead(myDataPin);
    if (temp) {
      pinState = 1;
      myDataIn = myDataIn | (1 << i);
    }
    else {
      pinState = 0;
    }

    digitalWrite(myClockPin, 1);

  }
  return myDataIn;
}

unsigned long testText() {
  mainDisplay.setCursor(29, 63);
  mainDisplay.setTextColor(white);  
  mainDisplay.setTextSize(1);
  mainDisplay.println("Hello World!");
}

Hope it will help troubleshooting.

Now you've got pin 8 doing double-duty. It may help to write down all your pins in a notebook or spreadsheet to keep track of which one is doing what. This is really useful when you need to add another function and you are looking for an available I2C pin or something special.

...And that's why we always ask for your latest code. We expect that you changed something since last night.

MorganS:
Now you’ve got pin 8 doing double-duty.

It was a long time, but I am back again.
Now, after I wrote down a table of the connections, the display almost works. the lcd was just flickering with white lines, but you can still see text and shapes.

About the LEDs… even when I commented the parts which are not related to the shiftPWM from the code the leds just was off. after that, I rewired everything in the circuit and it worked! problem solved, tho the shiftPWM is not using the SPI communication. but I am still happy with what I’ve got. the display is sharp and the LEDs are working as expected.

I want to thank very much to everyone helped me figure out this problem, I don’t think anyonr used these two things together.

also look at this page:
http://henrysbench.capnfatz.com/henrys-bench/arduino-displays/arduino-1-44-in-spi-tft-display-tutorial/
The lcd code is not mine, I got it from there.

the shiftPWM is by elco jacobs.

For anyone who will see this page in the future you can use this code (because I belive nothing has to be done twice):

//int inLatchPin = 3;
//int inDataPin = 4;
//int inClockPin = 2;

int colorData[8][3] = {
  {0, 0, 255},
  {0, 255, 0},
  {255, 0, 0},
  {255, 0, 255},
  {255, 255, 0},
  {0, 255, 255},
  {155, 155, 155},
  {255, 255, 255}
};

byte switchVar1 = 72;

//Main Display Stuff
#include <SPI.h>
#include <Adafruit_GFX.h>
#include <TFT_ILI9163C.h>
#define white 0xFFFF
#define displayCS 10
#define displayRST 9
#define displayDC 8
TFT_ILI9163C mainDisplay = TFT_ILI9163C(displayCS, displayRST, displayDC);

//ShiftPWM Library Stuff
const int ShiftPWM_latchPin = 5;
#define SHIFTPWM_NOSPI
const int ShiftPWM_dataPin = 7;
const int ShiftPWM_clockPin = 6;
const bool ShiftPWM_invertOutputs = true;
const bool ShiftPWM_balanceLoad = false;
#include <ShiftPWM.h>
unsigned char maxBrightness = 255;
unsigned char pwmFrequency = 75;
int numRegisters = 3;
int numRGBleds = numRegisters*8/3;

void setup() {
  Serial.begin(9600);
  /*
  pinMode(inLatchPin, OUTPUT);
  pinMode(inClockPin, OUTPUT); 
  pinMode(inDataPin, INPUT);
  */
  mainDisplay.begin();
  
  ShiftPWM.SetAmountOfRegisters(numRegisters);
  ShiftPWM.SetPinGrouping(1);
  ShiftPWM.Start(pwmFrequency,maxBrightness);
}

void loop() {
  /*
  //shift in
  digitalWrite(inLatchPin, HIGH);
  digitalWrite(inLatchPin, LOW);

  switchVar1 = shiftIn(inDataPin, inClockPin);
  Serial.println(switchVar1, BIN);
  Serial.println("-------------------");
  */

  //Display Drawing
  testText();
  
  //LED control
  for(int i = 0; i < numRGBleds; i++){
    ShiftPWM.SetRGB(i, colorData[i][0], colorData[i][1], colorData[i][2]);
  }
  
}

byte shiftIn(int myDataPin, int myClockPin) { 
  int i;
  int temp = 0;
  int pinState;
  byte myDataIn = 0;

  pinMode(myClockPin, OUTPUT);
  pinMode(myDataPin, INPUT);

  for (i=7; i>=0; i--) {
    digitalWrite(myClockPin, 0);
    temp = digitalRead(myDataPin);
    if (temp) {
      pinState = 1;
      myDataIn = myDataIn | (1 << i);
    }
    else {
      pinState = 0;
    }

    digitalWrite(myClockPin, 1);

  }
  return myDataIn;
}

unsigned long testText() {
  mainDisplay.setCursor(29, 63);
  mainDisplay.setTextColor(white);  
  mainDisplay.setTextSize(1);
  mainDisplay.println("Hello World!");
}

Thanks for the feedback! Good to know it all worked out.