AJ-SR04M Returning 9999 while using the AJ-SR04M Component

Use this section to discuss your embedded Flowcode projects.
Post Reply
Matrixv8
Posts: 22
http://meble-kuchenne.info.pl
Joined: Mon Jun 03, 2024 2:51 am
Been thanked: 4 times

AJ-SR04M Returning 9999 while using the AJ-SR04M Component

Post by Matrixv8 »

Hi anyone, can someone help me figuring out why I am getting the same value, 9999, when I use the AJ-SR04M in Flowcode V10. The HC-SR04 component works just fine. I have change the timers and prescaler but still the same value. I have tried other new units, but still the same. Can someone help please?

Regards,

Pierre

chipfryer27
Valued Contributor
Posts: 1953
Joined: Thu Dec 03, 2020 10:57 am
Has thanked: 425 times
Been thanked: 647 times

Re: AJ-SR04M Returning 9999 while using the AJ-SR04M Component

Post by chipfryer27 »

Hi

That board appears to be able to communicate using different protocols, however without your chart we have no idea how you have setup. If you post your chart it would help, and also detail connections.

Regards

mnfisher
Valued Contributor
Posts: 1876
Joined: Wed Dec 09, 2020 9:37 pm
Has thanked: 154 times
Been thanked: 886 times

Re: AJ-SR04M Returning 9999 while using the AJ-SR04M Component

Post by mnfisher »

The protocol does depend on the value of the link R19 - so check that?

I just got one of these in a AliExpress assortment - so will have a play....

Martin

mnfisher
Valued Contributor
Posts: 1876
Joined: Wed Dec 09, 2020 9:37 pm
Has thanked: 154 times
Been thanked: 886 times

Re: AJ-SR04M Returning 9999 while using the AJ-SR04M Component

Post by mnfisher »

Wired up the sensor to an Arduino - and got 9999 (error). R19 open (mode 1 HCSR04 compatible)

I added a connection to a logic analyser - and the output from the sensor looks good - there is a 'trigger' pulse - followed by an output pulse of variable length (depending on distance)

However - the output pulse occurs ~12ms after the trigger pulse and this is longer than then 10000us (10ms) allowed by the component before deciding it is an error. Looks like the sensor is a bit slower!

Therefore - the component always treats the result as an error (and never attempts to read the output pulse time)


Msrtin

chipfryer27
Valued Contributor
Posts: 1953
Joined: Thu Dec 03, 2020 10:57 am
Has thanked: 425 times
Been thanked: 647 times

Re: AJ-SR04M Returning 9999 while using the AJ-SR04M Component

Post by chipfryer27 »

Hi

I believe medelec35 did some posts on the HC-SR04 regarding timing, so it may be worth doing a quick search for them.

Regards

mnfisher
Valued Contributor
Posts: 1876
Joined: Wed Dec 09, 2020 9:37 pm
Has thanked: 154 times
Been thanked: 886 times

Re: AJ-SR04M Returning 9999 while using the AJ-SR04M Component

Post by mnfisher »

The component 'attempts' to add an extra delay - delay 'type' but this is just 20us - the delay before the output pulse (on the board I have anyway) is 12.4ms

So it always 'time outs' the response.

mnfisher
Valued Contributor
Posts: 1876
Joined: Wed Dec 09, 2020 9:37 pm
Has thanked: 154 times
Been thanked: 886 times

Re: AJ-SR04M Returning 9999 while using the AJ-SR04M Component

Post by mnfisher »

I wrote a very simple program - that sends a trigger and then waits for a return pulse. It measures this using a loop with a 58us delay - and the results look reasonable.

Note that the sensor has a minimum range of ~20cm and results go awry below this. The code here also has no time out - so if a reply never comes it will never display a distance...

Martin
Attachments
ultrasonic.fcfx
(11.8 KiB) Downloaded 28 times

Matrixv8
Posts: 22
Joined: Mon Jun 03, 2024 2:51 am
Been thanked: 4 times

Re: AJ-SR04M Returning 9999 while using the AJ-SR04M Component

Post by Matrixv8 »

As usual a great thanks to your Martin and the others for your replies and work. I knew this was the problem but I was not going to change to component internal code. So the best is to look for another sensor or use a variation with a resistor on R19. I was aware of the R19 function but hopping I could avoid it. My program was already completed for the environment station I have built but the moisture was a problem with the HC-SR04

Again a great thank you for your replies and work.

Regards,
Pierre

mnfisher
Valued Contributor
Posts: 1876
Joined: Wed Dec 09, 2020 9:37 pm
Has thanked: 154 times
Been thanked: 886 times

Re: AJ-SR04M Returning 9999 while using the AJ-SR04M Component

Post by mnfisher »

The component only seems to work with the compatibility mode.
The other modes are interesting too though - I'll try and add something to the board so I can easily switch the connection at r19 and play some more....

Martin

Post Reply