UART Reading

  • 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'B': #hex 0x42
                print(Data:", data)

    But when I have been trying it like this:

    while i < 60:
            if'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:
    Please enlighten me.

  • 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:


    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.

  • This post is deleted!

  • @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".


Log in to reply

Pycom on Twitter