BrickPi Ultrasonic sensor

Hi!
I recently bought a lego mindstorms ultrasonic sensor.
I have been running the LEGO-UltraSonic_sensor_Test.py from the Sensor Examples and all I get is -1 continuously.
I have been googling around (If thats a thing) for 3-4 days and can’t find anything to make the ultrasonic sensor activate code when it detects motion in python.
If you can help it would be extremely appreciated as i am sick and tired of looking through 7-8 pages of google results.
Thanks in advance,
H1pp0s

That’s a lot of days to google. Sorry for your loss of time.

Can you post a picture of the exact sensor you’re trying to hook up? Take a picture with your phone?

Hi John!
Thanks for replying.
Its a lego windstorms
Here you go.
Thanks in advance,
H1pp0s

Looks like you’re using an EV3 sensor, with the older NXT code.

Try running the “EV3-Ultrasonic . . . .py” code.

I tried the EV3-Ultrasonic.py and waved my hand in front of the sensor and nothing…
I’m pretty sure i put it in sensor port 4?
But when i run lego ultrasonic it the sensor flashes red every few seconds or so…
Thanks,
H1pp0s

Ok, now that we have the correct sensor and correct software; have you tried running any other sensors just to make sure the BrickPi is communicating with the Raspberry Pi?

I don’t have any other sensors but i tried one of my motors and its working with the motor timeout test.
Is the sensor working or should i send it back and get my money back?
Thanks,
H1pp0s

Great, so it seems the BrickPi is running correctly then.

Two more questions:
1). Are you able to run the EV3 Firmware test to make sure that the BrickPi is running the latest firmware? If this is the only EV3 sensor you have, can you attach a picture of your BrickPi? Is it a BrickPi+?
2). Are you sure you have the sensor on the right port?

Hi,

I am in a similar situation. Using BrickPi/Scratch/EV3 and my ultrasonic sensor keeps saying -1.

John said H1pp0s was using EV3 sensors with NXT code. Could the same thing be happening to me but in Scratch?

I’m using the DI example codes.

Thanks

Hi aewang, can you post a screenshot of the code you’re using with the EV3 sensor?

Hi John, I have similar issue with NXT Ultrasonic sensor running DI sample code in Scratch.
Sensor always reads value of 0.
I tried connecting to a different port. But the sensor drop down doesn’t refresh? That is my second question.
How do you make the new ports with sensors to show up in the drop down?
Thanks.

Hello,
Can I please get a response for my queries from Dexter or someone who has made it work with Scratch?
Thanks.

Temecula,
First, just want to make sure you’re running Raspbian for Robots. Can you tell me which version you’re running?

Have you had any success with Motor examples or have you tried any other examples? In Scratch or another language?

Also, is it possible to first test with the python Ultrasonic Example. Here’s a link: https://github.com/DexterInd/BrickPi_Python/blob/master/Sensor_Examples/LEGO-UltraSonic_sensor_Test.py
For this, you will connect the sensor to Port 1.

You should be able to run the Python Script, if you’re using Raspbian for Robots, with the following commands:


cd ~/Desktop/BrickPi_Python/Sensor_Examples/
sudo python LEGO-UltraSonic_sensor_Test.py

Can you give this a shot, let us know how it goes?

Hi John,
I am running v6.9 updated on 2016.05.09
The python code worked fine. I got the correct return values from Ultrasonic sensor.
But Scratch is giving only 0.
I seem to have the same issue with Color sensor yesterday. Python code worked fine but not Scratch.
Thanks

Temecula, that’s good to hear the python code works ok. Sorry about the Scratch, let’s see what we can do there. Are any errors popping up in the background when you run Scratch? Can you post a screenshot of the program you’re running in Scratch?

Please see the first screenshot for Ultrasonic.
Second for color sensor. The sensor does not even light up.

For both, I am running DI sensor examples.
Thanks.

The picture “color.jpg” seems to be working. It looks like Scratch and the BrickPi have connected.

I just tried out “Ultrasonic Sensor test.sb” with the NXT Ultrasonic sensor attached to the BrickPi on Port 3; I couldn’t not get the same response you did.

It looks like you’re using an older card that’s Wheezy, not Jessie. Do you have another sd card you could try putting our latest Jessie Raspbian for Robots on? When was the last time you ran an update?

You can find the latest version of Raspbian for Robots here, I was just successfully running it on the June 26th version, and had no issues.

Hi John,
I have another SD card and I ran with June 26th version of Jessie.
Even the motors did not respond in Scratch.
It is frustrating to see sensors not working with Scratch because my target audience is kids in CoderDojo who are learning Scratch.
Thanks.

Hey @temecula-us, I’m sorry about the frustration. Scratch should be working, I’m racking my brain though about what else might be giving trouble. Are you getting any error messages in the terminal screen that runs?