I have a Python program which is working properly when I run it normally from LXTerminal:
$ sudo python testcon.py
but when I run it with cron
to start after reboot:
@reboot python /home/pi/testcon.py &
it stops at the line:
f = open('info.txt')
and doesn't do anything more. It's supposed to open the file /home/pi/info.txt
.
Why does this happen? How can I fix this?
Here's a simpler version of my program that shows the problem:
import smbus
import time
bus = smbus.SMBus(1) # Rev 2 Pi uses 1
DEVICE = 0x23 # Device address (A0-A2)
IODIRA = 0x00 # Pin direction register
OLATA = 0x14 # Register for outputs
GPIOA = 0x12 # Register for inputs
bus.write_byte_data(DEVICE,IODIRA,0x00)
bus.write_byte_data(DEVICE,OLATA,0xFF) #set all of the outputs
time.sleep(3) #wait for 3 sec
f = open('info.txt') #should open the txt file
bus.write_byte_data(DEVICE,OLATA,0) #clear all of the outputs
f.close()