arduino pins

does it matter which arduino pins i connect to oled ssd1306 if i define the pins in my code

(i am using arduino nano and cant get my oled working, i attached a bluetooth module and a an oled)

// Include Libraries
#include "Arduino.h"
#include "BTHC05.h"
#include "Wire.h"
#include "SPI.h"
#include "Adafruit_SSD1306.h"
#include "Adafruit_GFX.h"
#include "Button.h"

// Pin Definitions
#define BTHC05_PIN_TXD 3
#define BTHC05_PIN_RXD 10
#define OLED128X64_PIN_RST 5
#define OLED128X64_PIN_DC 4
#define OLED128X64_PIN_CS 2
#define TOGGLESWITCH_PIN_2 6

// Global variables and defines

// object initialization
BTHC05 bthc05(BTHC05_PIN_RXD,BTHC05_PIN_TXD);
#define SSD1306_LCDHEIGHT 64
Adafruit_SSD1306 oLed128x64(OLED128X64_PIN_DC, OLED128X64_PIN_RST, OLED128X64_PIN_CS);
Button ToggleSwitch(TOGGLESWITCH_PIN_2);

// define vars for testing menu
const int timeout = 10000; //define timeout of 10 sec
char menuOption = 0;
long time0;

// Setup the essentials for your circuit to work. It runs first every time your circuit is powered with electricity.
void setup()
{
// Setup Serial which is useful for debugging
// Use the Serial Monitor to view printed messages
Serial.begin(9600);
while (!Serial) ; // wait for serial port to connect. Needed for native USB
Serial.println("start");

bthc05.begin(9600);
//This example uses HC-05 Bluetooth to communicate with an Android device.
//Download bluetooth terminal from google play store, https://play.google.com/store\/apps/details?id=Qwerty.BluetoothTerminal&hl=en
//Pair and connect to 'HC-05', the default password for connection is '1234'.
//You should see this message from your arduino on your android device
bthc05.println("Bluetooth On....");
oLed128x64.begin(SSD1306_SWITCHCAPVCC); // by default, we'll generate the high voltage from the 3.3v line internally! (neat!)
oLed128x64.clearDisplay(); // Clear the buffer.
oLed128x64.display();
ToggleSwitch.init();
menuOption = menu();

}

// Main logic of your circuit. It defines the interaction between the components you selected. After setup, it runs over and over again, in an eternal loop.
void loop()
{

if(menuOption == '1') {
// HC - 05 Bluetooth Serial Module - Test Code
String bthc05Str = "";
//Receive String from bluetooth device
if (bthc05.available())
{
//Read a complete line from bluetooth terminal
bthc05Str = bthc05.readStringUntil('\n');
// Print raw data to serial monitor
Serial.print("BT Raw Data: ");
Serial.println(bthc05Str);
}
//Send sensor data to Bluetooth device
bthc05.println("PUT YOUR SENSOR DATA HERE");
}
else if(menuOption == '2') {
// Monochrome 1.3 inch 128x64 OLED graphic display - Test Code
oLed128x64.setTextSize(1);
oLed128x64.setTextColor(WHITE);
oLed128x64.setCursor(0, 10);
oLed128x64.clearDisplay();
oLed128x64.println("Circuito.io Rocks!");
oLed128x64.display();
delay(1);
oLed128x64.startscrollright(0x00, 0x0F);
delay(2000);
oLed128x64.stopscroll();
delay(1000);
oLed128x64.startscrollleft(0x00, 0x0F);
delay(2000);
oLed128x64.stopscroll();
}
else if(menuOption == '3') {
// ToggleSwitch - Test Code
//read Toggle Switch state.
//if Switch is open function will return LOW (0).
//if it is closed function will return HIGH (1).
bool ToggleSwitchVal = ToggleSwitch.read();
Serial.print(F("Val: ")); Serial.println(ToggleSwitchVal);
}

if (millis() - time0 > timeout)
{
menuOption = menu();
}

}

// Menu function for selecting the components to be tested
// Follow serial monitor for instrcutions
char menu()
{

Serial.println(F("\nWhich component would you like to test?"));
Serial.println(F("(1) HC - 05 Bluetooth Serial Module"));
Serial.println(F("(2) Monochrome 1.3 inch 128x64 OLED graphic display"));
Serial.println(F("(3) ToggleSwitch"));
Serial.println(F("(menu) send anything else or press on board reset button\n"));
while (!Serial.available());

// Read data from serial monitor if received
while (Serial.available())
{
char c = Serial.read();
if (isAlphaNumeric(c))
{

if(c == '1')
Serial.println(F("Now Testing HC - 05 Bluetooth Serial Module"));
else if(c == '2')
Serial.println(F("Now Testing Monochrome 1.3 inch 128x64 OLED graphic display"));
else if(c == '3')
Serial.println(F("Now Testing ToggleSwitch"));
else
{
Serial.println(F("illegal input!"));
return 0;
}
time0 = millis();
return c;
}
}
}

Please post your full sketch.

If possible, you should always post code directly in the forum thread as text using code tags:

  • Do an Auto Format (Tools > Auto Format in the Arduino IDE or Ctrl + B in the Arduino Web Editor) on your code. This will make it easier for you to spot bugs and make it easier for us to read.
  • In the Arduino IDE or Arduino Web Editor, click on the window that contains your sketch code.
  • Press "Ctrl + A". This will select all the text.
  • Press "Ctrl + C". This will copy the selected text to the clipboard.
  • In a forum reply here, click on the reply field.
  • Click the </> button on the forum toolbar. This will add the forum's code tags markup to your reply.
  • Press "Ctrl + V". This will paste the sketch between the code tags.
  • Move the cursor outside of the code tags before you add any additional text to your reply.
  • Repeat the above process if your sketch has multiple tabs.

This will make it easy for anyone to look at it, which will increase the likelihood of you getting help.

If the sketch is longer than the 9000 characters maximum allowed by the forum, then it's OK to add it as an attachment. After clicking the "Reply" button, you will see an "Attachments and other settings" link.

When your code requires a library that's not included with the Arduino IDE please post a link (using the chain links icon on the forum toolbar to make it clickable) to where you downloaded that library from or if you installed it using Library Manger (Sketch > Include Library > Manage Libraries in the Arduino IDE or Libraries > Library Manager in the Arduino Web Editor) then say so and state the full name of the library.

Please post a link (using the chain links icon on the forum toolbar to make it clickable) to where you downloaded the SSD1306 library from. Or if you installed it using Library Manger (Sketch > Include Library > Manage Libraries in the Arduino IDE or Libraries > Library Manager in the Arduino Web Editor) then say so and state the full name of the library.

Yes, you can use random pins. But this means you use the bit-bang constructor:

  Adafruit_SSD1306(uint8_t w, uint8_t h, int8_t mosi_pin, int8_t sclk_pin,
    int8_t dc_pin, int8_t rst_pin, int8_t cs_pin);

If you use the hardware SPI constructor, you must use the HW mosi_pin and HW sclk pins

Note that the Adafruit_SSD1306 library has been undergoing changes recently.
Install/Update via the IDE Library Manager.

David.