I have tried 3 codes, similar to each, but didnt work
1)
#include<SoftwareSerial.h>
SoftwareSerial SUART(0,1);
void setup()
{
Serial.begin(9600);
SUART.begin(9600);
}
void loop()
{
SUART.print('A'); //sending A using SUART port
byte n = SUART.available();
if(n != 0)
{
char x = SUART.read();
Serial.println(x);
}
delay(1000);
}
#include <SoftwareSerial.h>
#include <string.h>
#include <stdio.h>
uint8_t recv_char;
char recv_str[20];
int i=0;
SoftwareSerial mySerial(6, 7); // RX, TX
#define LED 8
void setup()
{
Serial.begin( 2400 ); //Set the baund rate as 2400 for arduino serial
Serial.println("USB Serial is ready");
mySerial.begin( 2400 ); // set the baund rate for the SoftwareSerial port
pinMode(LED, OUTPUT);
digitalWrite(LED,LOW);
}
void loop()
{
if ( mySerial.available() )
{
recv_char = mySerial.read();
if(recv_char == '\r'){
recv_str[i] = '\0';
if(!strcmp(recv_str, "ON")){
digitalWrite(LED,HIGH);
Serial.println("high");
}
if(!strcmp(recv_str, "OFF")){
digitalWrite(LED,LOW);
Serial.println("low");
}
Serial.println(recv_str); // Write the serial from MAX3232 to Arduino serial
i=0;
memset(recv_str, 0, sizeof(recv_str));
}
else{
if(recv_char == '\r' || recv_char == '\n'){
}
else{
recv_str[i++] = recv_char;
}
}
}
if ( Serial.available() )
{
recv_char = Serial.read();
if(recv_char == '\r'){
recv_str[i] = '\0';
mySerial.println(recv_str); // Write the serial from MAX3232 to Arduino serial
i=0;
memset(recv_str, 0, sizeof(recv_str));
}
else{
if(recv_char == '\r' || recv_char == '\n'){
}
else{
recv_str[i++] = recv_char;
}
}
}
}
3)`void setup() {
// Initialize serial communication at the baud rate of the weighing scale
Serial.begin(9600); // Change 9600 to the baud rate of your weighing scale
}
void loop() {
// Check if data is available to read
if (Serial.available() > 0) {
// Read the incoming data
String data = "";
while (Serial.available() > 0) {
char inChar = (char)Serial.read();
data += inChar;
delay(5); // Small delay to ensure the complete data is read
}
// Print the data to the Serial Monitor
Serial.println("Weighing Scale Data: " + data);
}
}`