Breaking a CSV string down.

I receive data from my rocket and I want to display the Altitude (absalt) on the OLED display, but I get nothing. The display is setup ok because I can display other info. (signal strength)

The received string looks like this:
-2.91,23.54,101359,2884,608,15896,-5033,651,-5033,13161
-2.83,23.55,101357,2960,540,15768,-4982,-579,-4982,13250

The command I am trying (among others) to do this with is:
sscanf(LoRa.read, "%d,%d,%d,%d,%d,%d,%d,%d,%d,%d", absalt, temp, realpressure, accelXraw, accelYraw, accelZraw, gXraw, gYraw, gZraw, timer);

But I can't even get past compiling.
Below is the entire sketch. I have left in all my failed attempts REM'ed out.

#include <SPI.h>
#include <LoRa.h>
#include "U8glib.h"
// #include <string.h>

U8GLIB_SSD1306_128X64 u8g(U8G_I2C_OPT_NONE | U8G_I2C_OPT_DEV_0); // I2C / TWI

#define absalt
#define temp
#define realpressure
#define accelXraw
#define accelYraw
#define accelZraw
#define gXraw
#define gYraw
#define gZraw
#define timer

void setup() {
  Serial.begin(115200);
//  delay(10000); // I added this to give me time to open serial monitor. 
  while (!Serial);
  Serial.println("LoRa Receiver");
  if (!LoRa.begin(433E6)) {
    Serial.println("Starting LoRa failed!");
    while (1);
  }
}
void loop() {
  // try to parse packet
  int packetSize = LoRa.parsePacket();
  if (packetSize) {
    // received a packet
    Serial.print("Received packet '");
    // read packet
    while (LoRa.available()) {
      Serial.print((char)LoRa.read());
    }
    // print RSSI of packet
    Serial.print("' with RSSI ");
    Serial.println(LoRa.packetRssi());

//     Serial.println(subStr(LoRa.read(), ' ', 1));
//     sscanf((char)LoRa.read(), "%[^,],%[^,],%[^,],%[^,],%[^,],%[^,],%[^,],%[^,],%[^,],%[^,]", absalt, temp, realpressure, accelXraw, accelYraw, accelZraw, gXraw, gYraw, gZraw, timer);
  }
    // Label received variables
//   
//    sscanf(LoRa.read, "%d,%d,%d,%d,%d,%d,%d,%d,%d,%d", absalt, temp, realpressure, accelXraw, accelYraw, accelZraw, gXraw, gYraw, gZraw, timer);
//    sscanf(LoRa.read, "%[^,]", absalt);
//    sscanf(LoRa.read, "%[^,],%[^,],%[^,],%[^,],%[^,],%[^,],%[^,],%[^,],%[^,],%[^,]", absalt);


  u8g.firstPage();
    do { 
      u8g.setFont(u8g_font_unifont);
      u8g.drawStr( 0, 35, "Rssi = ");
      u8g.setPrintPos(50, 35);
      u8g.print(LoRa.packetRssi());
      u8g.drawStr( 0, 55, "S/N = ");      
      u8g.setPrintPos(50, 55);
      u8g.print(LoRa.packetSnr());
      
  }
  while( u8g.nextPage() );
    }

If you could tell me what the line should look like that would be great. Please don't refer me to any web pages. I've scoured many so far. I am not very good at programming and have already spent days trying to work this out. Seriously - spell it out for me if you know the answer.
Many thanks.

The received string looks like this:
-2.91,23.54,101359,2884,608,15896,-5033,651,-5033,13161
-2.83,23.55,101357,2960,540,15768,-4982,-579,-4982,13250

And is of what type ? I suggest you first store it in a variable before you attempt to parse it.
I am not familiar with the LoRa.h so i don't know what type is being returned by LoRa.packetRssi() or LoRa.read()But if you store the data in a "String" or a "c-string" (preferred) first then parsing it afterwards becomes a lot more straightforward.

Have a look at the parse example in Serial Input Basics

...R

Hi Deva_Rishi - LoRa.packetRssi() and LoRa.packetSnr() come from the LoRa receiver and display signal strength. They display ok.

LoRa.read() = -2.91,23.54,101359,2884,608,15896,-5033,651,-5033,13161
This is the one I am having problems with.

All my code is from examples that I have put together and then spent weeks trying to get the smallest problems worked out. I have absolutely no knowledge in programming.
Storing something in a String or Cstring I have no idea where to even start.

Hi Robin2 - does example 5 relate to what I am trying to do?
I have saved and will spend some time trying to understand it.

Thank you both for your efforts.

Hi RedeyePete,

if "spending mutliple weeks" on trying to get it to work means 50-100 hours of sitting in front of the screen
I recommend learning programming. In the end learning programming Iwill be faster and much more satisfying.

I recommend this tutorial: startingelectronics learn-to-program

I have looked inside the tutorials of Arduino.cc. If I compare them with the tutorial above
the Arduino.cc-Tutorials are harder to understand because they don't reduce complexity of the commands.
In the Arduino.cc-Tutorials each command is explained with all aspects at once using technical terms that are not all explained before their first use. This is what makes any stuff hard to understand.

The startingelectronics-tutorial is easier to understand startingelectronics arduino/learn-to-program-course/

From your sketch I can conclude that your knowledge is on an improvable level ;-))
You can go on for weeks and months trying all kinds of things without really knowing what you are doing
or

You can spend three days each day 5-6 hours reading copy&paste small examples but then start to modify these example by yourself and doing so understanding how it works!

Compare these two imaginations with each other. Of course to become a real good coder takes months and years but the basic understanding will come within three days if you use a good tutorial.

Come on ! :slight_smile: Give it a try! :slight_smile: :slight_smile:
If you have any questions while working with the tutorial come back here to ask,
If the other users see that you are a learning newbee it will be a joy for them to help.
best regards
Stefan

RedeyePete:
Hi Robin2 - does example 5 relate to what I am trying to do?
I have saved and will spend some time trying to understand it.

Yes that's the appropriate one.

...R

Hi Deva_Rishi - LoRa.packetRssi() and LoRa.packetSnr() come from the LoRa receiver and display signal strength. They display ok.

yes but they don't just magically appear on your Serial monitor !
that must somehow happen here :

// read packet
    while (LoRa.available()) {
      Serial.print((char)LoRa.read());
    }

so i think you should be able to tap that into Robin's tutorial.

IMO, sending and receiving CSV ASCII characters is the wrong approach for this application. For telemetry data like this, the same data packet format should be sent and received every time, only the values should change. So, put everything in a struct and send it in binary. On the RX end you only need to memcpy() the data (once you've determined that a valid packet was received) into an identical struct. Then, almost as if by magic, all the data fields will be populated with the correct values.

#define absalt

"#define" does not declare a program variable. Its just a compiler directive. What you mean is:

float absalt;
sscanf(LoRa.read, "%d,%d,%d,%d,%d,%d,%d,%d,%d,%d", absalt, temp, realpressure, accelXraw, accelYraw, accelZraw, gXraw, gYraw, gZraw, timer);

"sscanf" parses a string (character array). You are giving it a single character returned by a function. You need to read the whole string into memory, then parse it. "%d" only parses int. You need to parse floats (%f), ints (%d) & longs (%ld) depending on which type of variable will receive the value. On Uno, you cannot even use %f, if I remember. You could use %s to read the value into another string, then use atof() I think.

Or you could simply use strtok() to tokenise the string and atoi(), atol(), atof().

If the lora library implements Stream class, and it sounds like it might, you may be able to use LoRa.parseInt() and LoRa.parseFloat(), which would mean you would not need to read the string into memory of use sscanf(), strtok(), atoi() etc.

Comms with these types of radios is inherently packet-based, so Stream is a poor fit. Hence, my suggestion in Reply #7 to treat it as a packet-based system.