Pro micro, Serial1 and rs485 problem

Happy New Year!

Please help me to creating rs485 wired connection for Arduino pro micro. I want to connect Arduino Pro Micro with Raspberry Pi and I can`t do it. I want to solve this problem step by step. First, I tried to receive a signal to another arduino. I use arduino pro micro as an transmitter. And arduino nano as a receiver.

Connections:

arduino pro micro arduino nano

0 pin (TX) <-> 8 pin (software RX)

1 pin (RX) <-> 9 pin (software TX)

Transmitter code (pro micro)

void setup () {

  Serial1.begin (9600);
  }
void loop () {
  Serial1.write (1);
  Serial1.print (1);
  Serial1.print ("A");
  delay (500);
}

Receiver code (nano)

#include <SoftwareSerial.h>
// software serial # 1: RX = digital pin 8, TX = digital pin 9
SoftwareSerial portOne (8, 9);

void setup () {
  // Open serial communications and wait for port to open:
  Serial.begin (9600);
  while (! Serial) {
    ; // wait for serial port to connect. Needed for native USB port only
  }
  // Start each software serial port
  portOne.begin (9600);
}

void loop () {
  // By default, the last intialized port is listening.
  // when you want to listen on a port, explicitly select it:
  portOne.listen ();
  Serial.println ("Data from port one:");
  // while there is data coming in, read it
  // and send to the hardware serial port:
  while (portOne.available ()> 0) {
    char inByte = portOne.read ();
    Serial.print (inByte);
  }

  // blank line to separate data from the two ports:
  Serial.println ();
}

The transmitter is powered by charging. The receiver is connected to the USB port of the computer. The serial port monitor only outputs the following:

Data from port one:

Data from port one:

Data from port one:

Data from port one:

Why is the Serial1 port on pro micro not working and where is my mistake?

Have you a GND connection between the two Arduinos? It is essential.

Have a look at the examples in Serial Input Basics - simple reliable non-blocking ways to receive data. There is also a parse example to illustrate how to extract numbers from the received text.

The technique in the 3rd example will be the most reliable. It is what I use for Arduino to Arduino and Arduino to PC communication.

You can send data in a compatible format with code like this (or the equivalent in any other programming language)

Serial.print('<'); // start marker
Serial.print(value1);
Serial.print(','); // comma separator
Serial.print(value2);
Serial.println('>'); // end marker

…R

This is a New Year’s miracle!

Robin2:
Have you a GND connection between the two Arduinos? It is essential.


The technique in the 3rd example will be the most reliable. It is what I use for Arduino to Arduino and Arduino to PC communication.

It really worked.
Transmitter code now:

void setup() {
  Serial1.begin(9600);
}
void loop() {
Serial1.print('<'); // start marker
Serial1.print(1);
Serial1.print(','); // comma separator
Serial1.print("S");
Serial1.println('>'); // end marker
  delay(500);
}

Receiver code from your 3rd example with small modification. It work with arduino nano as receiver.
And work with PC. I run Putty as serial port monitor and receive al data in terminal.
Thanks a lot!
First and second step is OK. Now I will try to connect Raspberry.