Trying the SonarMote code on Arduino NANO.
Wiring done as per the SonarMote sketch.
Starting for the first time, it reports correct distance.
QuoteTransmitting at 868 Mhz, id:22 nid:250 gid:1
28.49cm BAT:2.58 - ACK:NOK...
28.49cm BAT:2.58 - ACK:OK! RSSI:-38
27.15cm BAT:2.58 - ACK:NOK...
27.15cm BAT:2.58 - ACK:NOK...
26.32cm BAT:2.58 - ACK:NOK...
26.32cm BAT:2.58 - ACK:NOK...
0cm BAT:2.58 - ACK:NOK...
0cm BAT:2.58 - ACK:OK! RSSI:-40
But dose not report the correct distant once the previous distance is 0cm
Serial output
Quote.39 - ACK:NOK...
.39 - ACK:NOK...
.45 - ACK:NOK...
.45 - ACK:NOK...
.07 - ACK:NOK...
.07 - ACK:NOK...
.98 - ACK:NOK...
.98 - ACK:NOK...
.11 - ACK:NOK...
.11 - ACK:NOK...
.39 - ACK:NOK...
.39 - ACK:NOK...
.86 - ACK:NOK...
.86 - ACK:NOK...
.40 - ACK:OK! RSSI:-39
.91 - ACK:NOK...
.91 - ACK:NOK...
.31 - ACK:NOK...
.31 - ACK:NOK...
.45 - ACK:NOK...
.45 - ACK:NOK...
.13 - ACK:NOK...
.13 - ACK:NOK...
.74 - ACK:NOK...
.74 - ACK:NOK...
.01 - ACK:NOK...
.01 - ACK:NOK...
.45 - ACK:NOK...
.45 - ACK:NOK...
.72 - ACK:NOK...
.72 - ACK:OK! RSSI:-40
To get it back I need to restart .
This issue happens only when powerDown is commented at the end of the loop function.
radio.sleep();
SERIALFLUSH();
//LowPower.powerDown(sleepTime, ADC_OFF, BOD_OFF); //put microcontroller to sleep to save battery life
}
You might need to give it enough time after power up for the sonar sensor to get a good reading.
The timings I put in the sample sketches are usually a good starting point that I try to test but you might need to play around and see what gets you the best result.
Also the HC-SR04 sensors can be a little tricky and finicky but usually they work just fine, try what I suggested above.
Hi Felix,
The sensor was left powered on for more the 3 days and I don't think its the issue with the HC-SR04 sensor. I added Serial.print before the diff calculation as below.
if (distReadLoops-- <= 0)
{
distance = readDistance(READ_SAMPLES);
distReadLoops = DIST_READ_LOOPS - 1;
}
Serial.print("Distnace: ");
Serial.println(distance);
float diff = distance - prevDistance;
if ((diff > HISTERESIS || diff < -HISTERESIS) || (sendLoops-- <= 0)) //only send a new message if the distance has changed more than the HISTERESIS or if sendloops has expired
{and this is the output.
QuoteDistance: 27.14
27.14cm BAT:3.48 - ACK:NOK...
Distance: 27.14
27.14cm BAT:3.48 - ACK:NOK...
Distance: 110.33
110.33cm BAT:3.48 - ACK:NOK...
Distance: 110.33
110.33cm BAT:3.48 - ACK:OK! RSSI:-34
Distance: 0.00
0cm BAT:3.48 - ACK:NOK...
Distance: 0.00
0cm BAT:3.48 - ACK:NOK...
Distance: 6.88
88 - ACK:NOK...
Distance: 6.88
88 - ACK:NOK...
Distance: 18.12
.12 - ACK:NOK...
Distance: 18.12
.12 - ACK:NOK...
Distance: 6.93
93 - ACK:NOK...
Distance: 6.93
93 - ACK:OK! RSSI:-34
Distance: 0.00
93 - ACK:NOK...
for some reason (which I have no idea) the buff is having values after the decimal point. Any clue?
Quote from: mario.almeida on February 14, 2017, 12:44:50 PM
The sensor was left powered on for more the 3 days and I don't think its the issue with the HC-SR04 sensor. I added Serial.print before the diff calculation as below.
The sample sketch turns OFF the sensor, otherwise your battery will not last.
So every time you power it back on you have to be careful to make sure it has enough time from power on before it takes a reading, some first readings may be invalid.
Why you get decimals is up to your code and how you format it.
Hi Felix,
Sorry for not making it clear, my mistake. NANO is powered from USB port without battery. Below code is commented which is at the end of the loop function.
//LowPower.powerDown(sleepTime, ADC_OFF, BOD_OFF); //put microcontroller to sleep to save battery lifeI also commented LowPower.powerDown in the entire sketch and also
//#include <LowPower.h> but still no luck.
Finally change the code as below.
char DISTstr[10] ="99999.99cm"; //longest distance reading message = 5charsand
if (distance > MAX_DISTANCE || distance < MIN_DISTANCE)
sprintf(DISTstr, "%s", "0"); // zero, out of range
else dtostrf(distance,3,2, DISTstr); and below is the output after the change which is working fine. I'll continue testing the code for some more days and update the post accordingly.
QuoteTransmitting at 868 Mhz, id:22 nid:250 gid:1
BAT:2.83 - ACK:NOK...
0cm BAT:2.83 - ACK:NOK...
0cm BAT:2.83 - ACK:NOK...
0cm BAT:2.83 - ACK:NOK...
0cm BAT:2.83 - ACK:NOK...
20.43cm BAT:2.83 - ACK:NOK...
20.43cm BAT:2.83 - ACK:NOK...
19.28cm BAT:2.83 - ACK:NOK...
19.28cm BAT:2.83 - ACK:NOK...
18.10cm BAT:2.83 - ACK:NOK...
18.10cm BAT:2.83 - ACK:NOK...
0cm BAT:2.83 - ACK:NOK...
0cm BAT:2.83 - ACK:NOK...
0cm BAT:2.83 - ACK:NOK...
0cm BAT:2.83 - ACK:NOK...
0cm BAT:2.83 - ACK:NOK...
0cm BAT:2.83 - ACK:NOK...
0cm BAT:2.83 - ACK:NOK...
0cm BAT:2.83 - ACK:NOK...
6.09cm BAT:2.83 - ACK:NOK...
6.09cm BAT:2.83 - ACK:NOK...
16.90cm BAT:2.83 - ACK:NOK...
16.90cm BAT:2.83 - ACK:NOK...
0cm BAT:2.83 - ACK:NOK...
0cm BAT:2.83 - ACK:NOK...
8.90cm BAT:2.83 - ACK:NOK...
8.90cm BAT:2.83 - ACK:OK! RSSI:-36
12.93cm BAT:2.83 - ACK:NOK...
12.93cm BAT:2.83 - ACK:NOK...
6.52cm BAT:2.83 - ACK:NOK...
6.52cm BAT:2.83 - ACK:NOK...
109.64cm BAT:2.83 - ACK:NOK...
109.64cm BAT:2.83 - ACK:NOK...
0cm BAT:2.83 - ACK:NOK...
0cm BAT:2.83 - ACK:NOK...
0cm BAT:2.83 - ACK:NOK...
0cm BAT:2.83 - ACK:NOK...
16.14cm BAT:2.83 - ACK:NOK...
16.14cm BAT:2.83 - ACK:NOK...
16.78cm BAT:2.83 - ACK:OK! RSSI:-38
0cm BAT:2.83 - ACK:NOK...
0cm BAT:2.83 - ACK:NOK...
0cm BAT:2.83 - ACK:NOK...
0cm BAT:2.83 - ACK:NOK...
0cm BAT:2.83 - ACK:NOK...
0cm BAT:2.83 - ACK:NOK...
109.50cm BAT:2.83 - ACK:NOK...
109.50cm BAT:2.83 - ACK:OK! RSSI:-32
0cm BAT:2.83 - ACK:NOK...
0cm BAT:2.83 - ACK:NOK...
0cm BAT:2.83 - ACK:NOK...
0cm BAT:2.83 - ACK:OK! RSSI:-31
0cm BAT:2.83 - ACK:NOK...
0cm BAT:2.83 - ACK:NOK...
109.97cm BAT:2.83 - ACK:NOK...
109.97cm BAT:2.83 - ACK:OK! RSSI:-32
0cm BAT:2.83 - ACK:NOK...
0cm BAT:2.83 - ACK:NOK...
It's designed to be used with battery but USB power is OK also...
If you modify the working sketch then I recommend starting from a working point (good readings) and work from there.
What is "NANO" ?
Revisiting your first post it looks like you are using an Arduino Nano.
Can you describe how you are using SonarMote? Do you have a SonarMote kit or how do you use the sketch?
Hi Felix,
Sorry for the late reply.
Sketch is deployed on Arduino NANO and the sensor is connected to pin 6 (TRIG), 7 (ECHO) , GND to GND and VCC to +5v of Arduino NANO.
OK I think you meant SonarMote sketch + ArduinoNano.
My sketches are only tested and supported on the hardware I make. I cannot support any 3rd party hardware.
Thanks Felix.
I only have 3 moteinos.
1 - MoteinoUSB connected to RPi
2 - SwitchMote Inuse
3 - and just a moteino, I'll use this once to test the sketch.
It is too expensive for me to order from lowepower labs with the shipping cost. I had a spare ArduinoNANO which I want to make use of. BTW, is it possible to share the schematic of SonarMote?
Sometimes using cheap/fake/clone/wrong hardware will cost you many times more in wasted time. But people never learn :-\
Here's the schematic:
(http://i.imgur.com/d2yXChE.png)
Thanks Felix for the schematic.