We use some essential cookies to make our website work.

We use optional cookies, as detailed in our cookie policy, to remember your settings and understand how you use our website.

nolczak
Posts: 7
Joined: Sun Oct 04, 2020 12:30 pm

How to get CamJam EduKit3 Distance Sensor Working?

Sun Oct 04, 2020 1:00 pm

Hi, I wondered if anybody might be able to help me with getting the distance sensor in the CamJam EduKit3 working with my Rpi 4.

I'm pretty sure I've got everything wired up properly (see images below), and have re-wired it a number of times, as well as switching the resistors for the spare ones, but it still doesn't seem to work :(

Running the code provided with the CamJam Worksheets '5-distance.py', I always just get:

Code: Select all

DistanceSensorNoEcho: no echo received
warnings.warn(DistanceSensorNoEcho('no echo received'))
Any suggestions or solutions would be really appreciated!
IMG_9619.JPG
IMG_9619.JPG (39.4 KiB) Viewed 2728 times
IMG_9618.JPG
IMG_9618.JPG (37.37 KiB) Viewed 2728 times

User avatar
B.Goode
Posts: 18715
Joined: Mon Sep 01, 2014 4:03 pm
Location: UK

Re: How to get CamJam EduKit3 Distance Sensor Working?

Sun Oct 04, 2020 3:24 pm

Welcome to the Raspberry Pi forums.

nolczak wrote:
Sun Oct 04, 2020 1:00 pm
Hi, I wondered if anybody might be able to help me with getting the distance sensor in the CamJam EduKit3 working with my Rpi 4.

I'm pretty sure I've got everything wired up properly (see images below), and have re-wired it a number of times, as well as switching the resistors for the spare ones, but it still doesn't seem to work :(

Running the code provided with the CamJam Worksheets '5-distance.py', I always just get:

Code: Select all

DistanceSensorNoEcho: no echo received
warnings.warn(DistanceSensorNoEcho('no echo received'))
Any suggestions or solutions would be really appreciated!

IMG_9619.JPG

IMG_9618.JPG


I can't see enough detail in your images to know anything about the wiring.

Is the sensor in a position where you would expect it to 'hear' an echo when you test it?


Edit: to add that I have one of those kits and have wired and tested the Distance Sensor a number of times. There is nothing inherently wrong with the design or the code.
Beware of the Leopard

nolczak
Posts: 7
Joined: Sun Oct 04, 2020 12:30 pm

Re: How to get CamJam EduKit3 Distance Sensor Working?

Tue Oct 06, 2020 5:18 pm

Thanks for your reply. I just tried again, and still no luck... I must have checked the wiring about a hundred times now.

I assume the sensor is supposed to be with the 'eyes' pointing towards a wall to get an echo? - I tried moving it around a bit, but that also didn't help. Would really appreciate any other suggestions!

User avatar
B.Goode
Posts: 18715
Joined: Mon Sep 01, 2014 4:03 pm
Location: UK

Re: How to get CamJam EduKit3 Distance Sensor Working?

Tue Oct 06, 2020 5:34 pm

nolczak wrote:
Tue Oct 06, 2020 5:18 pm
Thanks for your reply. I just tried again, and still no luck... I must have checked the wiring about a hundred times now.

I assume the sensor is supposed to be with the 'eyes' pointing towards a wall to get an echo? - I tried moving it around a bit, but that also didn't help. Would really appreciate any other suggestions!

The 'tubes' need to be pointing to an acoustically reflective surface. I would start by testing something up close (50-100mm) initially, and work outwards from there.
Beware of the Leopard

User avatar
scruss
Posts: 6537
Joined: Sat Jun 09, 2012 12:25 pm
Location: Toronto, ON

Re: How to get CamJam EduKit3 Distance Sensor Working?

Tue Oct 06, 2020 6:38 pm

Which code from the Edukit 3 repo are you running? Both of them use the following pins:

Code: Select all

pinTrigger = 17
pinEcho = 18
These are BCM numbers, so consulting pinout.xyz those are physical pin numbers 11 and 12, but the Edukit controller board should sort that out. You've wired everything as per page 3 of the Robotics Worksheet 6?
‘Remember the Golden Rule of Selling: “Do not resort to violence.”’ — McGlashan.
Pronouns: he/him

nolczak
Posts: 7
Joined: Sun Oct 04, 2020 12:30 pm

Re: How to get CamJam EduKit3 Distance Sensor Working?

Tue Oct 06, 2020 8:24 pm

Thanks for your help. I am using the first code. I keep checking and I'm pretty sure I have it wired correctly. But the resistor wires are not pushed so much into the breadboard - does that matter? I also wondered if it might be a problem with the (slightly cheap...) batteries I am using to power the motors etc... could it be they're not delivering enough power?

User avatar
B.Goode
Posts: 18715
Joined: Mon Sep 01, 2014 4:03 pm
Location: UK

Re: How to get CamJam EduKit3 Distance Sensor Working?

Tue Oct 06, 2020 10:22 pm

nolczak wrote:
Tue Oct 06, 2020 8:24 pm
Thanks for your help. I am using the first code. I keep checking and I'm pretty sure I have it wired correctly. But the resistor wires are not pushed so much into the breadboard - does that matter? I also wondered if it might be a problem with the (slightly cheap...) batteries I am using to power the motors etc... could it be they're not delivering enough power?

Yes, it definitely matters that all connections must be electrically secure.


What does your question about motors have to do with getting the Distance Sensor working?


@scruss has pointed out that the Distance Sensor worksheet is numbered as #6. You reference it as #5 - why?
Beware of the Leopard

nolczak
Posts: 7
Joined: Sun Oct 04, 2020 12:30 pm

Re: How to get CamJam EduKit3 Distance Sensor Working?

Wed Oct 07, 2020 6:44 am

The battery pack that comes with the kit goes into the 'hat' that is placed on the pins, then out to the motors. So I assumed that this hat is taking its power from those batteries too. I though that if the hat was sending power to the Ultrasonic sensor (instead of the motors) then maybe if the batteries are duff and it is not sending enough power, then there wouldn't be an echo to detect?

The motors and the line detector sensor both work.

Sorry, I think I was confused regarding the worksheet number by the fact that the code is called '5-distance.py' - I assumed this name was linked to the worksheet number.

User avatar
recantha2
Posts: 412
Joined: Wed Nov 14, 2012 9:34 am
Location: Potton, Bedfordshire

Re: How to get CamJam EduKit3 Distance Sensor Working?

Wed Oct 07, 2020 10:01 am

Hi.
Mike here from CamJam.
The battery pack is for the motors. Everything else is powered from the Pi itself.
One thing to check: Are you using an up-to-date version of the operating system (and therefore GPIO Zero)? There was a bug with GPIO Zero's distance sensor implementation at one point.
--
Michael Horne - @recantha on Xitter, Bluesky, Mastodon
Raspberry Pi Pod blog - http://www.recantha.co.uk/blog
Cambridge Raspberry Jam - https://camjam.me
Pi Wars - https://piwars.org

nolczak
Posts: 7
Joined: Sun Oct 04, 2020 12:30 pm

Re: How to get CamJam EduKit3 Distance Sensor Working?

Wed Oct 07, 2020 12:14 pm

Hi Mike,

Thanks for your reply!

I didn't realise you were one of the people behind 'CamJam'. I also emailed you recently about the driving direction of your 'remote' code (forwards and backwards seeming to be swapped), but I thought for this question I'd was pick the collective brains of the forum.

I just bought the Rpi 4 a month ago, so the Raspbian OS should be the latest version. I don't know how up to date all of the Python modules are. I will try to manually update the 'gpiozero' module this evening and see if that helps with getting the sensor to work.

nolczak
Posts: 7
Joined: Sun Oct 04, 2020 12:30 pm

Re: How to get CamJam EduKit3 Distance Sensor Working?

Thu Oct 08, 2020 7:13 am

UPDATE: I know this is maybe something that it is not wise to do, but I noticed by accident that I do get a different result when the 'ground' cable is unplugged from the hat. Then the terminal shows a stream like this:

Code: Select all

 Distance: 0.0 cmDistance: 0.0 cmDistance: 0.0 cmDistance: 0.0 cmDistance: 0.0 cmDistance: 0.0 cmDistance: 0.0 cmDistance: 0.0 cmDistance: 0.0 cmDistance: 0.0 cmDistance: 0.0 cmDistance: 0.0 cmDistance: 0.0 cmDistance: 0.0 cmDistance: 0.0 cmDistance: 0.0 cmDistance: 0.0 cmDistance: 0.0 cmDistance: 0.0 cmDistance: 0.0 cmDistance: 0.0 cmDistance: 0.0 cmDistance: 0.0 cmDistance: 0.0 cmDistance: 0.0 cm 
Still not picking up the distance, but maybe better than 'no echo' ?

User avatar
B.Goode
Posts: 18715
Joined: Mon Sep 01, 2014 4:03 pm
Location: UK

Re: How to get CamJam EduKit3 Distance Sensor Working?

Thu Oct 08, 2020 7:54 am

nolczak wrote:
Thu Oct 08, 2020 7:13 am
UPDATE: I know this is maybe something that it is not wise to do, but I noticed by accident that I do get a different result when the 'ground' cable is unplugged from the hat. Then the terminal shows a stream like this:

Code: Select all

 Distance: 0.0 cmDistance: 0.0 cmDistance: 0.0 cmDistance: 0.0 cmDistance: 0.0 cmDistance: 0.0 cmDistance: 0.0 cmDistance: 0.0 cmDistance: 0.0 cmDistance: 0.0 cmDistance: 0.0 cmDistance: 0.0 cmDistance: 0.0 cmDistance: 0.0 cmDistance: 0.0 cmDistance: 0.0 cmDistance: 0.0 cmDistance: 0.0 cmDistance: 0.0 cmDistance: 0.0 cmDistance: 0.0 cmDistance: 0.0 cmDistance: 0.0 cmDistance: 0.0 cmDistance: 0.0 cm 
Still not picking up the distance, but maybe better than 'no echo' ?

I would take that as a pretty clear indication that you have some sort of wiring problem.

One thought - for which I can't find a reference at the moment - is that perhaps not all HC-SR04 ultrasonic modules have the same arrangement of pins. Are you following the wiring exactly pin-to-pin, or are you also considering the functions of the pins as marked on the module? [You need to do the latter.]

[And to head off other people pointing it out - the add-on board for the Edukit3 set is not a HAT.]
Beware of the Leopard

User avatar
neilgl
Posts: 11167
Joined: Sun Jan 26, 2014 8:36 pm
Location: Near The National Museum of Computing

Re: How to get CamJam EduKit3 Distance Sensor Working?

Thu Oct 08, 2020 12:18 pm

Maybe dispense with the “hat” and connect to the appropriate GPIO pins (with resistors for echo pin) directly. Like this

Code: Select all

SR04 Wire   Pi Function
5V   Red    5V
TRIG Green  GPIO20
ECHO Orange GPIO21  (Note we use two resistors on breadboard to get 5v voltage DOWN to 3.3V for pi input)
GND  Black  GND
Test on pi, in terminal start python3, point sensor to nothing close (range is 10.m default) then an object at 15cm
>>> from gpiozero import DistanceSensor
>>> ultrasonic = DistanceSensor(echo=21, trigger=20)
>>> ultrasonic.distance
1.0
>>> ultrasonic.distance
0.1575

User avatar
B.Goode
Posts: 18715
Joined: Mon Sep 01, 2014 4:03 pm
Location: UK

Re: How to get CamJam EduKit3 Distance Sensor Working?

Thu Oct 08, 2020 1:20 pm

Just to express agreement with the suggestion from @neilgl for troubleshooting with the minimum of connections and complications.

And to add that GPIO20 is physical pin #38, and GPIO21 is #40. They are adjacent pins at the end of the header strip that is just behind the Ethernet connector.
Beware of the Leopard

User avatar
neilgl
Posts: 11167
Joined: Sun Jan 26, 2014 8:36 pm
Location: Near The National Museum of Computing

Re: How to get CamJam EduKit3 Distance Sensor Working?

Thu Oct 08, 2020 2:49 pm

Yes, or use (echo = 18, trigger = 17) and connect to GPIO 17 and GPIO 18 see https://pinout.xyz/

nolczak
Posts: 7
Joined: Sun Oct 04, 2020 12:30 pm

Re: How to get CamJam EduKit3 Distance Sensor Working?

Thu Oct 08, 2020 6:47 pm

One thought - for which I can't find a reference at the moment - is that perhaps not all HC-SR04 ultrasonic modules have the same arrangement of pins. Are you following the wiring exactly pin-to-pin, or are you also considering the functions of the pins as marked on the module? [You need to do the latter.]

@B.Goode thanks for your help! My sensor looks like this... which I think is like it should be right?
sensor.JPG
sensor.JPG (32.53 KiB) Viewed 2448 times
Maybe dispense with the “hat” and connect to the appropriate GPIO pins (with resistors for echo pin) directly. Like this

@nielgl thanks for the suggestions and guidance! I will definitely try that. At the moment I am lacking one male-female wire to connect it directly to the pins, but will try to pick one up and give it a go.

User avatar
neilgl
Posts: 11167
Joined: Sun Jan 26, 2014 8:36 pm
Location: Near The National Museum of Computing

Re: How to get CamJam EduKit3 Distance Sensor Working?

Thu Oct 08, 2020 7:42 pm

Yes that picture shows an HC-SR04 the same as mine.

statedlight
Posts: 1
Joined: Sun Jan 10, 2021 10:22 pm

Re: How to get CamJam EduKit3 Distance Sensor Working?

Sun Jan 10, 2021 10:25 pm

Did you find the solution to this issue I am having exactly the same problem? Have rewired it over and over and just keep getting this error:
/usr/lib/python3/dist-packages/gpiozero/input_devices.py:997: DistanceSensorNoEcho: no echo received warnings.warn(DistanceSensorNoEcho('no echo received')).

Return to “Automation, sensing and robotics”