Skip to content

'_SPI_OPCODE_RDID' is not defined (Jetson Nano) #12

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
ADV-LUT opened this issue Nov 25, 2019 · 20 comments
Closed

'_SPI_OPCODE_RDID' is not defined (Jetson Nano) #12

ADV-LUT opened this issue Nov 25, 2019 · 20 comments
Labels
bug Something isn't working

Comments

@ADV-LUT
Copy link

ADV-LUT commented Nov 25, 2019

I'm trying to run the SPI fram breakout board with the Jetson nano and always get the following error message when I'm running the example.

Traceback (most recent call last):
File "fram_spi_simpletest.py", line 11, in <module>
fram = adafruit_fram.FRAM_SPI(spi, cs)
File "/home/adves/.local/lib/python3.6/site-packages/adafruit_fram.py", line 301, in __init__
spi.write(bytearray([_SPI_OPCODE_RDID]))
NameError: name '_SPI_OPCODE_RDID' is not defined
Exiting...
Cleaning up pins

@ladyada
Copy link
Member

ladyada commented Nov 25, 2019

thats odd because its defined right above
https://github.com/adafruit/Adafruit_CircuitPython_FRAM/blob/master/adafruit_fram.py#L291
@jerryneedell or @makermelissa have y'all used this library recent

@jerryneedell
Copy link
Contributor

@ladyada Just tried one on a feather_nrf5280_express -- no problem.

@makermelissa
Copy link
Collaborator

I haven't used it recently. Perhaps this is something related specifically to the Jetson Nano.

@ladyada
Copy link
Member

ladyada commented Nov 25, 2019

@ADV-LUT how are you installing? what version python are you running

@ADV-LUT
Copy link
Author

ADV-LUT commented Nov 27, 2019

@ladyada
I also suspect that it could a very special problem with the Jeston Nano. I am also confused because it is defined, I had already checked that.

I have python version 3.6.8

I am grateful for any help.

@caternuson
Copy link
Contributor

It might be a slight syntax error? Need to add a self. or FRAM_SPI. in front of the class variable _SPI_OPCODE_RDID ?

Simple example to demonstrate issue:

class Foo:
    _SOME_VAR = 23

    def foo(self):
        return bytearray([_SOME_VAR])

and then:

$ python3
Python 3.6.8 (default, Oct  7 2019, 12:59:55) 
[GCC 8.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import foo
>>> f = foo.Foo()
>>> dir(f)
['_SOME_VAR', '__class__', '__delattr__', '__dict__', '__dir__', '__doc__', '__eq__', '__format__', '__ge__', '__getattribute__', '__gt__', '__hash__', '__init__', '__init_subclass__', '__le__', '__lt__', '__module__', '__ne__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__', '__weakref__', 'foo']
>>> f.foo()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "foo.py", line 5, in foo
    return bytearray([_SOME_VAR])
NameError: name '_SOME_VAR' is not defined
>>> 

same for CP:

Adafruit CircuitPython 4.1.0 on 2019-08-02; Adafruit ItsyBitsy M4 Express with samd51g19
>>> import foo
>>> f = foo.Foo()
>>> dir(f)
['__class__', '__dict__', '__module__', '__qualname__', 'foo', '_SOME_VAR']
>>> f.foo()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "foo.py", line 5, in foo
NameError: name '_SOME_VAR' is not defined
>>>

@makermelissa
Copy link
Collaborator

That makes sense.

@ladyada ladyada closed this as completed Dec 2, 2019
@ladyada
Copy link
Member

ladyada commented Dec 2, 2019

@ADV-LUT please try the example code as is

@ADV-LUT
Copy link
Author

ADV-LUT commented Dec 3, 2019

I have the same result/issue as @caternuson with the sample code on the Jetson Nano.

And how can I fix that?

@caternuson
Copy link
Contributor

@ADV-LUT Do you know how to make pull requests? This looks like a pretty simple issue that would make for a good first one.

@ADV-LUT
Copy link
Author

ADV-LUT commented Dec 4, 2019

@caternuson I have not made a pull request yet, but I would like to do it. I've just read how it works, but have not quite understood.
And I still do not fully understand how and where to change something now to fix the bugs.

And if I understand that correctly, the pull request is there for me, that my changes are taken over in the repository. But I do not know, where I have to do changes.

@caternuson
Copy link
Contributor

@deanpan
Copy link

deanpan commented Sep 24, 2020

I am running similar issue on Raspberry Pi.

name '_SPI_OPCODE_RDID' is not defined

Thanks!

pi@raspberrypi:~ $ python3
Python 3.7.3 (default, Jul 25 2020, 13:03:44)
[GCC 8.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.

import board
import busio
import digitalio
import adafruit_fram
spi = busio.SPI(board.SCK, board.MOSI, board.MISO)
cs = digitalio.DigitalInOut(board.D6)
fram = adafruit_fram.FRAM_SPI(spi, cs)
Traceback (most recent call last):
File "", line 1, in
File "/usr/local/lib/python3.7/dist-packages/adafruit_fram.py", line 323, in init
spi.write(bytearray([_SPI_OPCODE_RDID]))
NameError: name '_SPI_OPCODE_RDID' is not defined

@caternuson
Copy link
Contributor

Reopening.

I think this works on CircuitPython and not elsewhere because of use of const(). Can re-create same issue on a RPI:


pi@raspberrypi:~ $ python3
Python 3.7.3 (default, Dec 20 2019, 18:57:59) 
[GCC 8.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import board
>>> import busio
>>> import digitalio
>>> import adafruit_fram
>>> spi = busio.SPI(board.SCK, board.MOSI, board.MISO)
>>> cs = digitalio.DigitalInOut(board.D6)
>>> fram = adafruit_fram.FRAM_SPI(spi, cs)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/pi/blinka/lib/python3.7/site-packages/adafruit_fram.py", line 330, in __init__
    spi.write(bytearray([_SPI_OPCODE_RDID]))
NameError: name '_SPI_OPCODE_RDID' is not defined
>>> 

@caternuson caternuson reopened this Sep 24, 2020
@deanpan
Copy link

deanpan commented Sep 25, 2020 via email

@tannewt
Copy link
Member

tannewt commented Sep 25, 2020

@caternuson I don't think this has to do with const. const should just return the same value. I think this is a slight difference in name lookup between CPython and CircuitPython.

I think #12 (comment) is exactly right. I'm not sure why it was closed and not fixed.

@caternuson
Copy link
Contributor

I'm not finding a way to allow use of class level const() that works with both CP and CPython.

This shoulnd't work, but does:

class Foo:

    _SOME_VAR = const(23)

    def __init__(self):
        print(_SOME_VAR)
Adafruit CircuitPython 5.3.1 on 2020-07-13; Adafruit ItsyBitsy M0 Express with samd21g18
>>> import foo
>>> f = foo.Foo()
23
>>>

While this:

class Foo:

    _SOME_VAR = const(23)

    def __init__(self):
        print(Foo._SOME_VAR)

leads to this:

Adafruit CircuitPython 5.3.1 on 2020-07-13; Adafruit ItsyBitsy M0 Express with samd21g18
>>> import foo
>>> f = foo.Foo()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "foo.py", line 6, in __init__
AttributeError: type object 'Foo' has no attribute '_SOME_VAR'
>>> 

Removing use of const() gets it to work though:

class Foo:

    _SOME_VAR = 23

    def __init__(self):
        print(Foo._SOME_VAR)
Adafruit CircuitPython 5.3.1 on 2020-07-13; Adafruit ItsyBitsy M0 Express with samd21g18
>>> import foo
>>> f = foo.Foo()
23
>>> 

@evaherrada evaherrada added the bug Something isn't working label Sep 25, 2020
@tannewt
Copy link
Member

tannewt commented Sep 28, 2020

@caternuson Thanks for the experiments. Removing the const is the best option. In general, it is overused and should only be used at the top level.

@caternuson
Copy link
Contributor

This should be fixed by #22. Please try the 1.3.4 version of the library:
https://github.com/adafruit/Adafruit_CircuitPython_FRAM/releases/tag/1.3.4

@caternuson
Copy link
Contributor

Closing for now. Can reopen if needed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

8 participants