• Hi all
    so now that I have my Lopy working with my own LoraWan network (based on RPi+ic880 and Loraserver+ mainflux)
    I wanted to add sensors to the Lopy
    is there already a DHT library
    a GPS library ? I connected my GPS (I didn't get any pytrack yet) sensors through UART but there is no sentence support for the reading I found a python micropython lib called micropyGPS but I'm still having issue with the lib

    any suggestion are welcome

    I'll share some of the code later (from Lora or LoraWAN to mqtt server)

  • @100rabhh : Just put these lines to your code:

    from nmeaParser import NmeaParser
    #Create NMEA structure
    nmea = NmeaParser()
    #..then send your uart input to the library
     if gps_uart.any():
    #...then you can access your data by
    print ('Latitude: ' + str(nmea.latitude))
    print ('Longitude: ' + str(nmea.longitude))
    print('Altitude:'+ str(nmea.altitude))
    #...there are several other data available, just check the parser code for more info

  • @affoltep Hi, How can i use it with my code?

    Here is my simple receive code for Adafruit Ultimate Breakout GPS----

    from machine import Pin
    from machine import UART

    #Interface definitons for GPS
    gps_pps = Pin('P23', mode = Pin.IN)
    gps_enable = Pin('P8', mode=Pin.OUT)
    #gps_uart = UART(2, 9600)
    #gps_uart.init(9600, bits=8, parity=None, stop=1)
    gps_uart = UART(2, baudrate=9600, bits=8, parity=None, stop=1, pins=('P10', 'P11'))
    while True:
    if gps_uart.any():

    Here i am simply reading the strings from GPS Rx. Now how do i implement in your code to parse it? Please help...

  • Cool the GPS part work well
    Beside DHT11 that is reading all the time zero all the other are working well
    PIR, RFId, GPS, Distnace , all this with Lora working to send the messages
    Next is accelerometer MPU 92/65

  • @johnmcdnz Cool, thanks - in case it still doesn't work, feel free to come to this quarter, spring is starting here ;o)

  • @affoltep The NmeaParser codes works really well (almost) :-)

    I've been using it this weekend, and discovered a minor flaw, and have fix for you.
    The code ignores the S/W hemispheres, so will only be correct for 1/4 of the planet.

    This change provides the correction
    # Update Object Data
    self.latitude = lat_degs + (lat_mins/60)
    if lat_hemi == 'S':
    self.latitude = -self.latitude
    self.longitude = lon_degs + (lon_mins/60)
    if lon_hemi == 'W':
    self.longitude = -self.longitude

    Good job I can test in the Southern hemisphere and spot the problem!

    Once I have my project working I'll post on github.

  • @Movsun I changed the name to DHT22RinusW-call.py. Described in the readme.

  • I never got the dht working I get always 28025 which is the zero values
    not sure id there are other action or I'm missing soemthing from teh library DHT itself

    >>> import DHT
    >>> dht_pin=Pin('P19', Pin.OPEN_DRAIN)
    >>> dht_pin(1)
    >>> temp, hum = DHT.DHT11(dht_pin)
    >>> temp_str = '{}.2{}'.format(temp//10,temp%10)
    >>> hum_str = '{}.2{}'.format(hum//10,hum%10)
    >>> print("sending Temp/Hum : %s/%s" % (temp_str,hum_str))
    sending Temp/Hum : 280.25/280.25

  • @johnmcdnz
    Hello, I look into your github repository. But I count not find DHT22RinusW.py file.
    Where can I find the file? Thank you in advance.

  • @gas I wrote a minimalistic NMEA parser, based on micropyGPS, which parses just the GPGGA messages. This message delivers lon, lat, alt, hdop and UTC. Feel free to use it.

    #Minimalistic NMEA-0183 message parser, based on micropyGPS
    #Version 0.1 - January 2017
    #Autor: Peter Affolter
    import utime
    class NmeaParser(object):
        """NMEA Sentence Parser. Creates object that stores all relevant GPS data and statistics.
        Parses sentences using update(). """
        def __init__(self):
            """Setup GPS Object Status Flags, Internal Data Registers, etc"""
            # Data From Sentences
            # Time
            self.utc = (0)
            # Object Status Flags
            self.fix_time = 0
            self.valid_sentence = False
            # Position/Motion
            self.latitude = 0.0
            self.longitude = 0.0
            self.altitude = 0.0
            # GPS Info
            self.satellites_in_use = 0
            self.hdop = 0.0
            self.fix_stat = 0
            #raw data segments
            self.nmea_segments = []
        def update(self,  sentence):
            self.valid_sentence = False
            self.nmea_segments = str(sentence).split(',')
            #Parse GPGGA
            if (self.nmea_segments[0] == "b'$GPGGA"):
                self.valid_sentence = True
                    # UTC Timestamp
                     utc_string = self.nmea_segments[1]
                    # Skip timestamp if receiver doesn't have on yet
                     if utc_string:
                        hours = int(utc_string[0:2])
                        minutes = int(utc_string[2:4])
                        seconds = float(utc_string[4:])
                        hours = 0
                        minutes = 0
                        seconds = 0.0
                     # Number of Satellites in Use
                     satellites_in_use = int(self.nmea_segments[7])
                     # Horizontal Dilution of Precision
                     hdop = float(self.nmea_segments[8])
                     # Get Fix Status
                     fix_stat = int(self.nmea_segments[6])
                except ValueError:
                    return False
             # Process Location and Speed Data if Fix is GOOD
                if fix_stat:
                    # Longitude / Latitude
                        # Latitude
                        l_string = self.nmea_segments[2]
                        lat_degs = float(l_string[0:2])
                        lat_mins = float(l_string[2:])
                        # Longitude
                        l_string = self.nmea_segments[4]
                        lon_degs = float(l_string[0:3])
                        lon_mins = float(l_string[3:])
                    except ValueError:
                        return False
                    # Altitude / Height Above Geoid
                        altitude = float(self.nmea_segments[9])
                        geoid_height = float(self.nmea_segments[11])
                    except ValueError:
                        return False
                    # Update Object Data
                    self.latitude = lat_degs + (lat_mins/60)
                    self.longitude = lon_degs + (lon_mins/60)
                    self.altitude = altitude
                    self.geoid_height = geoid_height
                # Update Object Data
                self.timestamp = (hours, minutes, seconds)
                self.satellites_in_use = satellites_in_use
                self.hdop = hdop
                self.fix_stat = fix_stat
                # If Fix is GOOD, update fix timestamp
                if fix_stat:
                    self.fix_time = utime.time()
                return True

  • I have connected the DHT22 sensor and had working very well. My code and description is here. Pay attention to the sample size change I made and that I had to adjust the bit sampling. Using the print statements to debug and understanding the one wire protocol can help in fine tuning the data conversion. Hope this helps.

Log in to reply

Looks like your connection to Pycom Forum was lost, please wait while we try to reconnect.