Like many, I struggled for a long time to get things working reliably. Finally some progress the last couple days. The biggest leap forward for me was learning about the PingPong sketch, and using it to implement evidence based testing. Along with a couple other small tricks.
If you are having radio trouble (or reliability trouble in general), I highly recommend starting out with the PingPong sketch, aka GettingStarted.ino example in the RF24 library. In fact, I think I will be flashing this first on all new radio nodes, to test my soldering / assembly, as well as positioning of the node initially, etc.
As an aside, I also started using PlatformIO recently, I personally find it much less confusing than the official Arduino IDE (and now I can use a real editor! ). I only mention it because that is the serial monitor command you will see below.
I am also on GNU/Linux, so I collected my data with a simple tee command on the output of pio device monitor, like so:
$ platformio device monitor -b 115200 -p /dev/ttyUSB<X> | tee test<Y>
I then make a copy of the file and call it test<Y>-trimmed
, which I then edit by hand to remove header lines at top and also the lines like "*** CHANGING TO TRANSMIT ROLE -- PRESS 'R' TO SWITCH BACK
", etc. So we end up with only result lines like the following:
Now sending 92111...ok...Got response 92111, round-trip delay: 28
Now sending 93139...ok...Got response 93139, round-trip delay: 29
Now sending 94170...ok...Got response 94170, round-trip delay: 34
Now sending 95205...ok...Failed, response timed out.
Now sending 96408...ok...Got response 96408, round-trip delay: 23
Now sending 97432...ok...Got response 97432, round-trip delay: 23
Now that I have a "trimmed" file containing only lines of results, I wrote a small bash script to calculate some things from there a little more easily:
#!/bin/bash
lines_total=$(cat "$1" | wc -l)
lines_response=$(grep 'Got response' "$1" | wc -l)
percent=$(echo "100 * $lines_response / $lines_total" | bc -l)
artd=$(grep 'round-trip delay: ' "$1" | rev | cut -c -2 | rev | awk '{ sum+=$1 } END { print sum/NR }' )
printf 'Lines of Response: %s\n' "$lines_response"
printf 'Lines Total: %s\n' "$lines_total"
printf 'Response %%: %.2f\n' "$percent"
printf 'Average Round Trip Delay (ARTD): %.2f\n' "$artd"
I save it as calculate
, make it executable ($ chmod +x calculate
) and then execute it with the name of the filename to process like $ ./calculate test1-trimmed
which would return something like:
Lines of Response: 801
Lines Total: 1016
Response %: 78.84
Average Round Trip Delay (ARTD): 25.75
I then plug these results into a table in Orgmode in Emacs, carefully accounting for each variable I thought might be relevant:
|----+----+----+-------+----+-----+-----+----+-----+------+------+--------+-------+---|
| TN | SL | RL | STC | SC | SCL | RTC | RC | RCL | LR | LT | R % | ARTD | N |
|----+----+----+-------+----+-----+-----+----+-----+------+------+--------+-------+---|
| 1 | 1 | 1 | 1,3,4 | 1 | 12 | 2 | 1 | 21 | 878 | 906 | 96.91 | 28.16 | |
| 2 | " | 2 | " | " | " | " | " | " | | | | | |
| 3 | " | " | " | 2 | " | " | 2 | " | 801 | 1016 | 78.84 | 25.75 | 1 |
| 4 | " | 3 | " | " | " | " | " | " | 910 | 959 | 94.89 | 23.68 | |
| 5 | " | 4 | " | " | " | " | " | " | 853 | 946 | 90.17 | 25.22 | |
| 6 | 6 | " | " | " | " | " | " | " | 871 | 875 | 99.54 | 23.73 | 2 |
| 7 | " | 5 | " | " | " | " | " | " | 28 | 289 | 9.69 | 40.39 | |
| 8 | " | 7 | " | " | " | " | " | " | 684 | 684 | 100.00 | 22.91 | 3 |
| 9 | " | " | " | 1 | " | " | 1 | " | 600 | 1042 | 57.58 | 34.47 | |
| 10 | " | " | " | 3 | " | " | 3 | " | 1014 | 1051 | 96.48 | 24.58 | |
| 11 | | | | | | | | | | | | | |
|----+----+----+-------+----+-----+-----+----+-----+------+------+--------+-------+---|
- Key:
- Abbreviations:
- TN = Test Number
- SL = Sender Location
- RL = Receiver Location
- STC = Sender Test Conditions
- SC = Sending Capacitance
- SCL = Sending Cable Length (mm)
- RTC = Receiver Test Conditions
- RC = Receiver Capacitance
- RCL = Receiver Cable Length (mm)
- LR = Lines Response
- LT = Lines Total
- R % = Response %
- ARTD = Average Round Trip Delay
- N = Notes
- Keys:
- Locations:
1. desk in front of keyboard
2. coffee table living room
3. dining room table
4. kitchen counter by stove
5. floor by front door (previous door switch radio location)
6. On top of both CPU towers, then plastic box
7. front door but higher up
- Test Conditions:
1. Arduino Nano 5v
2. Arduino Pro Mini 3.3v
3. Mismatched length power cables
4. ferrite choke on USB power cable to computer
- Capacitor(s):
1. single 4.7uF capacitor
2. 1uF + 10uF capacitors
- Notes:
1. A lot of interference from me moving my chair/body(?) in between and banging tools on the
table.
2. Antenna in vertical plane, face toward dining room table.
3. Took some effort to align plane of receiving antennae face to face.
Now, I am no where nearly as talented in electronics and radios as some of the guys on this forum, however I do know how to follow basic scientific principles and do experiments... And by doing so, I have been able to learn quite a lot about radio propagation, electronics (ideal decoupling capacitor values), as well as things particular to my own site conditions here. And this is what I wanted to share. Even if you are not an expert, you can do the same and get a much better result.
For me, I feel like I am finally making some progress (instead of throwing darts in the dark)!
A few other little details. I want to talk about decoupling capacitors. I know it is already mentioned frequently, but doing experiments as above you can test and really see the difference for yourself.
First, how to attach the caps? I saw in someone's YouTube video (Great Scott! I think it was) where he had soldered the cap to the top part of the nRF board, I mean where the stub of the header pokes through the board, where you would be soldering to attach the header, opposite side of where you would attach your dupont cables. I thought this was a great idea and I started doing it, too. Keeps it out of the way, and insures a good electrical connection. I never really liked just jamming the leads of the cap into the back of the dupont connector housing. I never was sure it was making a good connection, the wires are easy to bend and they are different lengths, etc... just a big hassle. This way is much better!
Secondly, about decoupling capacitor values. I have heard all kinds of stuff thrown around, from 4.7uF to 47uF to 100uF, and then some people even saying to combine a 0.1uF and a 10uF in parallel. I get the impression, that in most of cases (except the parallel case, or in the case of you few EEs out there ) that most people are just guessing, and/or parroting stuff they heard somewhere.
I did a bit of research on this, even started watching one of EEVBlog videos about it (until I started dozing off, lol). Now, I am no EE for sure, but there appears to be something to the parallel thing, which I was able to bear out in testing. Check some of my results above where I purposefully kept all conditions the same, except for swapping out radios with different decoupling capacitor setups. The results (for me at least) were dramatic. For instance look at tests 8 and 9. Now I didn't have a 0.1uF cap on hand, so I used the smallest one I could find which was 1uF + a 10uF. And with that arrangement, 100% Response %! Compared to 57.58% with a single 4.7uF cap. This is at maybe 20m distance inside, through 1 or 2 walls with metal studs and drywall.