🤖Have you ever tried Chat.M5Stack.com before asking??😎
    M5Stack Community
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Register
    • Login

    NCIR, i2c_bus and unit Updated micropython code

    Micropython
    2
    7
    9.8k
    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.
    • T
      tialm
      last edited by tialm

      Hello!
      Is there any way to share the updated ncir unit micropython code? I really need it, the one in github is not updated.
      Thank you!
      Tiago

      1 Reply Last reply Reply Quote 0
      • T
        tialm
        last edited by tialm

        Also the unit code and updated i2c_bus would be highly appreciated!
        I am making a PoC using micropython 1.12 and some external libs, but I can't proceed if I don't have the m5stack libraries that I need!
        Please support us so that in our turn we can support you!

        liemphL 4 Replies Last reply Reply Quote 0
        • liemphL
          liemph @tialm
          last edited by liemph

          @tialm said in NCIR, i2c_bus and unit Updated micropython code:

          Also the unit code and updated i2c_bus would be highly appreciated!
          I am making a PoC using micropython 1.12 and some external libs, but I can't proceed if I don't have the m5stack libraries that I need!
          Please support us so that in our turn we can support you!

          I managed to use the NCIR unit (M5 product) connected to an ESP8266 developing board using micropython 1.12. Sorry for the belated response, hopefully still useful. The NCIR unit uses mlx90614 semiconductor chip, and I provide below the python library for it. The main program which calls the library for testing also provided below. Good luck.

          1 Reply Last reply Reply Quote 0
          • liemphL
            liemph @tialm
            last edited by

            @tialm
            Here is the NCIR library:

            import ustruct
            
            _REGISTER_TA = const(0x06)     # ambient
            _REGISTER_TOBJ1 = const(0x07)  # object
            _REGISTER_TOBJ2 = const(0x08)  # object2
            
            class MLX90614:
            	def __init__(self, i2c, address=0x5a):
            		self.i2c = i2c
            		self.address = address
            		_config1 = i2c.readfrom_mem(address, 0x25, 2)
            		_dz = ustruct.unpack('<H', _config1)[0] & (1<<6)
            		self.dual_zone = True if _dz else False
            
            	def read16(self, register):
            		data = self.i2c.readfrom_mem(self.address, register, 2)
            		return ustruct.unpack('<H', data)[0]
            
            	def read_temp(self, register):
            		temp = self.read16(register);
            		# apply measurement resolution (0.02 degrees per LSB)
            		temp *= .02;
            		# Kelvin to Celcius
            		temp -= 273.15;
            		return temp;
            
            	def read_ambient_temp(self):
            		return self.read_temp(_REGISTER_TA)
            
            	def read_object_temp(self):
            		return self.read_temp(_REGISTER_TOBJ1)
            
            	def read_object2_temp(self):
            		if self.dual_zone:
            			return self.read_temp(_REGISTER_TOBJ2)
            		else:
            			raise RuntimeError("Device only has one thermopile")
            
            	@property
            	def ambient_temp(self):
            		return self.read_ambient_temp()
            
            	@property
            	def object_temp(self):
            		return self.read_object_temp()
            
            	@property
            	def object2_temp(self):
            		return self.read_object2_temp()
            
            1 Reply Last reply Reply Quote 0
            • liemphL
              liemph @tialm
              last edited by

              @tialm Here is the main program which calls the unit:

              import time
              import mlx90614
              from machine import I2C, Pin
              
              i2c = I2C(scl=Pin(5), sda=Pin(4))
              sensor = mlx90614.MLX90614(i2c)
              
              print("Ambient (C)", sensor.read_ambient_temp())
              print("Object  (C)", sensor.read_object_temp())
              
              if sensor.dual_zone:
                  print("Dual zone")
                  print(sensor.object2_temp)
              else:
                  print("Single zone")
              print("Continuous sampling")
              while True:
                  print(sensor.read_ambient_temp(), sensor.read_object_temp())
                  time.sleep_ms(500)
              
              1 Reply Last reply Reply Quote 0
              • liemphL
                liemph @tialm
                last edited by liemph

                @tialm I do not know your development board but you should check the pins assignment for correct operation. Please change the scl and sda pins properly:

                i2c = I2C(scl=Pin(5), sda=Pin(4))
                

                I have to say that I quoted many parts of the codes from other resources but I could not remember the resources anymore. Sorry about that. This is not all my creation.

                1 Reply Last reply Reply Quote 0
                • T
                  tialm
                  last edited by

                  Thank you for your help @liemph ! I ended up doing something similar. I have only now seen your answer. But for sure that will be helpful to someone!

                  1 Reply Last reply Reply Quote 0
                  • First post
                    Last post