[W600] IO pins not working

Discussion and questions about boards that can run MicroPython but don't have a dedicated forum.
Target audience: Everyone interested in running MicroPython on other hardware.
cdude1990
Posts: 4
Joined: Fri Jul 17, 2020 2:56 pm

[W600] IO pins not working

Post by cdude1990 » Fri Jul 17, 2020 3:18 pm

I have an Air602 that I am using to report sensor data over wifi. I loaded micropython, and can manipulate the file system and call out over wifi using sockets. I am trying to use the IO pins for sensor input.

The pin voltages are:

Code: Select all

GND 0
TX1 3.3
RX1 3.3
RTS 0
CTS 0
IO  0
Nothing I do in code changes these voltages. For example, if I run the following code:

Code: Select all

import network
import utime
from machine import Pin

with open('error.log', 'w') as f:

	for i in range(7, 12):
		try:
			pin = Pin(i, Pin.OUT)
			pin.value(0)
		except BaseException as e:
			f.write("PinError: {}\r".format(str(e)))            
	f.write("pins set\r")

for _ in range(30):
	utime.sleep(1)
the logfile reads "pins set" and the voltages are unchanged. The result is the same if the pins are set to 1.

Reading the pins also does nothing. If I ground IO to GND and run the following code:

Code: Select all

import network
import utime
from machine import Pin

with open('error.log', 'w') as f:

	for i in range(7, 12):
		try:
			pin = Pin(i, Pin.IN, Pin.PULL_DOWN)
			f.write("pin {} value is {}\r".format(i, pin.value()))
		except BaseException as e:
			f.write("PinError: {}\r".format(str(e)))            
the logfile is:

Code: Select all

pin 7 value is 1
pin 8 value is 1
pin 9 value is 1
pin 10 value is 1
pin 11 value is 1
This result does not change if I use Pin.PULL_UP. But if I omit that parameter, the logfile is:

Code: Select all

pin 7 value is 0
pin 8 value is 0
pin 9 value is 1
pin 10 value is 0
pin 11 value is 0
This result does not change even if I ground RTS.

Others have gotten the Air602 IO working using the C SDK ( https://yoursunny.com/t/2018/Air602-blink/ ). So I wonder if there is something in the micropython implementation.

What am I missing?

User avatar
Roberthh
Posts: 3667
Joined: Sat May 09, 2015 4:13 pm
Location: Rhineland, Europe

Re: [W600] IO pins not working

Post by Roberthh » Fri Jul 17, 2020 3:40 pm

Which version of the firmware are you using?

Besides, you are using the wrong pin numbers. You have to use the symbolic names, not the pin numbers of the module.

Code: Select all

Module #    Python name  Python # 
 5          Pin.PA_04       4 
 6          Pin.PA_05       5
 7          Pin.PB_08      24
 8          Pin.PB_09      25
 9          Pin.PB_10      26
10          Pin.PB_11      27
11          Pin.PB_12      28
Edit: You can write the loop as:

for i in (Pin.PB_08, Pin.PB_09, Pin.PB_10, Pin.PB_11, Pin.PB_12):

or:

for i in range(24, 29):

cdude1990
Posts: 4
Joined: Fri Jul 17, 2020 2:56 pm

Re: [W600] IO pins not working

Post by cdude1990 » Fri Jul 17, 2020 4:25 pm

Thanks. The version is 1.10 . I changed the for loop to

Code: Select all

    for i in [Pin.PA_08, Pin.PB_09, Pin.PB_10, Pin.PB_11, Pin.PB_12]:
Most of the results were unchanged (with corrected pin numbers) except for reading with no pull parameter:

Code: Select all

pin 8 value is 0
pin 25 value is 0
pin 26 value is 0
pin 27 value is 1
pin 28 value is 0
The 1 becomes 0 if I ground that pin. So at least I can use that pin for input.

Can you tell me, does the PULL_UP parameter add an internal resistance, similar to Arduino, or does it mean it expects me to add a pull up resistor?

User avatar
Roberthh
Posts: 3667
Joined: Sat May 09, 2015 4:13 pm
Location: Rhineland, Europe

Re: [W600] IO pins not working

Post by Roberthh » Fri Jul 17, 2020 4:39 pm

The first pin should be Pin.PB_08. the docs i had found about the air602 were inconclusive.
The pull should be internal.
I have made versions of the firmware thst are mor close to the standard micropython. You'll find some fks files here:https://github.com/robert-hh/Shared-Stuff
And the corresponding sources here:https://github.com/robert-hh/micropython/tree/w60x
These versions contain a lot of bug fixes.

User avatar
Roberthh
Posts: 3667
Joined: Sat May 09, 2015 4:13 pm
Location: Rhineland, Europe

Re: [W600] IO pins not working

Post by Roberthh » Fri Jul 17, 2020 7:00 pm

I made a test with a W600 board. It looks like PULL_DOWN does not work. PULL_UP seems to work. But all pins work as input with low/high values if I connect them to GND or Vcc. I will check in the source code, if that is an issue of the MicroPython driver or the SDK functions.

Edit: PULL_DOWN is not supported by the W600/W601 chip. See the note in the SDK:

"All gpio's attribute can only be set as WM_GPIO_ATTR_FLOATING or WM_GPIO_ATTR_PULLHIGH on W600/W601."

cdude1990
Posts: 4
Joined: Fri Jul 17, 2020 2:56 pm

Re: [W600] IO pins not working

Post by cdude1990 » Fri Jul 17, 2020 8:51 pm

Ah. It's working now with the pins corrected and with PULL_UP. Thank you!

One more question. If I run an infinite loop in main.py, how do I interrupt it so I can download the log file? I am using pyboard.py to move files and it waits for the running program to finish. So far I have had to limit my loop so I can read the output.

User avatar
Roberthh
Posts: 3667
Joined: Sat May 09, 2015 4:13 pm
Location: Rhineland, Europe

Re: [W600] IO pins not working

Post by Roberthh » Sat Jul 18, 2020 6:02 am

Try pushing Ctrl-C or Ctrl-D.

adxx
Posts: 9
Joined: Mon Oct 08, 2018 6:45 pm

Re: [W600] IO pins not working

Post by adxx » Fri Sep 18, 2020 7:42 am

Roberthh wrote:
Fri Jul 17, 2020 4:39 pm
I have made versions of the firmware thst are mor close to the standard micropython. You'll find some fks files here:https://github.com/robert-hh/Shared-Stuff
And the corresponding sources here:https://github.com/robert-hh/micropython/tree/w60x
These versions contain a lot of bug fixes.
Robert, one question about your versions - it wants to get connected somewhere right after reset. Is there a way to get rid of it other than recompile own version? And yet - how SSID and PASSWD are stored for long term to survive reset?

User avatar
Roberthh
Posts: 3667
Joined: Sat May 09, 2015 4:13 pm
Location: Rhineland, Europe

Re: [W600] IO pins not working

Post by Roberthh » Fri Sep 18, 2020 8:28 am

Yes. For my convenience it contains a script to connect to a local AP. That script looks for a file called wifi_config.py with the content:

WIFI_SSID=<ssid>
WIFI_PASSWD =<password>

If if exists in the local file system, the micro tries to connect. Unfortunately this file is frozen in the firmware. So I'll going to make some packages w/o it.
This connection attempt is in the frozen _boot.py file. I've put it there since during testing I changed the file system type quite often, and having that in frozen bytecode established ftp. And yes, removing that requires a rebuild of the firmware.

adxx
Posts: 9
Joined: Mon Oct 08, 2018 6:45 pm

Re: [W600] IO pins not working

Post by adxx » Fri Sep 18, 2020 9:30 am

Roberthh wrote:
Fri Sep 18, 2020 8:28 am
Yes. For my convenience it contains a script to connect to a local AP. That script looks for a file called wifi_config.py with the content:

WIFI_SSID=<ssid>
WIFI_PASSWD =<password>

If if exists in the local file system, the micro tries to connect. Unfortunately this file is frozen in the firmware. So I'll going to make some packages w/o it.
This connection attempt is in the frozen _boot.py file. I've put it there since during testing I changed the file system type quite often, and having that in frozen bytecode established ftp. And yes, removing that requires a rebuild of the firmware.
Thank, it makes sense now.

Post Reply