OLED stops functioning when I assign D7 (Wemos D1)

Ok I need to test this further to be sure, I’ve been changing more things and its possible that I got this wrong, but perhaps someone knows what is going on. This concerns a Wemos D1 with:

  • OLED SPI (SW, no chip select)

  • a temp sensor,

  • two buttons (up/down)

  • an external LED

  • a relay. (currently not connected)
    This is the layout:

      const int SCL_PIN = Dn5; //D5
      const int SDA_PIN = Dn6; //D6
      const int RES_PIN = Dn1;  //D1
      const int DC_PIN = Dn2;  //D2
      const int BUTTON_UP_PIN = Dn4;        //D4 the pin that the pushbutton is attached to
      const int BUTTON_DO_PIN = Dn8;        //D8 the pin that the pushbutton is attached to
      const int HEATER_RELAY_PIN = 25;       //Dx NOT CONNECTED the pin that the Relay is attached to: LOW LVL TRIGGER (so GRND is ON)
      const int HEATER_LED_PIN = Dn7;       //D7 the pin that the LED is attached to
      const int T_SENSOR_PIN = An0;         //A0 ADC !! (only this pin = (A0)
    

I’ve ‘Dn’ corresponds with ‘D’ on the Wemos board.

THIS WORKS…somewhat, since I have the button up connected to the internal led (and I let that one blink) the up button is virtually pushed.

Hence I’ve tried to remap the UP BUTTON to D0, D7 and (IRC) D3 (or in my the code: Dn0, Dn7, Dn3). In all cases the OLED stop working. Anyone got a clue whats going on?

Note that I declare them properly so:

  pinMode(BUTTON_UP_PIN, INPUT);
  pinMode(BUTTON_DO_PIN, INPUT);
  pinMode(T_SENSOR_PIN, INPUT);
  pinMode(HEATER_LED_PIN, OUTPUT);

When you install the ESP8288 core and select Wemos D1 Mini as your board type, the Arduino interpreter knows that D1 = GPIO5, D2 = GPIO4 etc.

I’ve never seen Dn5 used in place of D5, and I’d guess that the Arduino interpreter is unable to make any sense of this.

It’s good programming practice not to use the D numbers in code, as it makes it much more difficult to transfer the code to different boards. Much better to simply use the GPIO numbers (1, 2, 3 etc).

Pete.

I defined those for own reference so Dn5 = D5 etc

But they’re integers. The Arduino IDE converts D5 to 14 (because D5=GPIO14), but I don’t think it will know what to do with Dn5 when it’s declared as an integer.

Pop a Serial.println(Dn5); in there and see what it comes up with. Anything other than 14 then that’s where your problem lies.

Pete.

Ok… This discussion is going completed the wrong way. At the top of nu code I have:

Const Dn5=14;
Etc

Which I later use. I do this for my own reference so I can see what is what

But we can’t understand it… thus hardpressed to assist properly :stuck_out_tongue_winking_eye:

Not really Blynk related, but you are probably tripping one of those special pins the wrong way and causing the board to reset or something.

1 Like

Well apparently so, as.I said if I change D7 from output (to led) to input (from button) then the oled no longer works, the question is : why?

Maybe you’d be better sharing your full code if you want constructive and meaningful feedback, as out of context code snippets don’t make sense to those of us who can’t see the full picture.

Pete.

1 Like

well, I would consider that lazy. Like here’s my code: figure it out!. So im trying o pin point the issue (aasigning D7 on the wemos from output to input, but as im still a n00b in this its very hard for me to communicate that properly (in one post) as im not yet accustomed to this forum and what people want to see. Anyway here are the parts that I think are relevant:

declarations:

 */
//define means an effective search and replace with on compilation!
#define ESP_NAME "ESP_RELAY"
#define BLYNK_PRINT Serial

#include <BlynkSimpleEsp8266.h>
#include <ESP8266WiFi.h>
#include <ESP8266mDNS.h>
#include <WiFiUdp.h>
#include <ArduinoOTA.h>
#include <SimpleTimer.h>
#include <U8g2lib.h>

const char* ssid = "wolph42";
const char* password = "smarlov42";
char auth[] = "bccac3b0cb0d44e4b413273fb0862de1";

static const uint8_t An0   = 0;  //analogue in/out
static const uint8_t Dn0   = 16;
static const uint8_t Dn1   = 5;  //I2C SCL
static const uint8_t Dn2   = 4;  //I2C SDA 
static const uint8_t Dn3   = 0;  //not analogue
static const uint8_t Dn4   = 2;  //LED
static const uint8_t Dn5   = 14; //SPI CLK
static const uint8_t Dn6   = 12; //SPI MISO
static const uint8_t Dn7   = 13; //SPI MOSI
static const uint8_t Dn8   = 15; //SPI CS
static const uint8_t RXn   = 3;
static const uint8_t TXn   = 1;

// Note that there is no mem difference between const and define, however define is more bug prone!
const int SCL_PIN = Dn5; //D5
const int SDA_PIN = Dn6; //D6
const int RES_PIN = Dn1;  //D1
const int DC_PIN = Dn2;  //D2
const int BUTTON_UP_PIN = Dn4;        //D4 the pin that the pushbutton is attached to
const int BUTTON_DO_PIN = Dn8;        //D8 the pin that the pushbutton is attached to
const int HEATER_RELAY_PIN = 25;       //Dx NOT CONNECTED the pin that the Relay is attached to: LOW LVL TRIGGER (so GRND is ON)
const int HEATER_LED_PIN = Dn7;       //D7 the pin that the LED is attached to
const int T_SENSOR_PIN = An0;         //A0 ADC !! (only this pin = (A0)
U8G2_SSD1306_128X64_NONAME_F_4W_SW_SPI u8g2(U8G2_R0, /* clock=*/ SCL_PIN, /* data=*/ SDA_PIN, /* cs=*/ U8X8_PIN_NONE, /* dc=*/ DC_PIN, /* reset=*/ RES_PIN);
U8G2_SSD1306_128X64_NONAME_F_4W_SW_SPI u8g2(U8G2_R0, /* clock=*/ SCL_PIN, /* data=*/ SDA_PIN, /* cs=*/ U8X8_PIN_NONE, /* dc=*/ DC_PIN, /* reset=*/ RES_PIN);

and in void setup():

pinMode(BUTTON_UP_PIN, INPUT);
  pinMode(BUTTON_DO_PIN, INPUT);
  pinMode(T_SENSOR_PIN, INPUT);
  pinMode(HEATER_LED_PIN, OUTPUT);    // currently a led, later this will be replaced with a write to the hub
  pinMode(HEATER_RELAY_PIN, OUTPUT);    // The actual

I can’t speak for others, but one way I need to use to “troubleshoot others code” is to load the same code on my hardware and test… can’t do that with snippets :stuck_out_tongue_winking_eye:

Aside from the complication of all your defines (fine for you perhaps, but you are asking for 3rd party assist :wink: ) I also see you referencing the OLED config twice, for no apparent reason… so who knows what else you are doing… :thinking:

im having trouble uploading it. its late so ill try tomorrow. Thank you all for now for the interest and replies.

well, this is annoying, I’ve simplified my code in the ‘annoying’ area and now I can’t reproduce the issue anymore… you could say case closed, but I have a feeling this will bite me in the future who knows.

I suspect you found your issue… probably confused the compiler/MCU as well :smiley: … sometimes simple is better :wink:

Glad it is working!