• I am trying to read from a i2c connect sensor. I managed to get my schematic and code working for arduino leonardo but not when I interface with the puck. I suck at bytes and low level stuff, so I am wondering if I understand what I am doing.

    var i2c = new I2C();
    i2c.setup({ scl : D31, sda: D30 });
    const TMP117_Address = '0x48';
    const Temp_Reg = '0x00';
    
    setInterval(() => {
      i2c.writeTo(TMP117_Address, Temp_Reg);
      let a = i2c.writeTo(TMP117_Address, 1);
      
      setTimeout(() => {
        let b = i2c.readFrom(TMP117_Address, 2);
        console.log(b);
        let datac = ((b[0] << 8) | b[1]); 
        console.log(datac*0.0078125);
      }, 500);
    }, 2000);
    

    trying to imitate this:

    /*********************** Read Temperature Sensor Function **************************/
    double ReadTempSensor(void){
         
      // Data array to store 2-bytes from I2C line
      uint8_t data[2]; 
      // Combination of 2-byte data into 16-bit data
      int16_t datac;   
    
      // Points to device & begins transmission
      Wire.beginTransmission(TMP117_Address); 
      // Points to temperature register to read/write data
      Wire.write(Temp_Reg); 
      // Ends data transfer and transmits data from register
      Wire.endTransmission(); 
    
      // Delay to allow sufficient conversion time
      delay(10); 
    
      // Requests 2-byte temperature data from device
      Wire.requestFrom(TMP117_Address,2); 
    
      // Checks if data received matches the requested 2-bytes
      if(Wire.available() <= 2){  
        // Stores each byte of data from temperature register
        data[0] = Wire.read(); 
        data[1] = Wire.read(); 
    
        // Combines data to make 16-bit binary number
        datac = ((data[0] << 8) | data[1]); 
    
        // Convert to Celcius (7.8125 mC resolution) and return
        return datac*0.0078125; 
        
      }
    }
    

    i am getting a senseless value, i wonder what am I doing wrong? I find it hard to understand how to map these i2c operations to the pucks i2c api.

About

Avatar for user101989 @user101989 started