Advertisement
silver2row

infineon ported to arduino...

Jan 10th, 2024
904
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.03 KB | None | 0 0
  1.  
  2. 9   // Read ID
  3. 10   uint8_t id = readByte(0x00);
  4. 11   Serial.print("ID: ");
  5. 12   Serial.println(id, HEX);
  6. 13  
  7. 14   // Check sensor status
  8. 15   uint8_t sts = readByte(0x01);
  9. 16   Serial.print("Sensor status: ");
  10. 17   Serial.println(sts, HEX);
  11. 18  
  12. 19   // Idle mode
  13. 20   writeByte(0x04, 0x00);
  14. 21   delay(400);
  15. 22  
  16. 23   // Set measurement rate to 10 s
  17. 24   writeByte(0x02, 0x00);
  18. 25   writeByte(0x03, 0x0A);
  19. 26  
  20. 27   // Configure continous mode
  21. 28   writeByte(0x04, 0x02);
  22. 29 }
  23. 30  
  24. 31 void loop() {
  25. 32  
  26. 33   // Poll measurement status
  27. 34   uint8_t meas_sts = readByte(0x07);
  28. 35   delay(100);
  29. 36  
  30. 37   if (meas_sts == 0x10) {
  31. 38  
  32. 39     // Get PPM value
  33. 40     uint8_t value1 = readByte(0x05);
  34. 41     delay(5);
  35. 42     uint8_t value2 = readByte(0x06);
  36. 43     delay(5);
  37. 44  
  38. 45     // Calculate ppm value
  39. 46     int16_t result = value1 << 8 | value2;
  40. 47     Serial.print("CO2: ");
  41. 48     Serial.print(result);
  42. 49     Serial.println(" ppm");
  43. 50   }
  44. 51   delay(1000);
  45. 52 }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement