Help with interfacing Arduino Uno with RAK811

Oh my god… I finally got it working :wink: I always used the wrong AT command to change the baudrate from 115200 to 9600!

I now used the RAK SERIAL PORT TOOL (v1.2.1) to set the baudrate:

at+set_config=device:uart:1:9600

After that I needed to switch the RX/TX jumpers to:

RXD <--> TX
TXD <--> RX

Now everything is working fine with your library :partying_face:

3 Likes

Well,that’s great. :smile: :smile:

Hey dude, I discovered in your comments that you could make a “combination” between Arduino Uno and RAK 811, how did you do it?

Seb my man, do you have a WisNode - a RAK811 on a board that can plug in as a shield, or are you like, rad enough to wire up a breakout board.

Hit me up with your reply!

1 Like

I have a question, I am quite new to this field, have you tried a sensor connected to arduino atmega and rak 811 with a sensor?

I’m trying to send a data from the sensor to display to TTN.

I have a gateway, rak 811 v1.2 and atmega.

I’m a bit confused on how to set it up. Like send the data. I’m using the temp sensor for example.

My rak811 can now be seen on TTN, problem now is how do I send the data into a readable format.

Thanks in advance!

What you need to do is program the Arduino to do EXACTLY the same thing as the Serial Tool when you issue commands.

So you need to connect the Arduino to the RAK811 serial port and use the RAK supplied library that will do most of the coding work for you:

There are three things to pay real attention to:

  1. You will need to MANUALLY set the Baud rate of the RAK811 to 9600 BEFORE you start - the Arduino can’t talk at 115200 - you aren’t sending much info over the serial link, so 9600 isn’t as slow as it sounds.
  2. The block that sets the working mode in the Arduino script needs to be removed - when you set the working mode, the RAK module will need restarting / resetting - which isn’t allowed for in the library so it will just stop there. Set this manually whilst you are setting the baud rate. You only need to do this once as the module will remember the settings you set.
  3. You will need some sort of level convertor if you have an Arduino Uno, Nano or indeed other that runs at 5V as the RAK811 runs at 3.3V and you don’t want to release the magic smoke.

If you have the Wisnode/Arduino Shield, the library provides all the information you need, including what jumpers to set depending on which version you have. If you just have a breakout modules, here’s mine:

You’ll see that I have in fact wired in a reset and that I’m so rich, I live life to the edge and don’t bother with a level converter. Please look at the RAK811 breakout module info and an Arduino Nano pinout to figure out the micro-details of the connections.

1 Like

I have a question. How do you this?
I mean, I only take out the #define WORK_MODE LoRaWAN from the code? or I have to modify something from the library?

“The block that sets the working mode in the Arduino script needs to be removed - when you set the working mode, the RAK module will need restarting / resetting - which isn’t allowed for in the library so it will just stop there. Set this manually whilst you are setting the baud rate. You only need to do this once as the module will remember the settings you set.”

Comment out the block that starts with the if statement or delete it?

Hello! Do u have a sample code of this that is merged w/ a sensor?

The first step is to write code to read the sensor.

Then you can add the result from the sensor to the buffer[].

Hopefully this gets you going, I can knock up something later on this week if you can bare with me.

Sure, I’m looking forward this week.

https://github.com/ztfnky/sensorCode/blob/main/FlowmeterSimplestCode_withsource.ino

This is my sensor code.

I edited the previous answer to add the float conversion for you. This would a way to solve your problem.
Float -> char -> add another char with something you may want, like sensor name -> merge them -> print(buffer, hex)

Please, note the this is was added inside the RAK811.cpp file, you need to create your own function for this.

bool RAK811::rk_sendData(int port, char *datahex)
{
  // String command = "";
  command = "at+send=lora:" + (String)port + ":";// + datahex;
  // _serial1.println(command);

  float resistance = 123.45;
  char res[7];
  dtostrf(resistance, 6, 2, res);

  char hi[3] = {0};
  hi[0] = 'h';
  hi[1] = 'i';
  hi[2] = '\0';

  char buffer[strlen(hi) + strlen(res) + 1];
  sprintf(buffer, "%s:%s", hi, res);

  Serial.println(buffer);

  command = command;// + converter(teste);
  Serial.println(command);

  while (_serial.available())
  {
    _serial.read();
  }
  //_serial1.println(cmd);
  _serial.print(command);

  for(int i=0;i<(strlen(hi) + strlen(res) + 1);i++){
    _serial.print(buffer[i], HEX);
  }
  _serial.println("");


  delay(200);
  return true;
  
  //sendRawCommand(command);

  return true;  
}

Here is the TTN print of the received payload.

And the hex payload converted to ascii.

1 Like

Whilst this does move things forward, it will have rendered the library specific only to this sensor.

The code should be put in the main ino and the hex string then passed to the rk_sendData.

Additionally, sending payloads as strings is considered wasteful - conversion to an integer (usually by multiplying by 10, 100 or 1000 etc as appropriate) and then byte packing / shifting is strongly encouraged. As far as the TTN forumites think, any other way is wrong, a heinous crime and bad for the network.

I definitely agree with @nmcc regarding floats. The best approach is to multiply it with 10, 100, etc. then do the conversion on the decoder side of the network server. It is just a simple javascript. But @SWoto’s code above can work as well and you can easily add char or string on your payload. However, if you are only going to send just float values, @nmcc advise is really recommended.

Sadly all too easy - I’ve yet to come across a really good reason for sending plain text in a LoRaWAN payload.

Conversely, I have a very messed up set of utilities I use to bit-pack so if, for example I only need 0-15, I only use 4 bits and the other 4 are used for another value - it handles all the fun of crossing byte boundaries. Perhaps I should clean it up and release it.

1 Like

I think with what i’m going to say I might be stepping outside the topic question, though I’m not sure because it is related with the replies. Mods, please correct me if I’m wrong.

@nmcc, @carlrowan, regarding the discussion about sending it as int or float and the usage of plain text, if you have three sensors (assume temperature, humidity and pressure) how would you send it with LoRaWAN? Three frames with the value as int, or try to fit it in a frame separated by some character?

No, no, no, no, never, ever. Never ever think like that again or the LoRaWAN SWAT team will visit.

That implies three transmissions - three times you use you battery.

Try? Do or do not, there is no try!

The LoRaWAN SWAT team won’t come for this, they just send the LoRaWAN police around to fine you 100 batteries - as this will add to battery burn.

OK, I’ll stop encouraging a search using the forum, TTN forum or Mistress Google and go for the direct answer using Arduino code:

#define PAYLOAD_SIZE  6

void setup() {

  Serial.begin(9600);
  Serial.println("LoRaWAN using RAK library payload demo");
  
  int data[PAYLOAD_SIZE]; //  binary data structure with enough bytes for the payload
  
  int temperature = 20;
  int humidity = 35;
  int pressure = 935;

/* This is where you get your readings
  // Get your readings
  temperature = getTheTemperature();
  humidity = getTheHumidity();
  pressure = getThePressure();
*/

  // Transfer to the binary data structure
  data[0] = highByte(temperature);
  data[1] = lowByte(temperature);
  data[2] = highByte(humidity);
  data[3] = lowByte(humidity);
  data[4] = highByte(pressure);
  data[5] = lowByte(pressure);

  // Convert to a HEX string
  String payload = "";
  for(int c = 0; c < PAYLOAD_SIZE; c++) {

    if(data[c] < 0x10) {  // If it is less that 10, we'll need to put the 0 in as the Arduino String function doesn't pad with leading 0's
        payload += '0';
    }
    
    payload += String(data[c], HEX);
    
  }

  payload.toUpperCase(); // Converts in place, just to add to new programmer confusion

  Serial.print("Payload as Hex string: ");
  Serial.println(payload);

  // RAKLoRa.rk_sendData(1, payload) // This is where we send the payload

  // Note, buffer is a reserved word in Arduino, so I don't use buffer, I use payload, but the RAK examples do, your mileage may vary

}

void loop() {
}

Scroll inside the above box to see it all

4 Likes

My understanding is that the Uno and 811 can only be connected by wires due to different voltages / pin mismatch. Correct?

Not sure what the alternatives are to wires but …

The alternative is to use a Pro Mini.