Our first LoRa transmission from an Arduino NANO

published: 11 October 2020 / updated 11 October 2020

Lire cette page en français

 

Preparing for transmission

To make our very first transmission in FORTH language, with FlashForth on ARDUINO NANO, you must first set up two LoRa transmitters.

This setting is made via the Tera Term application (voir: Parameterization of the LoRa transmitter).

Master transmitter parameters:

// Chief:
AT+IPR=38400
AT+CRFOP=15
AT+NETWORKID=0
AT+BAND=865000000
AT+ADDRESS=22

Why is the Chef communicator assigned the address 22?

In French, the CHEF is four letters. Order of each letter in the alphabet: C=3, H=8, E=5, F=6...

We add 3 + 8 + 5 + 6 = 22

I am the BOSS (CHEF in french)

Second Transmitter Parameters::

// Second:
AT+IPR=38400
AT+CRFOP=15
AT+NETWORKID=0
AT+BAND=865000000
AT+ADDRESS=11

Wiring transmitter 22 (CHEF)

We wire our LoRa transmitter which has address 22 as follows:

CAUTION: the LoRa transmitter must be supplied with 3.3 Volts (with a margin up to 3.6 Volts). It turns out that our card Arduino NANO has a 3.3V terminal (red wire). The output voltage has been tested at voltmeter before wiring.

Photo of the wiring:

Only the TX wire has been wired from the TX output of the ARDUINO NANO board to the RX input of the LoRa transmitter.

Wiring the second transmitter

We wire our LoRa transmitter which has the address 11 as in the article
  REYAX RYLR890 LoRa transmitter test)

The serial link on ARDUINO NANO

The ARDUINO NANO card has only one serial port. If we type the word words from the terminal communicating with FlashForth, we see these words in particular:

These three words, rx0?, rx0 and tx0 are used to communicate with the serial port, precisely the port on which our LoRa transmitter is connected.

But the serial port of the ARDUINO NANO card is also used by the USB connector which is used to power the ARDUINO card and communicate with our Tera Term terminal!

So any character that appears on the terminal screen will also be transmitted to the LoRa transmitter...

So to simply transmit "HELLO" from our transmitter 22 to the other transmitter which has been given the address 11, it suffices to create this word for example:

: hello ( ---) 
    ." AT+SEND=11,5,HELLO" cr ; 

On power-up, the ARDUINO NANO card communicates at 38400 bps. It is for this because this baud rate has also been assigned to the LoRa transmitter.

From now on, if we cut the power to our ARDUINO NANO card, then that it is re-supplied, the transmission is initialized at 38400 bps between the ARDUINO NANO card and the LoRa transmitter. If we run our word hello, we will see it displayed on the terminal screen AT+SEND=11,5,HELLO. But as FlashForth shares this serial link with the LoRa transmitter, the word "HELLO" will be sent by the LoRa transmitter to the other transmitter which has the address 11.

Our first LoRa transmission

We connect the ARDUINO NANO card to a USB port of our microcomputer. Then we open the Tera Term terminal and we connect to our ARDUINO card (COM6 port in our test):

We connect the LoRa transmitter which has address 11 to another USB port. Then since Tera Term, we click on File and select New connection and we are connects to the second LoRa transmitter (COM7 port in our test):

We can immediately test our word hello from the left window.

A second later, we see displayed in the right window:
  +RCV=22,5,HELLO,-50,37

The pseudo command AT + RCV tells us that we have just received a message from transmitter 22, message 5 characters, message content HELLO. We are not going to process the other data at this time.

Definition of the word ATsend

As we have seen in the word hello , to transmit a message to the the LoRa transmitter, the word ." is therefore necessary and sufficient. The content of the message must respect the syntax of the AT + SEND command.

We could be satisfied with the word .", but that forces us to recalculate endlessly the length of the strings to transmit...

We are therefore going to create a kind of alias for the word . " in the style ._____" where we will put the word ATsend instead of _____

\ convert a number to a Forth code for FlahsForth:decimal string 
: .#s ( n ---) 
    base @ >r 
    0 <# #s #> type 
    r> base ! 
  ; 
 
\ Send data to the appointment Address n 
\ ex: AT+SEND=50,5,HELLO 
: (ATsend) ( LORAaddress str ---) 
    ." AT+SEND=" 
    rot .#s    \ convert LORAaddress to string and type 
    [char] , emit 
    dup .#s    \ convert str len to string and emit 
    [char] , emit 
    type 
  ; 
 
: .ATsend" ( LORAaddress ---) 
    postpone s" 
    postpone (ATsend) 
  ; immediate 

A carriage return (CR+LF) is required at the end of each AT sequence. We do not have not integrated this CR+LF in .ATsend" just as there is no CR + LF in the word .".

The word cr, under FlashForth, passes the codes $ OD $ 0A (CR LF). It will take so complete any .ATSend" transmssion with cr.

Here is a new version of the word hello using .ATsend":

: hello 
    11 .ATsend" This is our fisrt LoRa Transmission!" 
    cr ; 

Result on display:

We still have to manage the reception of messages in FORTH on ARDUINO:

LoRa transmission decoding on Arduino NANO