Go Down

Topic: Multiple DS18B20 and Reserve Question Mark (Read 207 times) previous topic - next topic

emrebulgur

I have 9 DS18B20 sensor and i use this code

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

// Data wire is plugged into digital pin 2 on the Arduino
#define ONE_WIRE_BUS 2

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

// Pass oneWire reference to DallasTemperature library
DallasTemperature sensors(&oneWire);

int deviceCount = 0;
float tempC;

void setup(void)
{
  sensors.begin();   // Start up the library
  Serial.begin(9600);
 
  // locate devices on the bus
  Serial.print("Locating devices...");
  Serial.print("Found ");
  deviceCount = sensors.getDeviceCount();
  Serial.print(deviceCount, DEC);
  Serial.println(" devices.");
  Serial.println("");
}

void loop(void)
{
  // Send command to all the sensors for temperature conversion
  sensors.requestTemperatures();
 
  // Display temperature from each sensor
  for (int i = 0;  i < deviceCount;  i++)
  {
    Serial.print("Sensor ");
    Serial.print(i+1);
    Serial.print(" : ");
    tempC = sensors.getTempCByIndex(i);
    Serial.print(tempC);
    Serial.print((char)176);//shows degrees character
    Serial.print("C  |  ");
    Serial.print(DallasTemperature::toFahrenheit(tempC));
    Serial.print((char)176);//shows degrees character
    Serial.println("F");
  }
 
  Serial.println("");
  delay(1000);
}


Serial Print export look like this

Sensor 1 : 34.06⸮C  |  93.31⸮F
Sensor 2 : 42.81⸮C  |  109.06⸮F
Sensor 3 : 28.00⸮C  |  82.40⸮F
Sensor 4 : 50.06⸮C  |  122.11⸮F
Sensor 5 : 23.06⸮C  |  73.51⸮F
Sensor 6 : 26.31⸮C  |  79.36⸮F
Sensor 7 : 24.12⸮C  |  75.43⸮F
Sensor 8 : 23.37⸮C  |  74.07⸮F


degree symbol appears as an inverted question mark. How do I fix this? Thank you.


Nick_Pyner


emrebulgur

I changed it, but it didn't fix
Try 130 instead of 176
I changed it, but it didn't fix.

I don't understand these things very well, but I've had a problem like this before and i wrote something similar and the problem was corrected. " ("\xC2\xB0");" but I can't remember exactly what the line is.

Budvar10

'\xB0' is hexa for 176 resp. octal \260. It depends on terminal type and character set. Normally it is 176.
Try 248 (\370 or \xF8).
If it wont work, print each character. One of them must be correct.
Arduino clone with ATmega1284P   http://forum.arduino.cc/index.php?topic=277260.0

emrebulgur

'\xB0' is hexa for 176 resp. octal \260. It depends on terminal type and character set. Normally it is 176.
Try 248 (\370 or \xF8).
If it wont work, print each character. One of them must be correct.
exactly where should I add the lines you say.

JCA34F

Copy this symbol  °   , and paste to a .txt file, when needed open the file , copy / paste the symbol. HEX is 0xCAB0.

Erik_Baas

#6
Oct 21, 2019, 12:16 am Last Edit: Oct 21, 2019, 01:01 am by Erik_Baas
Hold your Alt key while typing 0176 (not 176!) on the numeric keypad, that will give you the degree symbol.

Edit: Doesn't show on LCD or serial monitor, sorry...

Erik_Baas

Serial monitor will only print characters with ASCII values from 32 to 126. Now, on an LCD you could create a "custom character", see createChar()...

Nick_Pyner

Serial monitor will only print characters with ASCII values from 32 to 126.
One has to wonder why you really need to do this at all, but I guess the above explains the problem. I only suggested 130 because ALT+0130 delivers a degree symbol in my CAD. Maybe using a proper terminal, like RealTerm, will deliver the goods.

Budvar10

#9
Oct 21, 2019, 07:54 pm Last Edit: Oct 21, 2019, 07:55 pm by Budvar10
exactly where should I add the lines you say.
Like this:
Code: [Select]
Serial.print("\260C  |  ");
octal representation of the character.

See the C/C++ escape sequences for details. Like here (the first I quickly found):

https://docs.microsoft.com/en-us/cpp/cpp/string-and-character-literals-cpp?view=vs-2019


Arduino clone with ATmega1284P   http://forum.arduino.cc/index.php?topic=277260.0

Go Up