0

Writing to file prevents GPIO input pin reading
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

Writing to file prevents GPIO input pin reading

by mrburns25 on Tue Jan 10, 2017 5:14 pm

I have come across and issue involving writing to a file and reading in a GPIO input.

SETUP:
Beaglebone Black running Ubuntu 14.04 with 3.8.13-bone78 using Adafruit beaglebone IO python library
Virtual HDMI Cape has been disabled

ISSUE:
I am reading a TAC signal from a computer fan using P8_7 as a GPIO_IN. It works well when all I do is just read the pin. However, I have noticed that if I write to a file before trying to read that pin, it will only return 0, nothing else. It seems to loose the ability to read in the signal after I write to a file. I have only noticed this with this one pin. I have tried setting up the pin again after I write to a file and that does not work. The only way to make it work is for me to just not write to a file before I try to read from the pin. Has anyone else seen this issue or know of a solution? Thanks.

mrburns25
 
Posts: 4
Joined: Tue Jan 10, 2017 4:44 pm

Re: Writing to file prevents GPIO input pin reading

by drewfustini on Tue Jan 10, 2017 5:31 pm

Are you using the most recent release of Adafruit_BBIO?
https://github.com/adafruit/adafruit-beaglebone-io-python/releases/tag/1.0.1

If not, please install 1.0.1 and test again. You should be able to do so with pip:
pip install upgrade Adafruit_BBIO

drewfustini
 
Posts: 944
Joined: Sat Dec 26, 2015 1:19 pm

Re: Writing to file prevents GPIO input pin reading

by mrburns25 on Wed Jan 11, 2017 4:18 pm

I updated the library to 1.0.1 and pin 8_7 still does not work after writing to a file.

mrburns25
 
Posts: 4
Joined: Tue Jan 10, 2017 4:44 pm

Re: Writing to file prevents GPIO input pin reading

by drewfustini on Wed Jan 11, 2017 9:20 pm

Could you please post the code you are running? I'll try replicating the issue on my BeagleBone.

drewfustini
 
Posts: 944
Joined: Sat Dec 26, 2015 1:19 pm

Re: Writing to file prevents GPIO input pin reading

by mrburns25 on Thu Jan 12, 2017 10:46 am

Here is the code I am running. It is not 100% the same code as I am running since it uses a few custom classes and yaml files.

START CODE
Code: Select all | TOGGLE FULL SIZE
import Adafruit_BBIO.GPIO as GPIO
import time

GPIO.setup("P8_7",GPIO.IN)

#Open file and write status
#Makes LED go blue and set to info to Test_F1
txt = open(runlog_path,'w')
txt.write("Blue\n")
txt.write("Test_F1")
txt.close()

#Take TAC1 sample for 1 sec
start_time = time.time()
diff_time = 0;
prev_pin_state = GPIO.input(self.TAC1_Pin)
TAC1_count = 0
while diff_time < 1:
    #Check state of pin
    current_pin_state = GPIO.input(self.TAC1_Pin)
           
    if current_pin_state != prev_pin_state:
        #Add to counter
        TAC1_count = TAC1_count + 1
        #Make current state prev state
        prev_pin_state = current_pin_state
           
     current_time = time.time()
     diff_time = current_time - start_time

print(TAC1_count)

END CODE

The print(TAC1_count) will always return 0 after I write to the file but will return a counted number greater than 0 when I do not write. I have doubled checked to make sure all the wires are hooked up correctly and that the fun is actually running as well. Thank you for your help.

mrburns25
 
Posts: 4
Joined: Tue Jan 10, 2017 4:44 pm

Re: Writing to file prevents GPIO input pin reading

by drewfustini on Fri Jan 13, 2017 4:09 am

mrburns25 wrote:Here is the code I am running. It is not 100% the same code as I am running since it uses a few custom classes and yaml files.

The print(TAC1_count) will always return 0 after I write to the file but will return a counted number greater than 0 when I do not write. I have doubled checked to make sure all the wires are hooked up correctly and that the fun is actually running as well. Thank you for your help.


I've modified the code in order to get it to run for me:
Code: Select all | TOGGLE FULL SIZE
import Adafruit_BBIO.GPIO as GPIO
import time

TAC1_Pin = "P8_7"
runlog_path = "run.log"

GPIO.setup(TAC1_Pin,GPIO.IN)

#Open file and write status
#Makes LED go blue and set to info to Test_F1
txt = open(runlog_path,'w')
txt.write("Blue\n")
txt.write("Test_F1")
txt.close()

#Take TAC1 sample for 1 sec
start_time = time.time()
diff_time = 0;
GPIO.setup(TAC1_Pin,GPIO.IN)
prev_pin_state = GPIO.input(TAC1_Pin)
print("prev_pin_state={0}".format(prev_pin_state))
TAC1_count = 0
while diff_time < 1:
    #Check state of pin
    GPIO.setup(TAC1_Pin,GPIO.IN)
    current_pin_state = GPIO.input(TAC1_Pin)
    print("current_pin_state={0}".format(current_pin_state))
    if current_pin_state != prev_pin_state:
        #Add to counter
        TAC1_count = TAC1_count + 1
        print("TAC1_count={0}".format(TAC1_count))
        #Make current state prev state
        prev_pin_state = current_pin_state
           
    current_time = time.time()
    diff_time = current_time - start_time

print("TAC1_count={0}".format(TAC1_count))


I connected P8_7 to P9_3 (3.3V) and ran the program:
prev_pin_state=1
current_pin_state=1
current_pin_state=1
current_pin_state=1
current_pin_state=1
[snip]
current_pin_state=1
current_pin_state=1
current_pin_state=1


Is that different from what you see if you run the above code?

drewfustini
 
Posts: 944
Joined: Sat Dec 26, 2015 1:19 pm

Re: Writing to file prevents GPIO input pin reading

by mrburns25 on Fri Jan 13, 2017 12:15 pm

That did fix my problem. Thanks! Do you know why writing to the file messed up that pin? I haven't been able to figure it out.

mrburns25
 
Posts: 4
Joined: Tue Jan 10, 2017 4:44 pm

Re: Writing to file prevents GPIO input pin reading

by drewfustini on Fri Jan 13, 2017 9:22 pm

mrburns25 wrote:That did fix my problem. Thanks! Do you know why writing to the file messed up that pin? I haven't been able to figure it out.


I'm not sure why you observed that issue. It is hard for me to determine the cause if I can't replicate it. Generally, strace is very useful to determine exactly what is happening when a program runs.

drewfustini
 
Posts: 944
Joined: Sat Dec 26, 2015 1:19 pm

Please be positive and constructive with your questions and comments.