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

    UART Reading

    Scheduled Pinned Locked Moved MicroPython
    4 Posts 4 Posters 124 Views 4 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.
    • O Offline
      Oridroo
      last edited by

      Hi,

      I have been trying to read from a dust sensor (Amphenol SM-UART-04L).

      When I'm communicating the UART as below, it's giving output.

      while i < 60:
               if uart.read(1)==b'B': #hex 0x42
                  data=uart.read(32)
                  print(Data:", data)
      

      But when I have been trying it like this:

      while i < 60:
              data=uart.read(32)
              if uart.read(1)==b'B': #hex 0x42
                 print(Data:", data)
                  
      

      I am getting error: TypeError: 'NoneType' object is not subscriptable
      Is there any protocol to follow to read from UART? Why the second one isn't working out?
      Below is the communication protocol from the datasheet:
      UART-1.PNG
      UART-2.PNG
      Please enlighten me.
      Thanks

      J 1 Reply Last reply Reply Quote 0
      • J Offline
        johand @Oridroo
        last edited by

        @Oridroo You need to check if there is data to read. Could be done with "if uart.any() >= 32" or check if data was received with "if data != None".

        Johan

        1 Reply Last reply Reply Quote 2
        • I Offline
          Immi
          last edited by

          This post is deleted!
          1 Reply Last reply Reply Quote 0
          • R Offline
            reekjohns
            last edited by

            The error is self-explanatory. You are trying to subscript an object which you think is a list or dict, but actually is None. This means that you tried to do:

            None[something]
            

            This error means that you attempted to index an object that doesn't have that functionality. You might have noticed that the method sort() that only modify the list have no return value printed – they return the default None. 'NoneType' object is not subscriptable is the one thrown by python when you use the square bracket notation object[key] where an object doesn't define the getitem method . This is a design principle for all mutable data structures in Python.

            1 Reply Last reply Reply Quote 0

            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