Notifications
Clear all

Help with coding

15 Posts
4 Users
2 Reactions
1,930 Views
(@no-hair)
Member
Joined: 4 years ago
Posts: 11
Topic starter  

Hi, I am new to coding, so I download all of my projects, could you please help me with issues with what I downloaded, when I vertified the code on my Arduino it said - SSD1306 display (0x3x, D3, D5, ); but an error message said D3 was not declared in this scope, can you please help me.

Many Thanks No Hair


   
Quote
Sean451
(@sean451)
Member
Joined: 4 years ago
Posts: 62
 

That type of error usually indicates that you forgot to declare the variable D3. A variable must be defined and given a value before you can use it in the setup or loop functions.

--->Sean

(◕(' 人 ') ◕)


   
ReplyQuote
(@no-hair)
Member
Joined: 4 years ago
Posts: 11
Topic starter  

Many thanks, but how do I do that, can you please do a diagram, its just I do struggle with programming a lot as you can see.

Many Thanks No Hair.


   
ReplyQuote
Sean451
(@sean451)
Member
Joined: 4 years ago
Posts: 62
 

int D3 = 0;

void setup() {
// put your setup code here, to run once:
}

void loop() {
// put your main code here, to run repeatedly:
D3 = D3 + 1;
}

(◕(' 人 ') ◕)


   
ReplyQuote
Sean451
(@sean451)
Member
Joined: 4 years ago
Posts: 62
 

Our good friend Paul McWhorter has an excellent series of YouTube videos that will teach you everything you need to know about programming Arduino sketches. Head on over!

https://www.youtube.com/user/mcwhorpj

--->Sean

(◕(' 人 ') ◕)


   
sj_h1 reacted
ReplyQuote
(@no-hair)
Member
Joined: 4 years ago
Posts: 11
Topic starter  

Thanks for the info, I have watched Paul McWhorter, he is good and the codes I have used from him I have had luck with. I am sending you the code that I am having trouble with,


#include <Wire.h>
#include "SSD1306.h"
#define BLYNK_PRINT Serial


#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>

// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXX";

// Your WiFi credentials.
// Set password to "" for open networks.
char ssid[] = "XXXX";
char pass[] = "XXXXXX";

#include <DHT.h>

#define DHTPIN 4 // what pin we're connected to
#define DHTTYPE DHT11 // DHT 11

// Initialize the OLED display i2C
// D3 -> SDA
// D5 -> SCL

// Initialize the OLED display using Wire library
SSD1306 display(0x3C, D3, D5);

DHT dht(DHTPIN, DHTTYPE);
BlynkTimer timer;
void setup(){
Serial.begin(115200);
// Initialising the UI will init the display too.
display.init();

display.flipScreenVertically();
display.setFont(ArialMT_Plain_16);
display.setTextAlignment(TEXT_ALIGN_LEFT);
dht.begin(); // initialize dht

Blynk.begin(auth, ssid, pass, "blynk-cloud.com", 8080);
timer.setInterval(1000L, sendSensor);
}

Hope you can help.
Many Thanks No Hair.

   
ReplyQuote
Sean451
(@sean451)
Member
Joined: 4 years ago
Posts: 62
 
Posted by: @no-hair

// Initialize the OLED display i2C
// D3 -> SDA
// D5 -> SCL

I think what you're supposed to do here is add what pins you're going to use for D3 and D5. It's asking for the D3 pin to be a SDA pin and the D5 an SCL pin.

Of course, I have no idea what I'm talking about so if someone else has a better suggestion, please jump in.

Cheers!

--->Sean

(◕(' 人 ') ◕)


   
ReplyQuote
(@yurkshirelad)
Member
Joined: 4 years ago
Posts: 495
 

The compiler expects D3 and D5 to be defined, but the error says they are not. The code in question that is failing:

SSD1306 display(0x3C, D3, D5);

What board did you select in the Arduino IDE and what board are you actually using? It's obviously an ESP8266 of some kind.

Pin names are defined in Arduino for each board. Perhaps D3 and D5 aren't the real names of pins? You need to refer to the pin diagram for your board to work out what its names and numbers are.


   
ReplyQuote
(@no-hair)
Member
Joined: 4 years ago
Posts: 11
Topic starter  

Many thanks for your help, I am using a Arduino uno, I will try and see what happens.

Many thanks No Hair.


   
ReplyQuote
(@yurkshirelad)
Member
Joined: 4 years ago
Posts: 495
 

My Uno has separate pins for SCL and SDA but they're not marked with numbers. I wonder if you could do this, assuming that the 2nd and 3rd parameters are the pins for SDA and SCL respectively:

// Initialize the OLED display using Wire library
SSD1306 display(0x3C, SDA, SCL);


   
ReplyQuote
(@no-hair)
Member
Joined: 4 years ago
Posts: 11
Topic starter  

Sorry, it`s a ESP 8266, I got that wrong in message.


   
ReplyQuote
(@yurkshirelad)
Member
Joined: 4 years ago
Posts: 495
 

No problem, do you know what kind? Try to find a pin diagram for it. For example:

 

https://randomnerdtutorials.com/esp8266-pinout-reference-gpios/


   
ReplyQuote
MadMisha
(@madmisha)
Member
Joined: 5 years ago
Posts: 343
 
Posted by: @no-hair

Sorry, it`s a ESP 8266, I got that wrong in message.

Adafruit notes on their github readme under compatibility that is was tested on the ESP 8266 but adds "Change OLED_RESET to different pin if using default I2C pins D4/D5". But it looks like you might be using a different library. More info on the brand of LCD you have would help. Also, load the example sketch and see if you can get that to work. Aslo, you have the pins commented out. They need to be defined before that.


   
ReplyQuote
(@no-hair)
Member
Joined: 4 years ago
Posts: 11
Topic starter  

@yurkshirelad

Thanks, this is the ESP8622 I`m using.

ESP8266 12-E NodeMCU Kit pinout diagram gpios pins
 

   
ReplyQuote
Sean451
(@sean451)
Member
Joined: 4 years ago
Posts: 62
 

So pm that board, you'd use D1 for SCL and D2 for SDA.

Sometimes, it's better to start simple and then work your way to more complex. Try doing something simple with D1 and D2 like attaching a pair of LEDs and using the program to turn them off and on. Then once you're comfortable working with them, you can start using the I2C functions.

Good luck!

--->Sean

(◕(' 人 ') ◕)


   
sj_h1 reacted
ReplyQuote