CCCPaste

SPI protocol

#include  // Include the SPI library

const int slaveSelectPin = 10; // SS pin

void setup() {
  pinMode(slaveSelectPin, OUTPUT); // Set SS pin as output
  SPI.begin(); // Initialize SPI
  Serial.begin(9600); // Start serial communication
}

void loop() {
  digitalWrite(slaveSelectPin, LOW); // Select the sensor
  SPI.transfer(0x00); // Send read command
  int temp = SPI.transfer(0x00); // Read temperature data
  digitalWrite(slaveSelectPin, HIGH); // Deselect the sensor

  Serial.print("Temperature: ");
  Serial.println(temp);

  delay(1000); // Wait for 1 second before next reading
}