IO pins on esp8266

Discussion of issues related to writing ZBasic applications for targets other than ZX devices, i.e. generic targets.
Post Reply
FFMan
Posts: 502
Joined: 09 January 2010, 12:52 PM

IO pins on esp8266

Post by FFMan »

Is there anything different about the way io pins work on an esp8266 ?

I'm trying to port some proven max7219 matrix display code to an esp8266 and couldn't get anything to happen.

So i put the scope on the io pins i thought were in use and nothing is happening. So i put this code in a test program and i can see from the debug print the pins are supposed to toggle every 3 secs. However I can't find any pin on my nodemcu that is changing state ?

Code: Select all

If ((curTick - lastTick) > (FRC2_ticksPerSec * 3)) Then
			lastTick = curTick
			if pinstate=0 then
				debug.print "high"
				pinstate=1
				call putpin(4,zxoutputhigh)
				call putpin(5,zxoutputhigh)
				call putpin(14,zxoutputhigh)
				call putpin(12,zxoutputhigh)
				call putpin(13,zxoutputhigh)
				call putpin(15,zxoutputhigh)
			else
				debug.print "low"
				pinstate=0
				call putpin(4,zxoutputlow)
				call putpin(5,zxoutputlow)
				call putpin(14,zxoutputlow)
				call putpin(12,zxoutputlow)
				call putpin(13,zxoutputlow)
				call putpin(15,zxoutputlow)
			end if
	end if
dkinzer
Site Admin
Posts: 3120
Joined: 03 September 2005, 13:53 PM
Location: Portland, OR

Re: IO pins on esp8266

Post by dkinzer »

FFMan wrote:Is there anything different about the way io pins work on an esp8266 ?
The setup and use are basically the same as with other ZX devices. The problem may lie with the first line that you show; I can't say since the rest of the program isn't shown.

This program seems to work:

Code: Select all

Option UserPostInit myPostInit

Const pin as Byte = A.2
Dim state as Integer
Dim pinState as Byte

Sub Main()
   If (state = 0) Then
       pinState = pinState Xor 1
       Call PutPin(pin, pinState)
       Debug.Print "Hello, world!"
   End If
   state = state + 1
   If (state >= 1000) Then
       state = 0
   End If
   Call Sleep(1)
End Sub

Sub myPostInit()
   Call PutPin(pin, pinState)
   Debug.Print
End Sub
- Don Kinzer
FFMan
Posts: 502
Joined: 09 January 2010, 12:52 PM

Post by FFMan »

thanks don - your program pulses A.2 which is the led, and this appears to equate to D4 on mini Nodemcu.

I suspect the issue is pin assignments. The compiler does not allow d.1 so I'm a bit unsure how to reference the pins. I've bee trying the Arduino raw in assignments with no luck and other combination but I've not been able to make any other pins work as yet.

So I have ascertained by experimentation:-

Zbasic Nodemcu

A2 D4-GOI02
A4 D2-GPI04
A5 D1-GPI05

But i can't find A.1, A.3 etc

I can't find the adc pin which is A0 on the node
Attachments
MiniNodeMCUPins-detailed.JPG
(101.28 KiB) Downloaded 86 times
NodeMCUPins.JPG
(105.18 KiB) Downloaded 84 times
dkinzer
Site Admin
Posts: 3120
Joined: 03 September 2005, 13:53 PM
Location: Portland, OR

Post by dkinzer »

FFMan wrote:But i can't find A.1, A.3 etc
As you may have deduced, A.0 through A.15 correspond to GPIO0 through GPIO15, respectively. Some of those pins have dedicated functions, such as GPIO1 being TxD, GPIO3 as RxD, etc. Some of the GPIO pins are dedicated to reading/writing the external Flash memory and can't be used for general purpose I/O.

Further, in ZBasic, the numeric pin values 1-16 correspond to A.0 through A.15. This is all summarized in a table in the ESP8266 ZBasic document:

www.zbasic.net/doc/ZBasicESP8266.php?page=8
- Don Kinzer
FFMan
Posts: 502
Joined: 09 January 2010, 12:52 PM

Post by FFMan »

thanks - i'd missed that part.

is there a way to reference the adc. It doesn't appear to have a GPIOnn designation that i can see.

The zbasic documentation doesn't say getadc isn't implemented.
dkinzer
Site Admin
Posts: 3120
Joined: 03 September 2005, 13:53 PM
Location: Portland, OR

Post by dkinzer »

FFMan wrote:is there a way to reference the adc. It doesn't appear to have a GPIOnn designation that i can see.
In the implementation, the pin number passed to the function implementing GetADC() is ignored for the ESP8266 since there is only one ADC channel. Consequently, you can use any pin number (even zero) and it will produce the same result.

However, I noticed that the compile will generate a warning when the pin number is known at compile time since none of the pins is designated as being an analog pin. You can either just ignore the warning that is generated or you can suppress it thus:

Code: Select all

#pragma warning(push)
#pragma warning(3:Off)
    ival = GetADC(0)
#pragma warning(pop)
- Don Kinzer
FFMan
Posts: 502
Joined: 09 January 2010, 12:52 PM

Post by FFMan »

thanks don - got it working in the end
Post Reply