Hello, I’m not very experimented and I have some trouble to connect an ultra sonic sensor ( A02YYUW) to my HTCC-AB01. The sensor Output is an UART output.
From what I’ve understood by reading some similar topics on this forum, there is only one serial connexion available and there is no library to create a virtual serial port. So my idea was to use the pins RX and TX to connect the sensors as I don’t really need to comunicate to my board throught the serial monitor.
But I don’t get the result I expected.
I tried many codes but the last one is this one :
#include “LoRaWan_APP.h”
unsigned char data[4]={};
float distance;
void setup()
{
Serial.begin(9600);
}
void loop()
{
do{
for(int i=0;i<4;i++)
{
data[i]=Serial.read();
turnOnRGB(10,1);
turnOffRGB();
}
}while(Serial.read()==0xff);
Serial.flush();
if(data[0]==0xff)
{
int sum;
sum=(data[0]+data[1]+data[2])&0x00FF;
if(sum==data[3])
{
distance=(data[1]<<8)+data[2];
if(distance>30)
{
//Serial.print(“distance=”);
//Serial.print(distance/10);
//Serial.println(“cm”);
turnOnRGB(1,1000);
turnOffRGB();
}else
{
// Serial.println(“Below the lower limit”);
turnOnRGB(25000,100);
turnOffRGB();
}
}else
{
distance=(data[1]<<8)+data[2];
turnOnRGB(data[2] * 10000,500);
turnOffRGB();
}
}
delay(1000);
}
Because I can’t use the serial monitor I use the RGB to understand where the errors are. At the moment it seems that it enter in the condition " if(data[0]==0xff)" but not in the “if(sum==data[3])” If I unplug the sensor and print sum and data[3], their values are 253 and 255.
If someone have an idea I would love to try it.
Thanks in advance