Arduino connecte Temp Sensor


I ran the same code on both Arduino Opta and Arduino Uno to read temperature data, using the A0 port for analog output in both cases. I used the same temperature sensor, the DS18B20, with a 5V power supply for both boards. However, I encountered a strange issue: even though the code and sensor are identical, the readings on the Opta are consistently incorrect, while they are accurate on the Uno. What I find particularly odd is that the sensor works on the A0 port of the Arduino Uno but not on the Opta.

#include <OneWire.h>
#include <DallasTemperature.h>

// Data wire is conntec to the Arduino digital pin 4
#define ONE_WIRE_BUS A0


// Setup a oneWire instance to communicate with any OneWire devices
OneWire oneWire(ONE_WIRE_BUS);

// Pass our oneWire reference to Dallas Temperature sensor 
DallasTemperature sensors(&oneWire);

void setup(void)
{
  // Start serial communication for debugging purposes
  Serial.begin(9600);
  // Start up the library
  sensors.begin();
}

void loop(void){ 
  // Call sensors.requestTemperatures() to issue a global temperature and Requests to all devices on the bus
  sensors.requestTemperatures(); 
  int randomNumber = random(0, 100); 
  Serial.print("Celsius temperature: ");
  // Why "byIndex"? You can have more than one IC on the same bus. 0 refers to the first IC on the wire
  Serial.print(sensors.getTempCByIndex(0)); 
  Serial.print(" - Fahrenheit temperature: ");
  Serial.println(sensors.getTempFByIndex(0));
  Serial.println(randomNumber); 
  delay(1000);
}

Have you tried other pins of the opta?

Not familiar with that processor, could it be that A0 is input only for the Opta?

Hello @steven_takeshi,
Before its latest release (2.3.8), the OneWire library was not compatible with Arduino boards based on STM32H747XI MCU. Uploading the sketch causes the Mbed OS to crash.

With the latest release, the sketch is uploaded successfully, but the output on the serial monitor is the same even without having a sensor connected.

You can check the OneWireNg library: GitHub - pstolarz/OneWireNg: Arduino 1-wire service library. OneWire compatible. Dallas thermometers support.

On the other hand you can have a look at the Analog Expansion module supporting PT100 RTDs: https://docs.arduino.cc/tutorials/opta/user-manual/#analog-rtd-input-mode

Best,

The analog channel in voltage mode can measure up to 10 VDC, and the ADC resolution is 16-bit. You’ll need to adjust your code to account for this. As far as I know, the DS18B20 provides a digital output, not an analog one.

I try other pins, it is always give me same output.