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
//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)