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;
}
}
}