SparkFun Forums 

Where electronics enthusiasts find answers.

For the discussion of Arduino related topics.
By ndthornton
#194014
I am having a problem getting my Arduino Micro Pro to work with an OLED screen.
I am using this library
https://github.com/wonho-maker/Adafruit_SH1106
I am using hardware SPI

Everything works fine if I use the pins specified in the example....

#define OLED_DC 6
#define OLED_CS 7
#define OLED_RESET 8

Unfortunately I am already using these pins for something else.....and specifically the interrupt functionality on these pins so I cannot change them. The only pins that are spare on my board are the Analogue pins A0-A4.

If I use.....

#define OLED_DC 18
#define OLED_CS 19
#define OLED_RESET 20

...which supposedly maps to the analogue pins it doesnt work.

When I looked into the library code I noticed that for speed digitalWrite() is not used to toggle the pins. Instead the ports are accessed directly like this....

csport = portOutputRegister(digitalPinToPort(cs));
cspinmask = digitalPinToBitMask(cs);
dcport = portOutputRegister(digitalPinToPort(dc));
dcpinmask = digitalPinToBitMask(dc);

portOutputRegister(), digitalPinToPort() and digitalPinToBitMask() are arduino functions but it seems they are having trouble accessing Port F (the analogue port)

I cant see any reason why this should be a problem?

Any help greatly appreciated

Thanks
Nick
By jremington
#194030
I don't have a pro micro to test, but my approach would be to replace all those lookup calls with direct digital writes to the port and pin in question.

For example, to set bit 0 in PORTD I would use the statement
PORTD |= 1;

To clear bit 0 in PORTD, I would use the statement
PORTD &= ~1;

To toggle, say bit 5 in PORTD, I would use the less well known statement
PIND ^= (1<<5);

Don't forget to set the appropriate bits in the Data Direction Register, i.e. to set bit 5 of PORTD to output, use
DDRD |= (1<<5);

You need only replace those examples with the bit and port definitions that correspond to pins you want to use.
By ndthornton
#194146
SOLVED

It was the dodgy Chinese clone
bought the Real Micro pro and the Analogue ports work as they should
buy cheap - buy twice!

Dont know how they screwed that up though - the analogue ports are not connected to anything on the schematic except the output pins- unless maybe they were shorted somehow when the chip was soldered on?