My apologies.  I hit reply and not reply to all.

Alan,

I think I answered many of your questions in this message to Steven.




---------- Forwarded message ----------
From: Chip Wachob <wach...@gmail.com>
Date: Tue, Sep 4, 2018 at 1:48 PM
Subject: Re: [Tutor] Accessing variables from other modules
To: Steven D'Aprano <st...@pearwood.info>


Steven,

Thank you.

Responding to your comments in order:

# module AdafruitInit.py
# from the Adafruit tutorials..
import Adafruit_GPIO.FT232H as FT232H
import Adafruit_GPIO as GPIO

FT232H.use_FT232H()

ft232h = FT232H.FT232H()

# config settings for the SPI 'machine'
spi = FT232.SPI(ft232h, 4, 20000, 2, FT232H.MSBFIRST)



# module RSI.py
def write(byte):
   spi.write(byte)

# toggle the latch signal
   ft232h.output(5, GPIO.LOW)
   ft232h.output(5, GPIO.HIGH)



# module main.py
import RSI
import AdafruitInit.py

ft232.setup(5, GPIO.OUT)

write(0xAA)


"write()" tells me that

"global name 'ft232h' is not defined"


Regarding permissions.  I'm not sure about the need for sudo, but that
was used in the example.  The script will fail to run without it.  I
can't say for certain that I understand why sudo is required.  It may
have something to do with disabling the "built in" FTDI driver and
enabling the Adafruit version.  I had hoped to just get things
'working' before worrying about trying to get rid of the sudo
requirement.

I had been working most of the day on Friday and the scripts were
running fine.  I was running the scripts from the command line as
noted above (and related to your question re: sudo).  I powered off
the machine Friday night, and started it back up this morning.

Does some of the FTDI (AdafruitInit.py) remain resident even though
I've exited out of the script.  My menu has an entry that will permit
breaking the while() loop and ending the script.



...



On Tue, Sep 4, 2018 at 1:19 PM, Steven D'Aprano <st...@pearwood.info> wrote:
> Hi Chip, and welcome!
>
> On Tue, Sep 04, 2018 at 11:10:36AM -0400, Chip Wachob wrote:
>
>> I'll refrain from posting a bunch of code, but here is the 5000 foot view:
>
> Not posting a mountain of code is a great idea, but from 5000 ft away
> we can't see what is going on.
>
> Try posting *a little bit of code*. This is written for Java programmers
> but the principle is the same for Python:
>
> http://sscce.org/
>
> If I had to make a *wild guess* as to what is going on, it would be that
> you have a couple of modules like this:
>
> # Module spam.py
> x = 1  # global variable
> def foo():
>     print(x)
>
>
> # Module eggs.py
> import spam
> from spam import x
> foo()  # prints 1, as you expect
> x = 999
> foo()  # still prints 1, instead of 999
>
>
> Is that what is going on? On something different?
>
>
> A few more comments:
>
>> execution looks like this:
>>
>> $ sudo python main.py
>
> Do you really need this to be run with root permissions?
>
>> So, the important questions are:
>>
>> - Was I mislead by the fact that there was a power cycle on the
>> machine and it has now forgotten something that was staying resident
>> when I tested the code on Friday?  Or, does each 'run' of the script
>> start fresh?
>
> Um, yes no maybe?
>
> Was there a power cycle? How were you running the scripts?
>
>
>> - What approach do I need to use to be able to initialize the
>> interface in spi.py and have it be something that is accessible to all
>> the other modules in my project?
>
>
>
>
>>
>> Thank you in advance for your time.
>> _______________________________________________
>> Tutor maillist  -  Tutor@python.org
>> To unsubscribe or change subscription options:
>> https://mail.python.org/mailman/listinfo/tutor
>>
> _______________________________________________
> Tutor maillist  -  Tutor@python.org
> To unsubscribe or change subscription options:
> https://mail.python.org/mailman/listinfo/tutor
_______________________________________________
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor

Reply via email to