Radar-Sensor on Softserial / I2C Display does not work

Hi Guys,

I'm currently building a Radar-device to see the speed of cars passing my house.
Since my daughter was born, I'm a little less tolerant about speeding :wink:

EDIT: Look at the end first, I guess I found the source of the problem, but I'm not smart enough to solve it...

At the end of the day, it will be installed at a Raspberry Pi, but actually I'm doing some testing and for this task I use some Arduino-Uno. (Which is the reason I need to use SoftSerial).

So I have bought a radar-sensor from Aliexpress, it sends the measured speeds via serial.

That works fine when I copy the output from the soft-serial to the serial-console.
This is my hand at the sensor (++++ / ---- is the direction):

AltSoftSerial Test Begin
v (km/h) is 2.380----
v (km/h) is 2.197----
v (km/h) is 2.380----
v (km/h) is 2.197--/-
v (km/h) is 2.197++++
v (km/h) is 2.197++++
v (km/h) is 2.197++++
v (km/h) is 2.197++++
v (km/h) is 2.197++++
v (km/h) is 2.197++++
v (km/h) is 2.197----
v (km/h) is 2.197----
v (km/h) is 2.197----
v (km/h) is 2.197----
v (km/h) is 2.197----
v (km/h) is 2.197--/-
v (km/h) is 2.197++++
v (km/h) is 2.197++++
v (km/h) is 2.197++++
v (km/h) is 2.197++++
v (km/h) is >.197++++
v (km/h) is 2.197++++
v (km/h) is 2.197++++
v (km/h) os 2.197++++
v (km/h) is 2.197++++
v (km/h) is 2.197++++
v (km/h) is 2.197++++
v (km/h) is 2.197----
v (km/h) is 2.197----
v (km/h) is 2.380----
v (km/h) is 2.197----
v (km/h) is 2.197----
v (km/h) is 2.197++++
v (km/h) is 2.197++++
v (km/h) is 2.380++++
v (km⸮h) is 2.197++++
v (km/h) is 2.197----
v (km/h) is 2.197++++

This is the code I use:

#include <AltSoftSerial.h>

AltSoftSerial altSerial;

void setup() 
{ 
  Serial.begin(9600);
  Serial.println("AltSoftSerial Test Begin");
  altSerial.begin(115200);
  }

void loop() {
  char c;
   
  if (altSerial.available()) {
    c = altSerial.read();
    Serial.print(c);
    
}
}

Then I'd like to display it to the (20 by 4) I2C-display:

#include <AltSoftSerial.h>
#include <LiquidCrystal_I2C.h>
AltSoftSerial altSerial;
LiquidCrystal_I2C lcd(0x27,20,4);  // set the LCD address to 0x27 

void setup() 
{ 
//LCD Initialisieren
  lcd.init();
  lcd.backlight();
  lcd.home();
  lcd.clear();

  Serial.begin(9600);
  Serial.println("AltSoftSerial Test Begin");
  altSerial.begin(115200);
  }

void loop() {
  char c;
  String RADAR;

  
  if (altSerial.available()) {
    c = altSerial.read();
    Serial.print(c);
    RADAR = c;
}
//lcd.setCursor ( 0, 0 );        // go to the next line
//lcd.print(RADAR);
}

Here goes the serial-output:

AltSoftSerial Test Begin
v⸮(mh) is 2190-⸮--
 (m⸮[⸮⸮&⸮1?7,--,
v (om/h) is&⸮197-
--
v (hm⸮h) is 2⸮19----
v (km/h( ip ⸮.197+(++
v (kl/h) ip ⸮.187++(+
v (kl/h( is 2380++++v ⸮[⸮[⸮⸮6⸮,X6--,-
v (k
/h( ip 3.103
--,
v ⸮[⸮[⸮⸮

The display also only shows garbage. (It shows in one symbol 3 horizontal lines, nothing else)
But even when I use the display at all (Hello world / or whatever), the serial-console only shows garbage.
Any idea?

EDIT: I have added a delay of 100ms after the LCD prints:
I can see that single characters are sent to the display and console as well.
Unfortunately I did not know that there is no incoming string but single-characters only.
So let me change the question: How can I assemble the single-chars into a string which ends with each line-feed?! And the other question here below...

And besides, any good idea how I can "disassemble the char into the speed-number (float) and some bool for the direction?!
Regards,
Maeffjus

How can I assemble the single-chars into a string which ends with each line-feed?!

Add each character to an array of chars as it arrives and terminate the array with '\0' to turn it into a string for printing

any good idea how I can "disassemble the char into the speed-number (float) and some bool for the direction

What is the exact format of the string to be split ?
strtok() will do the job if the data is delimited

Thanks for the answer, Bob!
So I have found some code that can do this (add the readout to a string).
But then another two problems came up, so now there are still two.
(I guess I can cut the string with strtok by myself - most likely ;-))

This is what I use now:

#include <AltSoftSerial.h>
#include <LiquidCrystal_I2C.h>
AltSoftSerial altSerial;
LiquidCrystal_I2C lcd(0x27,20,4);  // set the LCD address to 0x27 for a 16 chars and 2 line display

const byte numChars = 32;
char receivedChars[numChars];   // an array to store the received data

boolean newData = false;

void setup() {
      lcd.init();
  lcd.backlight();
  lcd.home();
  lcd.clear();

  Serial.begin(9600);
  Serial.println("AltSoftSerial Test Begin");
  altSerial.begin(115200);
}

void loop() {
    recvWithEndMarker();
    showNewData();
}

void recvWithEndMarker() {
    static byte ndx = 0;
    char endMarker = '\n';
    char rc;
   
    while (altSerial.available() > 0 && newData == false) {
        rc = altSerial.read();

        if (rc != endMarker) {
            receivedChars[ndx] = rc;
            ndx++;
            if (ndx >= numChars) {
                ndx = numChars - 1;
            }
        }
        else {
            receivedChars[ndx] = '\0'; // terminate the string
            ndx = 0;
            newData = true;
        }
    }
}

void showNewData() {
    if (newData == true) {
       Serial.println(receivedChars);
       lcd.setCursor ( 0, 0 );        // go to the next line
       lcd.clear();
       lcd.print(receivedChars);
        newData = false;
       
    }
}
  1. The faster the speeds are reported (at least it seems so), the more "crap" is coming-in.
    Still some of the readings are weird and I don't know why.
    These look like:

v (hm⸮h) is 2⸮19----
v (km/h( ip ⸮.197+(++
v (kl/h) ip ⸮.187++(+

Any idea? Does the Arduino skip some chars or what could possibly happen?

  1. When a car passes by, the speed is updated constantly, so the sensor is reporting VERY fast. (Faster than the display can show)
    But this also gives a ton of data. Do you have any idea, what I could do to find a high speed in a range of, lets say 10s? (for this to work, the problem with the "wrong" symbols need to be solved.
    I think somehow the way to go is:

a) cut-out the raw number from the reported values (v (km/h) is 2.380----), so remove the "v (km/h) is " and the "++++ / ----".
b) somehow gather them, if the speed reported is beyond a certain threshold (if beyond, for e.g. 25km/h) for 10s.
c) find the highest number in these 10s and save it / display it.

Any ideas? I can do some basic programming, but I'm worlds apart from being good at all..
Regards,
Maeffjus

Okay, only one point is left, I have now changed to a NodeMCU V3 and I use its UART.
Now the speeds come-in without any problem of wrong symbols.

The only other, major point is, how to get the whole set of data from 10-20s (whatever) and get the highest and maybe an average?

Regards,
Maeffjus