[riot-notifications] [RIOT-OS/RIOT] drivers/srf04: incorrect values on ATmega based platforms (#13079)

gdiribarne notifications at github.com
Sun Nov 22 19:43:41 CET 2020


Hello,

I have read all the exchanges. I needed to use sfr04 with a arduino-mega2560 and I have the same issue. I reproduced and fixed the issue. @kaspar030 had a good solution which consists in adapting the int32_t distance inside the sfr04_dev structure.

The main issue is here, since on AVR, it creates an overflow for AVR integer. 
      return ((dev->distance * 100) / SRF04_DISTANCE);
However, the function result may return an int since the 2 mm <= distance is <= 4000 mm.

I needed to adapt the test using different pin
- The echo pin requires to be a interrupt pin
- The trigger pin is not necessarily an interrupt pin

If you need, I can manage the pull-request issue and propose a patch (I added also some comments, etc.) which would be my first contrib to the RIOT OS ;-) The resulting tests are conform to expected. I didn't notice any issue with bad reading or so.
While reading the code, I had some other ideas to make the srf04 code. I'll propose a new pull request.

Here is the result of the test:
main(): This is RIOT! (Version: 2021.01-devel-997-g63af2)
SRF04 range finder example
D: 2029 mm
D: 2016 mm
D: 2016 mm
D: 2016 mm
D: 2030 mm
D: 2020 mm
D: 2016 mm
D: 2030 mm
D: 2020 mm
D: 2021 mm
D: 2029 mm
D: 2029 mm
D: 2016 mm
D: 2020 mm
D: 2020 mm
D: 2016 mm
D: 2015 mm
D: 2021 mm
D: 2016 mm
D: 2016 mm
D: 2030 mm
D: 189 mm   (hand ahead the device - moving a little bit)
D: 176 mm
D: 153 mm
D: 157 mm
D: 154 mm
D: 152 mm
D: 155 mm
D: 149 mm
D: 168 mm
D: 167 mm
D: 171 mm
D: 144 mm
D: 150 mm
D: 156 mm
D: 152 mm
D: 149 mm
D: 150 mm
D: 158 mm
D: 168 mm
D: 164 mm
D: 169 mm
D: 164 mm
D: 150 mm
D: 145 mm
D: 137 mm
D: 173 mm
D: 141 mm
D: 128 mm
D: 129 mm
D: 121 mm
D: 121 mm
D: 118 mm
D: 114 mm
D: 110 mm
D: 110 mm
D: 105 mm
D: 105 mm
D: 101 mm
D: 93 mm
D: 77 mm
D: 70 mm
D: 73 mm
D: 71 mm
D: 76 mm
D: 69 mm
D: 80 mm
D: 83 mm
D: 92 mm
D: 96 mm
D: 100 mm
D: 108 mm
D: 175 mm
D: 163 mm
D: 153 mm
D: 137 mm
D: 152 mm
D: 140 mm
D: 126 mm
D: 128 mm
D: 134 mm
D: 140 mm
D: 141 mm
D: 145 mm
D: 137 mm
D: 139 mm
D: 143 mm
D: 2021 mm (hand exit - returning to measuring something else)
D: 2030 mm
D: 2021 mm
D: 2020 mm
...


-- 
You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub:
https://github.com/RIOT-OS/RIOT/issues/13079#issuecomment-731810806
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.riot-os.org/pipermail/notifications/attachments/20201122/5e5357c8/attachment-0001.htm>


More information about the notifications mailing list