B4R Question ESP8266 NodeMCU ESP-12E pins?

Kevin

Well-Known Member
Licensed User
I am finally starting to experiment with my project but I am unsure of which pins are which.

I was following this tutorial, but instead I was trying to get a relay to open and close. I tried 1-30 for the pin # and nothing ever happened. It's possible that I had something wrong, but mainly for now I am curious if anyone knows how to "address" a specific pin on this board.

All I have to go on is this image, but it doesn't tell me what # to use for each pin.

B4X:
#Region Project Attributes
    #AutoFlushLogs: True
    #CheckArrayBounds: True
    #StackBufferSize: 300
#End Region

' DO NOT USE PINS: 6,7,8,11
Sub Process_Globals
    'These global variables will be declared once when the application starts.
    'Public variables can be accessed from all modules.
    Public Serial1 As Serial
    Private gpio0 As Pin
    Private Timer1 As Timer
End Sub

Private Sub AppStart
    Serial1.Initialize(115200)
    Log("AppStart")
    gpio0.Initialize(13, gpio0.MODE_OUTPUT) ' Tried 1-30
    gpio0.DigitalWrite(False)
    Timer1.Initialize ("Timer1_Tick", 3000)
    Timer1.Enabled = True
End Sub

Private Sub Timer1_Tick
    Dim currentState As Boolean = gpio0.DigitalRead
    Log("Relay > CurrentState: ", currentState)
    Dim NewState As Boolean = Not(currentState)
    Log("Relay > NewState: ", NewState)
    gpio0.DigitalWrite(NewState)
End Sub

Regarding my relay, I was expecting it to click at some point as I literally went through each pin (1-30) in the code, one at a time.

I have a 5v power supply connected to Vin and Gnd. For the 5v relay, I have Positive going to the 5v rail on my breadboard, Gnd going to the ground rail on my breadboard and for the signal pin, I have it connected to GPIO0 as per a diagram linked above.
 

Kevin

Well-Known Member
Licensed User
I did find a problem (had to jumper Positive & Ground from one set of rails to the other on the same side of the board. I assumed (wrongly) that they were all connected along each side of the board. I guess the little gap in between them should have clued me in. :rolleyes:

I also figured out that GPIO13 is pin 13 in B4A, but still, if anyone has a map of them then I'd appreciate it. Also, which pins I can safely use and which ones I should avoid. I did figure out in my initial testing that pins 6,7,8 and 11 cause it to crash.
 
Upvote 0

Kevin

Well-Known Member
Licensed User
Use the rESP8266 library to get the D1Pins Object which has pin constants.
I just shut down my computer for the night but I'll look into this in the morning.

I was as giddy as a schoolgirl when I finally got my relay to click on and off.
 
Upvote 0

derez

Expert
Licensed User
I suggest to use a led (with 150ohm resistor ) for checking the pins one by one after letting each pin to be digital true. A relay consumes high current and its operation depends on the power supply.
In my WEMOS D1R2 and Nodemcu (esp8266) which I bought from Aliexpress the D numbers are not as in the library, for example for pin D4 I have to use D2 while 5,6,7, are the same.
I don't know the settings on esp32.
 
Last edited:
Upvote 0

Kevin

Well-Known Member
Licensed User
Does anyone know how I would address A0 in B4R? ESPin only supports digital pins. Basically, does anyone know which pin this is so I can just use the pin number?

What I plan to do is use this pin to work my relay by just giving it full power or no power. How would I set this pin to "full", being that it is an analog pin?
 
Upvote 0
Top