Issues with SEN0395 and ESP32
I have just purchased a bunch of SEN0395 sensors for a project. If successful we will run this for all our devices.
However I have some serious issues getting it going as I want.
We are using Esp32 devices and I have followed your guide as good as I can.
https://wiki.dfrobot.com/mmWave_Radar_Human_Presence_Detection_SKU_SEN0395
This is the board pinout we are using:
https://arduino-projekte.info/wp-content/uploads/2020/12/D1_mini_ESP32_pinout.jpg
There are some information I cant seem to find really.
So first of some main questions:
1. RX/TX should these swap to TX/RX on my board?
2. Can I select other GPIO ports for RX/TX like you done in your guide? Or dose it have to be RX/TX (and then see question 1)?
3. In your example you do not use IO2 port. Googling there seems to be most that have used this have connected this port?
My Setup right now for testing:
Sensor RX → TX (GPIO01)
Sensor TX → RX (GPIO03)
Sensor IPO2 → GPIO16
Sensor GND → GND
Sensor V → VCC (5V)
So first test Im using ESPSoftwareSerial library since its not default with ESP32.
Here is the code:
#include <SoftwareSerial.h>
#include "DFRobot_mmWave_Radar.h"
SoftwareSerial mySerial(1, 3);
DFRobot_mmWave_Radar sensor(&mySerial);
void setup()
{
Serial.begin(115200);
mySerial.begin(115200);
pinMode(LED_BUILTIN, OUTPUT);
sensor.factoryReset(); //Restore to the factory settings
sensor.DetRangeCfg(0, 9); //The detection range is as far as 9m
sensor.OutputLatency(0, 0);
}
void loop()
{
int val = sensor.readPresenceDetection();
digitalWrite(LED_BUILTIN, val);
Serial.print("Detection result: ");
Serial.println(val);
delay(1000);
}
Result is this:
12:06:19.394 -> entry 0x400805e4
12:06:19.503 -> ⸮sensorStop
12:06:19.503 -> ⸮sensorStop is not recognized as a CLI command
12:06:19.503 -> Error
12:06:19.503 -> leapMMW:/>factoryReset 0x45670123 0xCDEF89AB 0x956128C6 0xDF54AC89
12:06:21.011 -> factory reset complete
12:06:21.044 -> Done
12:06:21.044 -> leapMMW:/>saveCfg 0x45670123 0⸮CDEF89AB 0⸮956128C6 0xDF54AC89
12:06:21.525 -> no parameter has changed
12:06:21.525 -> Error
12:06:21.525 -> leapMMW:/>sensorStart
12:06:22.616 -> Done
12:06:22.616 -> leapMMW:/>sensorStop
12:06:23.521 -> Done
12:06:23.521 -> leapMMW:/>detRangeCfG -1 0 60
12:06:24.532 -> detRangeCfG is not recognized as a CLI command
12:06:24.532 -> Error
12:06:24.532 -> leapMMW:/>saveCfg 0x45670123 0xCDEF89AB 0xr56128C6 0xDF54AC89
12:06:25.509 -> no parameter has changed
12:06:25.509 -> Error
12:06:25.509 -> leapMMW:/>sensorStart
12:06:26.630 -> Done
12:06:26.630 -> leapMMW:/>sensorStop
12:06:27.527 -> Done
12:06:27.527 -> leapMMW:/>outputLate~cy -1 0 0
12:06:28.519 -> outputLate~cy is not recognized as a CLI command
12:06:28.519 -> Error
12:06:28.519 -> leapMMW:/>saveCfg 0x45670123 0xCDEF89AB 0x956128C6 0x⸮F54AC89
12:06:29.534 -> no parameter has changed
12:06:29.534 -> Error
12:06:29.534 -> leapMMW:/>sensorStart
12:06:30.637 -> Done
12:06:30.637 -> leapMMW:/>
12:06:31.086 -> ..\User_code\main.c line:232
12:06:31.086 -> reset system
12:06:31.187 ->
12:06:31.187 -> leapMMW:/>$JYBSS,0, , , *
12:06:53.307 -> $JYBSS,0, , , *
12:06:54.286 -> $JYBSS,0, , , *
12:06:55.308 -> $JYBSS,0, , , *
12:06:56.284 -> $JYBSS,0, , , *
12:06:57.289 -> $JYBSS,0, , , *
12:06:57.546 -> $JYBSS,1, , , *
12:06:58.549 -> $JYBSS,1, , , *
12:06:59.566 -> $JYBSS,1, , , *
12:07:00.552 -> $JYBSS,1, , , *
So a bunch of errors but then I see the result and it works with 0 and 1. However I do not get any reading on sensor.readPresenceDetection and its even stuck and do not even get a faulty error.
I have tried swaping mySerial(1, 3) to mySerial(3, 1) but then nothing happens. Have also switched the cables so RX→RX and TX→TX but thats not working either.
Then second test I took the code you hade in your example instead where it uses HardwareSerial.
Here is the code:
#include <DFRobot_mmWave_Radar.h>
HardwareSerial mySerial(1);
DFRobot_mmWave_Radar sensor(&mySerial);
void setup()
{
Serial.begin(115200);
mySerial.begin(115200, SERIAL_8N1, 1, 3);//RX,TX
pinMode(LED_BUILTIN, OUTPUT);
sensor.factoryReset(); //Restore to the factory settings
sensor.DetRangeCfg(0, 9); //The detection range is as far as 9m
sensor.OutputLatency(0, 0);
}
void loop()
{
int val = sensor.readPresenceDetection();
digitalWrite(LED_BUILTIN, val);
Serial.print("Detection result: ");
Serial.println(val);
delay(1000);
}
This give me the exact same result as the other code.
So to sumerize. It feels like it has connection with the device since I get this type of result:
12:14:45.596 -> $JYBSS,1, , , *
12:14:46.562 -> $JYBSS,1, , , *
12:14:46.881 -> $JYBSS,0, , , *
12:14:47.880 -> $JYBSS,0, , , *
12:14:47.916 -> $JYBSS,1, , , *
It feels like the commands sent to the unit is not working and it feels like its not sending any results through the sensor. Probably since it looks like it crashed.
Any help on what Im doing wrong here?
Can someone provide the example code that Ludvigaldrin alluded to? I'm trying to use the GPIO2 pin to signal presence/absence but the sensor does not seem to be changing the IO pin. GPIO2 stays low. I know the SEN0395 is working since I can test it using the UART based code. I want to pair the SEN0395 with an ESP-01 so want just the GPIO2 pin for signaling to the ESP-01.
Joe.CloudThis is how I got it working in the end. The main issue was that my used mySerial.begin to the same port as the print out for Serial. That mean I did not get any data output.
I also could not use the
int val = sensor.readPresenceDetection();
that blocks the code completely.
I have used pins for me to just solder pins on all sensor ports and direct on to the ESP32 mini. So VCC/GND is deciding which legs are used for readPin and RX/TX
So for all you that are looking for a working example with DFRobot SEN0395 here it is:
#include <DFRobot_mmWave_Radar.h>
HardwareSerial mySerial(1);DFRobot_mmWave_Radar sensor(&mySerial);int readPin = 16; // where pinout GPIO2
void setup() {
pinMode(readPin, INPUT);
mySerial.begin(92600, SERIAL_8N1, 21, 22);// RX AND TX pinMode(LED_BUILTIN, OUTPUT); sensor.factoryReset(); //Restore to the factory settings sensor.DetRangeCfg(0, 1); //The detection range is as far as 9m sensor.OutputLatency(0, 0); Serial.begin(115200);}
void loop() { int val = digitalRead(readPin); digitalWrite(LED_BUILTIN, val); Serial.println("Detection result: "); Serial.println(val); delay(1000);
}
Hope it works out good for the rest of you
LudvigaldrinHi
For the HardwareSerial, the output shows it is working, see from WIKI, where 1 means people presence detected and 0 means No one.
For the SoftwareSerial, it seems that it go through some error, but at the end, it also output meaningful result ($JYBSS,0, , , * etc). Maybe there are something wrong with the softserial library with esp32, but it seems still working.
For the IO pin part. Yes, you can use GPIO2 to read the result of the sensor. Sorry for not providing demo code for it. You can just try to connect it to a digital pin on ESP32 and read its result.
Hope it can help!
Tonny12138Thanks. This got me on the right track. Se my code in the next comment