Welcome to the Pycom forum Forum
    • \[\[global:header.categories\]\]
    • \[\[global:header.recent\]\]
    • \[\[global:header.tags\]\]
    • \[\[global:header.popular\]\]
    • Login

    Explore Pybytes | Official Documentation | Report a Firmware Bug/Issue | GitHub

    TypeError: 'module' object is not callable

    Scheduled Pinned Locked Moved LoPy
    deep sleep shiddeep sleeplibrarylopyexpansion board
    11 Posts 5 Posters 5.4k Views 5 Watching
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • R Offline
      Rachelsimida
      last edited by

      Hi everybody

      I am new here to use the deep sleep shield. I add the deepsleep.py in the library and sync the project. I don't know if it's right and I am very confused this process:0_1522411632391_00db0c68-9025-479d-8c6c-e0d52896e43e-image.png
      You can see the deepsleep.py file is in the left side of my screenshots.
      The problem is always: TypeError: 'module' object is not callable!
      0_1522411779061_0a1af925-d0dd-4229-adaa-8b282926814e-image.png

      import pycom
      import time
      from machine import Pin, Timer
      from deepsleep import DeepSleep
      
      echo = Pin(Pin.exp_board.G7, mode=Pin.IN)
      trigger = Pin(Pin.exp_board.G8, mode=Pin.OUT)
      
      # Colors different color stand for different state
      off = 0x000000
      red = 0xff0000
      green = 0x00ff00
      blue = 0x0000ff
      
      # Turn off hearbeat LED
      pycom.heartbeat(False)
      
      #enable the deepsleep
      ds = DeepSleep()
      
      trigger(0)
      chrono = Timer.Chrono()
      
      while True:
          ds.go_to_sleep(60)  # go to sleep for 60 seconds
          print("Wake up")
          chrono.reset()
      
          trigger(1)
          time.sleep_us(10)
          trigger(0)
      
          while echo() == 0:
              pass
      
          chrono.start()
      
          while echo() == 1:
              pass
      
          chrono.stop()
      
          distance = chrono.read_us() / 58.0
      
          if distance > 400:
              print("Out of range")
          else:
              print("Distance {:.0f} cm".format(distance))
      
          time.sleep(1)
      1 Reply Last reply Reply Quote 0
      • R Offline
        Rachelsimida
        last edited by

        This is my device. 0_1522414421476_bd41dd1f-2625-4387-9340-de3099824a68-image.png

        1 Reply Last reply Reply Quote 0
        • J Offline
          jcaron
          last edited by

          I believe you should have deepsleep.py directly in the lib folder, not a subfolder.

          R 1 Reply Last reply Reply Quote 0
          • R Offline
            Rachelsimida @jcaron
            last edited by

            @jcaron I tried but still fail.0_1522416923781_b54165aa-8551-4720-a011-25df8be45387-image.png

            robert-hhR 1 Reply Last reply Reply Quote 0
            • robert-hhR Offline
              robert-hh @Rachelsimida
              last edited by

              @rachelsimida if you type in the REPL prompt:

              from deepsleep import DeepSleep
              dir (DeepSleep)
              

              What do you get as output?

              R 1 Reply Last reply Reply Quote 0
              • R Offline
                Rachelsimida @robert-hh
                last edited by

                @robert-hh 0_1522422050423_744947d6-62bd-4ca4-9d05-4e9ec750edd6-image.png

                1 Reply Last reply Reply Quote 0
                • J Offline
                  jcaron
                  last edited by

                  The errors do not seem to be very consistent. Note that Pymakr uploads files it knows about but it can leave odd stuff on the module's filesystem.

                  I recommend you either use FTP to check that you only have the files required, or clear the flash and then re-upload with Pymakr, it should help.

                  Also, don't add all those other files in lib, you'll end up with issues.

                  R 1 Reply Last reply Reply Quote 0
                  • N Offline
                    nathanh
                    last edited by

                    Would it be because you have the directory as /Lib instead of /lib (i.e. try using lowercase).

                    R 1 Reply Last reply Reply Quote 0
                    • R Offline
                      Rachelsimida @nathanh
                      last edited by

                      @nathanh Thaks. I tried. It still the same problem.

                      1 Reply Last reply Reply Quote 0
                      • R Offline
                        Rachelsimida @jcaron
                        last edited by

                        @jcaron Thank you. I tried but still like this, I don't know why it's so complicated.
                        0_1522429924401_11fc2968-19ce-49de-8853-1b51e65584cf-image.png
                        I run the deepsleep.py and there is no action in the console, if the deepsleep code is right. I downloaded from there.
                        https://github.com/pycom/pycom-libraries/tree/master/deepsleep
                        0_1522430148933_e30bfb96-f357-4737-8873-299c3bc69a76-image.png

                        1 Reply Last reply Reply Quote 0
                        • C Offline
                          cronywalls
                          last edited by

                          This error statement TypeError: 'module' object is not callable is raised as you are being confused about the Class name and Module name. The problem is in the import line . You are importing a module, not a class. This happend because the module name and class name have the same name .

                          If you have a class "MyClass" in a file called "MyClass.py" , then you should import :

                          from MyClass import MyClass
                          

                          In Python , a script is a module, whose name is determined by the filename . So when you start out your file MyClass.py with import MyClass you are creating a loop in the module structure.

                          In Python, everything (including functions, methods, modules, classes etc.) is an object , and methods are just attributes like every others. So,there's no separate namespaces for methods. So when you set an instance attribute, it shadows the class attribute by the same name. The obvious solution is to give attributes different names.

                          1 Reply Last reply Reply Quote 1

                          Hello! It looks like you're interested in this conversation, but you don't have an account yet.

                          Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.

                          With your input, this post could be even better 💗

                          Register Login
                          • 1 / 1
                          • First post
                            Last post

                          Pycom on Twitter

                          Pycom