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

    Lopy GPS/DHT/RFiD

    Scheduled Pinned Locked Moved LoPy
    dht gps mqtt
    11 Posts 5 Posters 4.3k Views 6 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.
    • J Offline
      johnmcdnz
      last edited by

      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.
      https://github.com/johnmcdnz/LoPy-DHT-transmission

      M 1 Reply Last reply Reply Quote 0
      • affoltepA Offline
        affoltep @gas
        last edited by

        @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
                    try:
                        # 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:])
                         else:
                            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
                        try:
                            # 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
                        try:
                            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
        
        J 1 2 Replies Last reply Reply Quote 0
        • M Offline
          Movsun @johnmcdnz
          last edited by

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

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

            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
            1 Reply Last reply Reply Quote 0
            • J Offline
              johnmcdnz @Movsun
              last edited by

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

              1 Reply Last reply Reply Quote 0
              • J Offline
                johnmcdnz @affoltep
                last edited by

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

                1 Reply Last reply Reply Quote 0
                • affoltepA Offline
                  affoltep
                  last edited by

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

                  1 Reply Last reply Reply Quote 0
                  • G Offline
                    gas
                    last edited by

                    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

                    1 Reply Last reply Reply Quote 0
                    • 1 Offline
                      100rabhh @affoltep
                      last edited by

                      @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_enable(False)
                      #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'))
                      uart.write('abs')
                      gps_enable(True)
                      while True:
                      if gps_uart.any():
                      print(gps_uart.readline())

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

                      1 Reply Last reply Reply Quote 0
                      • affoltepA Offline
                        affoltep
                        last edited by

                        @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():
                                nmea.update(gps_uart.readline())
                        
                        #...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
                        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