Communication between temperature Sensor and Arduino Uno with Rs 232 C

Hello everyone,

I am doing this post following a project aiming to make a temperature sensor communicate with an Arduino Uno board through a RS 232 protocol.

My communication seems to be established except that the response of the temperature sensor is not the one expected by the documentation but a completely crazy response.
Moreover, when I emulate the serial link thanks to the Hyperterminal connected to the arduino I can see that the right instructions are written and the right data are read.
I have also transmitted the instruction to the probe via Hyperterminal and I also have the right answer...

I also transmit my code to you in the hope that someone can help me...

Many thanks for all attempts to answer

PS: In the code there are also instructions to display the result of the comm on a screen don't be surprised :slight_smile:

//Created August 2020
//author JNU
//http://www.arduino.cc

#include <ctype.h>
#include <LiquidCrystal.h>

#define bit9600Delay 100  
#define halfBit9600Delay 50
#define bit4800Delay 188
#define halfBit4800Delay 94
#define RS 11
#define enable 10
#define d4  5  
#define d5  4
#define d6  3
#define d7  2  


LiquidCrystal lcd(RS,enable,d4,d5,d6,d7);

byte rx = 6;
byte tx = 7;
byte SWval;
char message[6]="#01VC"; // 01 est l'adresse VC la commande de lecture de température

void setup() {
  lcd.begin(16,2);
  lcd.clear();
 lcd.print("couc");
  Serial.begin(9600);
  pinMode(rx,INPUT);
  pinMode(tx,OUTPUT);
  digitalWrite(tx,HIGH);
  delay(2);
  digitalWrite(13,HIGH); //turn on debugging LED
  for (int i=0; i<6;i++ ) {
    SWprint(message[i]);
  }
 // SWprint('h');  //debugging hello
 // SWprint('i');
 // SWprint('n'); 
  SWprint(13);//carriage return
  SWprint(10);// Line feed 
 }

void SWprint(int data)
{
  byte mask;
  //startbit
  digitalWrite(tx,LOW);
  delayMicroseconds(bit9600Delay);
  for (mask = 0x01; mask>0; mask <<= 1) {
   // int a=data & mask;
   // Serial.println(a);
    if (data & mask){ // choose bit
     digitalWrite(tx,HIGH); // send 1
    }
    else{
     digitalWrite(tx,LOW); // send 0
    }
    delayMicroseconds(bit9600Delay);
  }
  //stop bit
  digitalWrite(tx, HIGH);
  delayMicroseconds(bit9600Delay);
}

int SWread()
{
  byte val = 0;
  while (digitalRead(rx)); // tant que c 'est rx=high
  //wait for start bit
  if (digitalRead(rx) == LOW) {
    delayMicroseconds(halfBit9600Delay);
    for (int offset = 0; offset < 8; offset++) { // sert a lire les bits de droite a gauche
     delayMicroseconds(bit9600Delay);
     val |= digitalRead(rx) << offset; // val = val ou digitalread(rx) val prend la valeur tapée au clavier
    }
    //wait for stop bit + extra
    delayMicroseconds(bit9600Delay);
    delayMicroseconds(bit9600Delay);
    return val;
  }
}

int rep[13];
int j=0;
int k=0;
String mess;

void loop() {
    if (j<13) {
      SWval=SWread();
      for (int k=0;k<12;k++) {
        rep[k]=SWread();
        mess=mess +String(rep[k]);
      }//for   
      Serial.print("Température : ");
      Serial.println((SWval)); 
      j++;
    lcd.print(mess);  
    }//if  
  //SWprint(toupper(SWval)); // change en majuscule
    
}

essai_projet_irtd.ino (2.33 KB)

Can you provide a link to the temperature sensor you are using.

If your temperature sensor is operating at RS232 voltages then you will need a MAX232 chip to convert to the TTL voltage levels that an Arduino uses. RS232 voltages may damage an Arduino.

...R

Yes I use and RS 232 Sheild see the following link : https://asset.conrad.com/media10/isa/160267/c1/-/fr/1310314_BB_00_FB/image.jpg?x=400&y=400

It is a Temperature Sensor called IRTD-400 constructor is Kaye.
Hier stand the most interesting part of the notice:

Example 1: Read value in °C.
To read the temperature in °C (VC for Value Celsius) from Probe
01, enter:
#01VC
The Intelligent RTD Probe responds with a value, such as:
VC = +22.388
This indicates that the sensor temperature is 22.388°C.
Note: The response to all Data Read commands is a 12-
character string. The first 3 characters are the two upper
case letters of the command plus an equal sign (=). The
remaining 9 characters indicate the value. A blank is a
character

AD: Read Probe Address
Format: #A1A2AD
Where:

= command lead-in

A1A2 = probe address 01-99
AD = command for reading the probe address
For example, to read (verify) the address at Probe 04, enter:
#04AD
The RTD Intelligent Probe responds with a value, such as:
AD = 04

VC: Read Sensor Value °C
Format: #A1A2VC
Where:

= command lead-in

A1A2 = probe address 01-99
VC = command for reading the sensor Value in °C
For example, to read the sensor Value in °C at Probe 35, enter:
#35VC
The RTD Intelligent Probe responds with a value, such as:
VC = +320.138

Setting the RS-232C Interface
If you are using a CRT or VDU, follow the manufacturer's
instructions to set the baud rate to 9600, the parity to N (none)
and the word length to 8 bits. Make sure that a carriage return
(CR) character is sent out from your terminal every time you
press RETURN or ENTER.
To test the communications link, enter the command:
#01VC
The temperature of the probe will be displayed on your screen in
degrees Celsius. (Commands are explained in detail in Chapter
4.)

It looks like you've tried to implement a software serial port instead of going with one of the existing software serial libraries. I've used AltSoftSerial with good results. You can find it here.

It is a software serial port so don't expect high baud rates. 9600 baud worked fine for me.

yes actually I didn't use the serial library so I am obliged to transmit byte by byte but I think my program is right anyway.
Im using 9600 baud.

Thanks for the link i will take a look