I’ve got a Nokia LCD shield that is working perfectly fine as long as it is the only device sitting on an ARDUINO.
I am now trying to make the Nokia LCD shield (A) work together with another board in development (B).
Both boards (A & B) use the SPI bus where SCLK, MOSI and MISO PINs are shareable. Also both boards use PIN 10 - but I need to keep PIN 10 reserved for the board in development(B).
Therefore I am trying to relocate PIN 10 for the NOKIA LCD shield (A) to some other PIN available.
At the moment I can make out 2 options (other suggestions are most welcome):
a) Move PIN 10 to digital PIN 4
b) with the aid of GPIO, move PIN 10 to analogue PIN 4.
Let’s look at option a) first.
The NOKIA LCD shield uses the library ‘PCF8833.h’ where PIN definitions currently occur like in the code below:
/* Pin definition for Arduino boards */ #define CS 10 #define CLK 13 #define DATA 11 #define RESET 9 #define BL_ON 8 #define LCD_CS(x) PORTB= (x)? (PORTB|(1<<PB2)) : (PORTB&~(1<<PB2)) #define LCD_CLK(x) PORTB= (x)? (PORTB|(1<<PB5)) : (PORTB&~(1<<PB5)) #define LCD_DATA(x) PORTB= (x)? (PORTB|(1<<PB3)) : (PORTB&~(1<<PB3)) #define LCD_RESET(x) PORTB= (x)? (PORTB|(1<<PB1)) : (PORTB&~(1<<PB1)) #define LCD_BACKLIGHT(x) PORTB= (x)? (PORTB|(1<<PB0)) : (PORTB&~(1<<PB0))
What would be the code for LCD_CS(x) to move from PB2 (PIN 10) to PD3 (PIN 4)?
I have tried to change the code for LCD_CS like below, but this did not work.
#define LCD_CS(x) PORTD= (x)? (PORTD|(1<<PD3)) : (PORTD&~(1<<PD3))
What would be the proper syntax to move PIN 10 to PIN 4?
Option b) make use of GPIO:
I was told that:
The SS pin for SPI port, is the slave select pin. It is used when the ATMEGA168 is used as a SPI slave. In your case, the ATMEGA168 is used as a SPI master, so you can choose any GPIO pin as a SPI select pin. Just pull the GPIO pin low, before you do SPI transmission; and pull it high, when SPI finish transmission.
Meanwhile by searching and reading the I/O tutorials I understand both options in principle, but I have not much idea how to write the code so that it functions properly, especially since PIN 10 is defined in the library for the NOKIA LCD shield.
The solution envisioned is nicely published in Wikipedia describing the SPI bus.
Suggestions for either solution a) or b) are most welcome.
- The project is published as a whole here: http://www.halo-photographs.com/remote-shutter-release-timer
- The sketch I have modified & use is here: http://www.halo-photographs.com/remote-shutter-release-timer/the-arduino-code.html
- The NOKIA LCD shield and its sample code are here: http://www.nuelectronics.com/estore/index.php?main_page=product_info&cPath=1&products_id=10
- I started with ARDUINO only a few months ago, therfore I am on beginner level.
Thanks for questions and feedback, Hans.