B4R Question ESP8266 - ESP01 - set output pin as 1 or 0

petr4ppc

Well-Known Member
Licensed User
Longtime User
Dear friends, please,

I have ESP01 ( ESP8266) and I please for advice how to declare pin GPIO00 and GPIO002

ESP01-Schematic.png


I am trying
B4X:
Sub Process_Globals
Private d1pins As D1Pins
Private d2 As Pin

Sub AppStart
    d2.Initialize(d1pins.D2, d2.MODE_OUTPUT) 
    d2.DigitalWrite(False)

Sub OnOff

            Dim b As Boolean
            Dim x() As Byte
            b = x(0) = 0
            d2.DigitalWrite(b)

but I can not turn LED on end off...
Please for advice
p4ppc
 

emexes

Expert
Licensed User
Dear friends, please,

I have ESP01 ( ESP8266) and I please for advice how to declare pin GPIO00 and GPIO002


I am trying
B4X:
Sub Process_Globals
Private d1pins As D1Pins
Private d2 As Pin

Sub AppStart
    d2.Initialize(d1pins.D2, d2.MODE_OUTPUT)
    d2.DigitalWrite(False)

Sub OnOff

            Dim b As Boolean
            Dim x() As Byte
            b = x(0) = 0
            d2.DigitalWrite(b)

but I can not turn LED on end off...
Please for advice
p4ppc
I don't have that device here, but this:
B4X:
b = x(0) = 0
is probably not doing what you think:
- in C, it will assign 0 to X(0), and then assign that to b also, which would be equivalent to false
- in BASIC, it would normally do a boolean comparison x(0) = 0, which will probably return True, and assign that to B

To track down that a pin is working, try alternating it True/False (or 1/0 or On/Off or High/Low) slow enough that you can check it with a logic probe or multimeter or oscilloscope.
B4X:
Sub Process_Globals
    Private d1pins As D1Pins
    Private d2 As Pin
End Sub

Sub AppStart
    d2.Initialize(d1pins.D2, d2.MODE_OUTPUT)

    For NumFlashes = 1 to 10000
        d2.DigitalWrite(False)
        Sleep(1000)
        d2.DigitalWrite(True)
        Sleep(1000)
    Next
End Sub
and if that doesn't do the job, then probably the LED is on a pin other than d1Pins.D2
 
Upvote 0

petr4ppc

Well-Known Member
Licensed User
Longtime User
Emexes,

thank you for your advice,

I have pins described as GPIO00 and GPIO002 but in declaration B4R is available the name of pin d0,d1,d2....
And this I dont know how to set in delaration GPIO002 pin of ESP8266.
I go to try your advice

EDIT: the led not flashes...It will be mistake in PIN declaration, please do you know how to declare the pin?

Thank you very much
Best regards
p4ppc
 
Upvote 0

janderkan

Well-Known Member
Licensed User
Longtime User
It is an ESP01 it does not have an USB interface, so how do you upload the program?
And why dont you use an ESP8266?
 
Upvote 0

petr4ppc

Well-Known Member
Licensed User
Longtime User
Emexes,

I understand - thank you very much for your advice and thank you for your time, I will try it.

Best regards,
p4ppc
 
Upvote 0

petr4ppc

Well-Known Member
Licensed User
Longtime User
I am only trying and I am learning possibilities.
As wrote somebody on forum, very good choice because of compatibility and everything what is needed is Wemos D1R2 (my opinion)
images

p4ppc
 
Upvote 0

petr4ppc

Well-Known Member
Licensed User
Longtime User
Emexes,

thank you for your empathy :)
I am learning step by step from "Hello world" and somewhere on this amazing forum I saw that this can be the best choice. Personaly I see this as best choice...

Best regards
p4ppc
 
Upvote 0

RJB

Active Member
Licensed User
Longtime User
Hi,
this will flash the on-board LED:
B4X:
Sub Process_Globals
 
'Set board selector to: LOLIN(WEMOS) D1 R2 & mini and select the relevant Serial Port
 Dim Serial1 As Serial
 Dim LEDOn As Boolean = False
 Dim LEDOff As Boolean = True
 Public led As Pin
 Private ledPin As Int = 2 'D4 also led on 8266
 
End Sub
Private Sub AppStart
 Serial1.Initialize(9600) '115200)
 Delay(5000)
 Log(CRLF, "AppStart")
 led.Initialize(ledPin, led.MODE_OUTPUT)     'led on GPIO2/ 8266
 
Do While True
 led.DigitalWrite(LEDOn)
 Delay(1000)
 led.DigitalWrite(LEDOff)
 Delay(1000)
Loop
End Sub
 
Last edited:
Upvote 0
Top