Problem With LCD ST7565 used with SPI Digital POT

Hi

I am currently trying to add a MCP4131 to a board with a Topway LCD using the ST7565 Chipset.
I can Seperatly either use the LCD , Or only the MCP4131 via SPI

it Seems that the ST7565 Library is Clashing with the SPI Library.

Does anyone know a workaround for this..??

Please See my code below :

#include <ST7565.h>
#include <SPI.h>

#define SS 18
#define LED 2 // LED connected to D2 Pin1(PD3)

void WritePot(int i);

// pin 4 - Serial data out (SID)
// pin 5 - Serial clock out (SCLK)
// pin 8 - Data/Command select (RS or A0)
// pin 9 - LCD reset (RST)
// pin 10 - LCD chip select (CS)
ST7565 glcd(4, 5, 8, 9, 10);

#define LOGO16_GLCD_HEIGHT 16
#define LOGO16_GLCD_WIDTH 16

void setup()
{
pinMode(LED,OUTPUT);
pinMode(SS,OUTPUT);

// Init SPI
SPI.begin();

// initialize and set the contrast to 0x18
glcd.begin(0x09);
glcd.display(); // show splashscreen

}

void loop()
{

int i;

for(i=0;i<100;i++)
{
WritePot(i);
delay(10);
}

digitalWrite(LED,HIGH);
delay(50);
digitalWrite(LED,LOW);
delay(50);
}

void WritePot(int i)
{

digitalWrite(SS,LOW);
SPI.transfer(0);
SPI.transfer(i);
digitalWrite(SS,HIGH);

}

This has been a week for shiftOut. ShiftOut will not work on the SPI bus pins after your sketch calls SPI.begin.

This is from the library in the file ST7565.cpp.

inline void ST7565::spiwrite(uint8_t c) {
  shiftOut(sid, sclk, MSBFIRST, c);

Either change the pins off the SPI pins or change this to SPI.transfer;

inline void ST7565::spiwrite(uint8_t c) {
  SPI.transfer(c);

You probably will need to include SPI.h in the same file, and call SPI.begin() in setup.

You need to set pin 10 as an OUTPUT pin, to make the Arduino the SPI master. You may not want to use that as the slave select pin for the LCD.

SurferTim:
This has been a week for shiftOut. ShiftOut will not work on the SPI bus pins after your sketch calls SPI.begin.

This is from the library in the file ST7565.cpp.

inline void ST7565::spiwrite(uint8_t c) {

shiftOut(sid, sclk, MSBFIRST, c);




Either change the pins off the SPI pins or change this to SPI.transfer;


inline void ST7565::spiwrite(uint8_t c) {
 SPI.transfer(c);




You probably will need to include SPI.h in the same file, and call SPI.begin() in setup.

Thank you for the fast reply. Does this mean that the SPI Digital Pot(MCP3141) and the ST7565 LCD display must use the same Pins for MOSI ; SCLK and (MISO) ?

I am Using an Arduino Uno and Used the Pins As Follows:

// pin D4 - LCD :: Serial data out (SID)
// pin D5 - LCD :: Serial clock out (SCLK)
// pin D8 - LCD :: Data/Command select (RS or A0)
// pin D9 - LCD :: reset (RST)
// pin D10 - LCD :: chip select (CS)

// Pin D11(MOSI) - DIGITAL POT SDI
// Pin D13(SCK) - DIGITAL POT SCK
// PIN D18(A4) - DIGITAL POT CS

Does this mean that the SPI Digital Pot(MCP3141) and the ST7565 LCD display must use the same Pins for MOSI ; SCLK and (MISO) ?

Yes, but not only that. They both must use the SPI library. The shiftOut function will not work on the SPI bus pins once the sketch calls SPI.begin.

And each must have a separate slave select pin.