user79883: I'm trying to use softwareserial to exchange datas with a sensor.
After some tries without any answer from the sensor, I checked the arduino TX with my scope and what I've seen is not what I've sended.
My original byte array (before the setup function):
static byte simple_write[] = {0xfe, 0x41, 0x00, 0x80, 0x01, 0x10, 0x28, 0x7e};

What I got on my scope:
0X77 , 0x61 , 0x69 , 0x74 , ...
Every single sent byte is wrong. I don't understand why.
The only thing on the way is a bridge divider to reduce 5V TTL from the arduino to 3,3V CMOS.
If someone have an idea, thanks in advance.
EDIT2: I use IS.MDuino.21+ (ATmega2560)
EDIT: Here are the parts of my code who involve the softwareserial
    #include "SoftwareSerial.h"

    SoftwareSerial LP8_Serial(1, 0);

    static byte simple_write[] = {0xfe, 0x41, 0x00, 0x80, 0x01, 0x10, 0x28, 0x7e}; //Write 0x010 to address 0x0080

void setup(){
LP8_Serial.begin(9600); //Opens the virtual serial port with baud of 9600
}

void loop(){

LP8_val1 = GetDatas_uart();

}

int GetDatas_uart() {
  if (first_loop == 0) {
    //reset_device();  // includes a 500 msec delay
    sendRequest(simple_write, 8, 4); // send to address 0x0080 a 0x10
    first_loop = 1;
  }
  else
    sendRequest(write_to_0x20, 8, 4); // send to address 0x0080 a 0x10
  delay(2000);
  unsigned long valCO2 = getValue(response);
  delay(3000);
  Serial.println("Now reading 32 bytes");   //sendRequest(read_16_bytes,7,21);
  sendRequest(read_32_bytes, 7, 37);
  Serial.print("CO2 from 0x9a-0x9b = ");
  Serial.print(response[29], HEX);
  Serial.print(response[30], HEX);
  Serial.print(" = ");
  int decimal = 256 * response[29] + response[30];
  Serial.print(decimal);
  Serial.println("d");

  return decimal;
}

void sendRequest(byte packet[], int m, int n)
{
  while (!LP8_Serial.available()) //keep sending request until we start to get a response
  {
    Serial.println("waiting for Software.serial port availability");
    LP8_Serial.write(packet, m);
    //LP8_Serial.write(simple_write, m);
    delay(1000); // Necessary to get consistent loading of response[i]
  }
  int timeout = 0; //set a timeout counter
  while (LP8_Serial.available() < n ) //Wait to get a n byte response
  {
    timeout++;
    if (timeout > 10) //if it takes too long there was probably an error
    {
      while (LP8_Serial.available()) //flush whatever we have
        LP8_Serial.read();
      break; //exit and try again
    }
    delay(50);
  }
  for (int i = 0; i < n; i++)
  {
    response[i] = LP8_Serial.read();
    //    Serial.print("response[i] = ");
    Serial.print("response[");
    Serial.print(i);
    Serial.print("] = ");
    Serial.println(response[i], HEX);
  }
  Serial.print("\n\n");
  Serial.flush();
}


user79883: Sooo, I feel a little ashamed...
After re-reading the documentation of the Arduino from Industrial Shields I use (model 21+), I discovered that using Serial0 on this board is unadvised because these pins are shared with USB.
I connected my serial wires to the Serial1 connection and now, my scope show me exactly what I wanted to see on my TX line.
Sorry for that. Like often, the problem whas between the screen and the chair.
Thanks,

79883: <p>I'm trying to use softwareserial to exchange datas with a sensor.
After some tries without any answer from the sensor, I checked the arduino TX with my scope and what I've seen is not what I've sended.</p>
<p>My original byte array (before the setup function):</p>
<pre><code>static byte simple_write[] = {0xfe, 0x41, 0x00, 0x80, 0x01, 0x10, 0x28, 0x7e};
</code></pre>
<p>What I got on my scope:</p>
<p>0X77 , 0x61 , 0x69 , 0x74 , ...</p>
<p>Every single sent byte is wrong. I don't understand why.
The only thing on the way is a bridge divider to reduce 5V TTL from the arduino to 3,3V CMOS.</p>
<p>If someone have an idea, thanks in advance.</p>
<p>EDIT2: I use IS.MDuino.21+ (ATmega2560)</p>
<p>EDIT: Here are the parts of my code who involve the softwareserial</p>
<pre><code>    #include &quot;SoftwareSerial.h&quot;

    SoftwareSerial LP8_Serial(1, 0);

    static byte simple_write[] = {0xfe, 0x41, 0x00, 0x80, 0x01, 0x10, 0x28, 0x7e}; //Write 0x010 to address 0x0080

void setup(){
LP8_Serial.begin(9600); //Opens the virtual serial port with baud of 9600
}

void loop(){

LP8_val1 = GetDatas_uart();

}

int GetDatas_uart() {
  if (first_loop == 0) {
    //reset_device();  // includes a 500 msec delay
    sendRequest(simple_write, 8, 4); // send to address 0x0080 a 0x10
    first_loop = 1;
  }
  else
    sendRequest(write_to_0x20, 8, 4); // send to address 0x0080 a 0x10
  delay(2000);
  unsigned long valCO2 = getValue(response);
  delay(3000);
  Serial.println(&quot;Now reading 32 bytes&quot;);   //sendRequest(read_16_bytes,7,21);
  sendRequest(read_32_bytes, 7, 37);
  Serial.print(&quot;CO2 from 0x9a-0x9b = &quot;);
  Serial.print(response[29], HEX);
  Serial.print(response[30], HEX);
  Serial.print(&quot; = &quot;);
  int decimal = 256 * response[29] + response[30];
  Serial.print(decimal);
  Serial.println(&quot;d&quot;);

  return decimal;
}

void sendRequest(byte packet[], int m, int n)
{
  while (!LP8_Serial.available()) //keep sending request until we start to get a response
  {
    Serial.println(&quot;waiting for Software.serial port availability&quot;);
    LP8_Serial.write(packet, m);
    //LP8_Serial.write(simple_write, m);
    delay(1000); // Necessary to get consistent loading of response[i]
  }
  int timeout = 0; //set a timeout counter
  while (LP8_Serial.available() &lt; n ) //Wait to get a n byte response
  {
    timeout++;
    if (timeout &gt; 10) //if it takes too long there was probably an error
    {
      while (LP8_Serial.available()) //flush whatever we have
        LP8_Serial.read();
      break; //exit and try again
    }
    delay(50);
  }
  for (int i = 0; i &lt; n; i++)
  {
    response[i] = LP8_Serial.read();
    //    Serial.print(&quot;response[i] = &quot;);
    Serial.print(&quot;response[&quot;);
    Serial.print(i);
    Serial.print(&quot;] = &quot;);
    Serial.println(response[i], HEX);
  }
  Serial.print(&quot;\n\n&quot;);
  Serial.flush();
}
</code></pre>
 79883: <p>Sooo, I feel a little ashamed...</p>
<p>After re-reading the documentation of the Arduino from Industrial Shields I use (model 21+), I discovered that using Serial0 on this board is unadvised because these pins are shared with USB.</p>
<p>I connected my serial wires to the Serial1 connection and now, my scope show me exactly what I wanted to see on my TX line.</p>
<p>Sorry for that. Like often, the problem whas between the screen and the chair.</p>
<p>Thanks,</p>
