Skip to main content
Arduino

Return to Question

Rollback to Revision 3
Source Link
the busybee
  • 2.4k
  • 9
  • 18

I have a task to connect an external device with my arduino and transfer data to each other via the UART protocol. The external device has 4 pins (Two for power supply and RS-485A and RS-485B), and I need to connect these 4 pins to the arduino nano pins (Either directly to the TX and RX pins, or, if possible, via usb on the arduino board)

I'm having problems with this, the data is not being transmitted. To transfer data, I need to send an array of bytes to it (for a request). And inIn response he should send me a string in the form

PARAM1= data PARAM2= data PARAM3=data\r

The real data and parameters are called differently, but the gist is thisexternal device sends it as a string for further processing for arduino.

To check the correctness of the data reading and parsing algorithm, I wrote an intermediate program on a PC Which is, so to speak, a bridge between Arduino and another device. Thatthat sends an array of bytes to an external device (To request a string of data) and sends the received string to arduino. On arduino, everything was read and parsed correctly from the PC. And I need them to be connected directly.

The external device must can be connected via a special station, this station has a fee with CH340G and ADM3485EARZ chips and all kinds of strapping for them. That is, as I understand it, this board in the station serves as a USB to RS-485 converter? It needs to be connected to a PC via the same station.I would like to note that the external device has a CH340G chip.

I tried different connections. For example, I tried connecting through an Arduino USB or connecting directly without a stationto connect via the MAX485. However, neither of these methods workedbut it didn't work either. The connection lookedwas like this:

I set D4 to HIGH before sending it, and set it to LOW after sending it.

Here is a piece of firmware on Arduino (The code itself is not complete, for example, there was a button poll above the loop)

#include <Arduino.h>

#include <Wire.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27, 16,uint32_t 2);
flag = 0;
uint8_t dataToSend[] = {
 0x23,
 0x080x23,
 0x00,
 0x460x08,
 0x00,
 0x0a0x00,
 0xb8,
 0xa40x46,
};
uint32_t flag_core = 0;
void setup()
{
 Serial.begin(115200);0x00,
 lcd.init();
 lcd.backlight();0x0a,
 lcd.print("Waiting...");
 pinMode(40xb8, OUTPUT);
}

void loop()
{
 if (millis() - flag_core >= 250)0xa4,
 {};
 void digitalWritesetup(4, HIGH);
 delay(1);{
 Serial.write(dataToSend, sizeofbegin(dataToSend)115200);
 delay(1);}
 void digitalWriteloop(4, LOW);

 uint32_t start_time = millis();{
 whileif (millis() - start_timeflag <>= 50250)
 {
 if (Serial.availablewrite())
 {
 String response;
 response =dataToSend, Serial.readStringUntilsizeof('\r'dataToSend));
 uint32_t start_time = lcd.clearmillis();
 while lcd.setCursor(0,0millis();
  - start_time < lcd.print(response50);
 return;
{
 const char *resp =if response.c_str();
 const char *p1 = strstrSerial.available(resp, "PARAM1=");
 const char *p2 = strstr(resp, "PARAM2=");
 const char *p3 = strstr(resp, "PARAM3=");
{
 float ta = atof(p1 +String 7);response;
 int a = round(ta);
  float tbresponse = atofSerial.readStringUntil(p2 + 7'\r');
 int b = round(tb);

 float с = atof(p3 + 7);
 с// *=Data 1e6;parsing
 // Next, the output to the displaybreak;
 // ...}
 }
 flag = break;millis();
 }
 }
 flag_core = millis();
 }
}

I don't have any more information about the device. WhatWhat is my mistake?

I have a task to connect an external device with my arduino and transfer data to each other via the UART protocol. The external device has 4 pins (Two for power supply and RS-485A and RS-485B)

I'm having problems with this, the data is not being transmitted. To transfer data, I need to send an array of bytes to it (for a request). And in response he should send me a string in the form

PARAM1= data PARAM2= data PARAM3=data\r

The real data and parameters are called differently, but the gist is this

To check the correctness of the data reading and parsing algorithm, I wrote an intermediate program on a PC Which is, so to speak, a bridge between Arduino and another device. That sends an array of bytes to an external device (To request a string of data) and sends the received string to arduino. On arduino, everything was read and parsed correctly from the PC. And I need them to be connected directly.

The external device must can be connected via a special station, this station has a fee with CH340G and ADM3485EARZ chips and all kinds of strapping for them. That is, as I understand it, this board in the station serves as a USB to RS-485 converter? It needs to be connected to a PC via the same station.

I tried different connections. For example, I tried connecting through an Arduino USB or connecting directly without a station via the MAX485. However, neither of these methods worked. The connection looked like this:

Here is a piece of firmware on Arduino

#include <Arduino.h>

#include <Wire.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27, 16, 2);

uint8_t dataToSend[] = {
 0x23,
 0x08,
 0x00,
 0x46,
 0x00,
 0x0a,
 0xb8,
 0xa4,
};
uint32_t flag_core = 0;
void setup()
{
 Serial.begin(115200);
 lcd.init();
 lcd.backlight();
 lcd.print("Waiting...");
 pinMode(4, OUTPUT);
}

void loop()
{
 if (millis() - flag_core >= 250)
 {
 digitalWrite(4, HIGH);
 delay(1);
 Serial.write(dataToSend, sizeof(dataToSend));
 delay(1);
 digitalWrite(4, LOW);

 uint32_t start_time = millis();
 while (millis() - start_time < 50)
 {
 if (Serial.available())
 {
 String response;
 response = Serial.readStringUntil('\r');
 lcd.clear();
 lcd.setCursor(0,0);
  lcd.print(response);
 return;

 const char *resp = response.c_str();
 const char *p1 = strstr(resp, "PARAM1=");
 const char *p2 = strstr(resp, "PARAM2=");
 const char *p3 = strstr(resp, "PARAM3=");

 float ta = atof(p1 + 7);
 int a = round(ta);
  float tb = atof(p2 + 7);
 int b = round(tb);

 float с = atof(p3 + 7);
 с *= 1e6;
 // Next, the output to the display
 // ...
 
 break;
 }
 }
 flag_core = millis();
 }
}

I don't have any more information about the device. What is my mistake?

I have a task to connect an external device with my arduino and transfer data to each other via the UART protocol. The external device has 4 pins (Two for power supply and RS-485A and RS-485B), and I need to connect these 4 pins to the arduino nano pins (Either directly to the TX and RX pins, or, if possible, via usb on the arduino board)

I'm having problems with this, the data is not being transmitted. To transfer data, I need to send an array of bytes to it (for a request). In response, the external device sends it as a string for further processing for arduino.

To check the correctness of the data reading and parsing algorithm, I wrote an intermediate program on a PC that sends an array of bytes to an external device (To request a string of data) and sends the received string to arduino. On arduino, everything was read and parsed correctly from the PC. And I need them to be connected directly.

I would like to note that the external device has a CH340G chip.

I tried to connect via the MAX485, but it didn't work either. The connection was like this:

I set D4 to HIGH before sending it, and set it to LOW after sending it.

Here is a piece of firmware on Arduino (The code itself is not complete, for example, there was a button poll above the loop)


 uint32_t flag = 0;
uint8_t dataToSend[] = {
 0x23,
 0x08,
 0x00,
 0x46,
 0x00,
 0x0a,
 0xb8,
 0xa4,
 };
 void setup()
 {
 Serial.begin(115200);
 }
 void loop()
 {
 if (millis() - flag >= 250)
 {
 Serial.write(dataToSend, sizeof(dataToSend));
 uint32_t start_time = millis();
 while (millis() - start_time < 50)
 {
 if (Serial.available())
 {
 String response;
 response = Serial.readStringUntil('\r');
 
 // Data parsing
 break;
 }
 }
 flag = millis();
 }
 }

What is my mistake?

Post Reopened by sempaiscuba, Rohit Gupta, Greenonline
Added more information and code
Added to review
Source Link

I have a task to connect an external device with my arduino and transfer data to each other via the UART protocol. The external device has 4 pins (Two for power supply and RS-485A and RS-485B), and I need to connect these 4 pins to the arduino nano pins (Either directly to the TX and RX pins, or, if possible, via usb on the arduino board)

I'm having problems with this, the data is not being transmitted. To transfer data, I need to send an array of bytes to it (for a request). InAnd in response, the external device sends it as he should send me a string for further processing for arduino.in the form

PARAM1= data PARAM2= data PARAM3=data\r

The real data and parameters are called differently, but the gist is this

To check the correctness of the data reading and parsing algorithm, I wrote an intermediate program on a PC thatWhich is, so to speak, a bridge between Arduino and another device. That sends an array of bytes to an external device (To request a string of data) and sends the received string to arduino. On arduino, everything was read and parsed correctly from the PC. And I need them to be connected directly.

I would like to note that the external device has a CH340G chip. The external device must can be connected via a special station, this station has a fee with CH340G and ADM3485EARZ chips and all kinds of strapping for them. That is, as I understand it, this board in the station serves as a USB to RS-485 converter? It needs to be connected to a PC via the same station.

I tried to connectdifferent connections. For example, I tried connecting through an Arduino USB or connecting directly without a station via the MAX485. However, but it didn't work eitherneither of these methods worked. The connection waslooked like this:

I set D4 to HIGH before sending it, and set it to LOW after sending it.

Here is a piece of firmware on Arduino (The code itself is not complete, for example, there was a button poll above the loop)

#include <Arduino.h>
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C constexprlcd(0x27, int16, PIN_RE_DE2);
uint8_t dataToSend[] = 4;{
 uint32_t0x23,
 flag = 0; 0x08,
 uint8_t0x00,
 dataToSend[] = { 0x46,
 0x00,
 0x230x0a,
 0xb8,
 0x080xa4,
};

uint32_t flag_core = 0;
void setup()
{
 0x00,Serial.begin(115200);
 lcd.init();
 0x46,lcd.backlight();
 lcd.print("Waiting...");
 0x00pinMode(4, OUTPUT);
}
void loop()
{
 if (millis() - flag_core 0x0a,>= 250)
 {
 0xb8 digitalWrite(4, HIGH);
 0xa4,delay(1);
 };
 voidSerial.write(dataToSend, setupsizeof(dataToSend));
 { delay(1);
 Serial.begindigitalWrite(1152004, LOW);
 pinMode(PIN_RE_DE,uint32_t OUTPUTstart_time = millis();
 }
 voidwhile loop(millis() - start_time < 50)
 {
 if (millisSerial.available()) - flag >= 250)
 {
 digitalWrite(PIN_RE_DE, HIGH); String response;
 response = Serial.writereadStringUntil(dataToSend,'\r');
 sizeof 
 lcd.clear(dataToSend));
 digitalWrite lcd.setCursor(PIN_RE_DE0,0);
 LOW lcd.print(response);
 uint32_t start_time return;
  const char *resp = millisresponse.c_str();
 while (millis const char *p1 = strstr(resp, "PARAM1=");
 - start_time < 50 const char *p2 = strstr(resp, "PARAM2=");
 { const char *p3 = strstr(resp, "PARAM3=");

 iffloat (Serial.availableta = atof()p1 + 7);
 {int a = round(ta);

 float tb = atof(p2 String+ response;7);
 int b = round(tb);
 response float с = Serial.readStringUntilatof('\r'p3 + 7);
 с *= 1e6;
 // DataNext, parsing
the output to the display
 break;// ...
 }
 } break;
 }
 flag = millis(); }
 flag_core }= millis();
 }
}

WhatI don't have any more information about the device. What is my mistake?

I have a task to connect an external device with my arduino and transfer data to each other via the UART protocol. The external device has 4 pins (Two for power supply and RS-485A and RS-485B), and I need to connect these 4 pins to the arduino nano pins (Either directly to the TX and RX pins, or, if possible, via usb on the arduino board)

I'm having problems with this, the data is not being transmitted. To transfer data, I need to send an array of bytes to it (for a request). In response, the external device sends it as a string for further processing for arduino.

To check the correctness of the data reading and parsing algorithm, I wrote an intermediate program on a PC that sends an array of bytes to an external device (To request a string of data) and sends the received string to arduino. On arduino, everything was read and parsed correctly from the PC. And I need them to be connected directly.

I would like to note that the external device has a CH340G chip.

I tried to connect via the MAX485, but it didn't work either. The connection was like this:

I set D4 to HIGH before sending it, and set it to LOW after sending it.

Here is a piece of firmware on Arduino (The code itself is not complete, for example, there was a button poll above the loop)

 constexpr int PIN_RE_DE = 4;
 uint32_t flag = 0;
 uint8_t dataToSend[] = {
 0x23,
 0x08,
 0x00,
 0x46,
 0x00,
 0x0a,
 0xb8,
 0xa4,
 };
 void setup()
 {
 Serial.begin(115200);
 pinMode(PIN_RE_DE, OUTPUT);
 }
 void loop()
 {
 if (millis() - flag >= 250)
 {
 digitalWrite(PIN_RE_DE, HIGH);
 Serial.write(dataToSend, sizeof(dataToSend));
 digitalWrite(PIN_RE_DE, LOW);
 uint32_t start_time = millis();
 while (millis() - start_time < 50)
 {
 if (Serial.available())
 {
 String response;
 response = Serial.readStringUntil('\r');
 // Data parsing
 break;
 }
 }
 flag = millis();
 }
 }

What is my mistake?

I have a task to connect an external device with my arduino and transfer data to each other via the UART protocol. The external device has 4 pins (Two for power supply and RS-485A and RS-485B)

I'm having problems with this, the data is not being transmitted. To transfer data, I need to send an array of bytes to it (for a request). And in response he should send me a string in the form

PARAM1= data PARAM2= data PARAM3=data\r

The real data and parameters are called differently, but the gist is this

To check the correctness of the data reading and parsing algorithm, I wrote an intermediate program on a PC Which is, so to speak, a bridge between Arduino and another device. That sends an array of bytes to an external device (To request a string of data) and sends the received string to arduino. On arduino, everything was read and parsed correctly from the PC. And I need them to be connected directly.

The external device must can be connected via a special station, this station has a fee with CH340G and ADM3485EARZ chips and all kinds of strapping for them. That is, as I understand it, this board in the station serves as a USB to RS-485 converter? It needs to be connected to a PC via the same station.

I tried different connections. For example, I tried connecting through an Arduino USB or connecting directly without a station via the MAX485. However, neither of these methods worked. The connection looked like this:

Here is a piece of firmware on Arduino

#include <Arduino.h>
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27, 16, 2);
uint8_t dataToSend[] = {
 0x23,
  0x08,
 0x00,
  0x46,
 0x00,
 0x0a,
 0xb8,
 0xa4,
};

uint32_t flag_core = 0;
void setup()
{
 Serial.begin(115200);
 lcd.init();
 lcd.backlight();
 lcd.print("Waiting...");
 pinMode(4, OUTPUT);
}
void loop()
{
 if (millis() - flag_core >= 250)
 {
  digitalWrite(4, HIGH);
 delay(1);
 Serial.write(dataToSend, sizeof(dataToSend));
  delay(1);
 digitalWrite(4, LOW);
 uint32_t start_time = millis();
 while (millis() - start_time < 50)
 {
 if (Serial.available()) {
  String response;
 response = Serial.readStringUntil('\r');
  
 lcd.clear();
  lcd.setCursor(0,0);
  lcd.print(response);
  return;
  const char *resp = response.c_str();
  const char *p1 = strstr(resp, "PARAM1=");
  const char *p2 = strstr(resp, "PARAM2=");
  const char *p3 = strstr(resp, "PARAM3=");

 float ta = atof(p1 + 7);
 int a = round(ta);

 float tb = atof(p2 + 7);
 int b = round(tb);
 float с = atof(p3 + 7);
 с *= 1e6;
 // Next, the output to the display
 // ...
 
  break;
 }
  }
 flag_core = millis();
 }
}

I don't have any more information about the device. What is my mistake?

Post Closed as "Needs details or clarity" by hcheung, VE7JRO, Rohit Gupta
added 156 characters in body
Source Link
 constexpr int PIN_RE_DE = 4;
 uint32_t flag = 0;
 uint8_t dataToSend[] = {
 0x23,
 0x08,
 0x00,
 0x46,
 0x00,
 0x0a,
 0xb8,
 0xa4,
 };
 void setup()
 {
 Serial.begin(115200);
 pinMode(PIN_RE_DE, OUTPUT);
 }
 void loop()
 {
 if (millis() - flag >= 250)
 {
 digitalWrite(PIN_RE_DE, HIGH);
 Serial.write(dataToSend, sizeof(dataToSend));
 digitalWrite(PIN_RE_DE, LOW);
 uint32_t start_time = millis();
 while (millis() - start_time < 50)
 {
 if (Serial.available())
 {
 String response;
 response = Serial.readStringUntil('\r');
 
 // Data parsing
 break;
 }
 }
 flag = millis();
 }
 }

 uint32_t flag = 0;
 uint8_t dataToSend[] = {
 0x23,
 0x08,
 0x00,
 0x46,
 0x00,
 0x0a,
 0xb8,
 0xa4,
 };
 void setup()
 {
 Serial.begin(115200);
 }
 void loop()
 {
 if (millis() - flag >= 250)
 {
 Serial.write(dataToSend, sizeof(dataToSend));
 uint32_t start_time = millis();
 while (millis() - start_time < 50)
 {
 if (Serial.available())
 {
 String response;
 response = Serial.readStringUntil('\r');
 
 // Data parsing
 break;
 }
 }
 flag = millis();
 }
 }
 constexpr int PIN_RE_DE = 4;
 uint32_t flag = 0;
 uint8_t dataToSend[] = {
 0x23,
 0x08,
 0x00,
 0x46,
 0x00,
 0x0a,
 0xb8,
 0xa4,
 };
 void setup()
 {
 Serial.begin(115200);
 pinMode(PIN_RE_DE, OUTPUT);
 }
 void loop()
 {
 if (millis() - flag >= 250)
 {
 digitalWrite(PIN_RE_DE, HIGH);
 Serial.write(dataToSend, sizeof(dataToSend));
 digitalWrite(PIN_RE_DE, LOW);
 uint32_t start_time = millis();
 while (millis() - start_time < 50)
 {
 if (Serial.available())
 {
 String response;
 response = Serial.readStringUntil('\r');
 
 // Data parsing
 break;
 }
 }
 flag = millis();
 }
 }
formatted text
Source Link
jsotola
  • 1.5k
  • 2
  • 12
  • 20
Loading
added 64 characters in body
Source Link
Loading
Source Link
Loading

AltStyle によって変換されたページ (->オリジナル) /