Go to Post In the end any amount of time can work, just be smart about how you use it. - Jay O'Donnell [more]
Home
Go Back   Chief Delphi > Technical > Control System > Sensors
CD-Media   CD-Spy  
portal register members calendar search Today's Posts Mark Forums Read FAQ rules

 
Reply
 
Thread Tools Rate Thread Display Modes
  #1   Spotlight this post!  
Unread 27-01-2017, 08:29
Stappy Stappy is offline
Registered User
FRC #5084
 
Join Date: Mar 2014
Location: Corunna
Posts: 27
Stappy is an unknown quantity at this point
HC-SR04 Ultrasonic Distance Sensor wiring and programming

Ok, so here it goes. Stupid question time.

I am trying to find information about utilizing the HC-SR04 ultrasonic distance sensor in a FIRST Robotics FRC situation with the RoboRIO.
Last year our seasoned programmer could not figure out how to use it and wound up giving up. He has since graduated and moved on to college and a computer science future. That was using C++. He told me that the four wire configuration was not compatible with RoboRIO and would have to use an arduino to translate.

This year I have a transfer team member that is up on programming in Java and I once again asked about the HC-SR04 and was told "Oh that is an arduino only sensor". And yet I see articles regarding the "Venerable HC-SR04" sensor but found nothing on how to wire it or program for it.

The sensor seems pretty standard,
VCC: +5VDC
Trig : Trigger (INPUT)
Echo: Echo (OUTPUT)
GND: GND

What is it about this sensor that keeps it from being used with a RoboRIO?
__________________
FridgeBot Inc
Providing robotic appliances since 2014!
Reply With Quote
  #2   Spotlight this post!  
Unread 27-01-2017, 10:31
rich2202 rich2202 is offline
Registered User
FRC #2202 (BEAST Robotics)
Team Role: Mentor
 
Join Date: Jan 2012
Rookie Year: 2012
Location: Wisconsin
Posts: 1,275
rich2202 has a reputation beyond reputerich2202 has a reputation beyond reputerich2202 has a reputation beyond reputerich2202 has a reputation beyond reputerich2202 has a reputation beyond reputerich2202 has a reputation beyond reputerich2202 has a reputation beyond reputerich2202 has a reputation beyond reputerich2202 has a reputation beyond reputerich2202 has a reputation beyond reputerich2202 has a reputation beyond repute
Re: HC-SR04 Ultrasonic Distance Sensor wiring and programming

Seems like you would:

VCC: +5VDC
Trig : Trigger (INPUT) - DIO<mm>
Echo: Echo (OUTPUT) - DIO<nn>
GND: GND

To use the sensor you would:
1) Reset a Timer to 0
2) Set DIO<mm> to high
3) wait 10us
4) Set DIO<mm> to low
5) See if DIO<nn> is High
6) If high, read Timer, otherwise back to 5 (abort after 1 second)
7) Distance is per the formula

Alternative to 5-7 (which also serves as a double check), see how long DIO<nn> is held high.
__________________

Reply With Quote
  #3   Spotlight this post!  
Unread 27-01-2017, 10:56
Mark McLeod's Avatar
Mark McLeod Mark McLeod is offline
Just Itinerant
AKA: Hey dad...Father...MARK
FRC #0358 (Robotic Eagles)
Team Role: Engineer
 
Join Date: Mar 2003
Rookie Year: 2002
Location: Hauppauge, Long Island, NY
Posts: 8,906
Mark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond repute
Re: HC-SR04 Ultrasonic Distance Sensor wiring and programming

LabVIEW has an example of how to use this sensor. It comes in the FRC Update package if you install LabVIEW.
You could use that as a guide and port the example to Java.
Attached Thumbnails
Click image for larger version

Name:	SRF04 Example.jpg
Views:	21
Size:	77.8 KB
ID:	21630  
__________________
"Rationality is our distinguishing characteristic - it's what sets us apart from the beasts." - Aristotle
Reply With Quote
  #4   Spotlight this post!  
Unread 27-01-2017, 13:51
Stappy Stappy is offline
Registered User
FRC #5084
 
Join Date: Mar 2014
Location: Corunna
Posts: 27
Stappy is an unknown quantity at this point
Re: HC-SR04 Ultrasonic Distance Sensor wiring and programming

So the SRF04 and the HC-SR04 are the same sensor?
__________________
FridgeBot Inc
Providing robotic appliances since 2014!
Reply With Quote
  #5   Spotlight this post!  
Unread 27-01-2017, 14:16
Stappy Stappy is offline
Registered User
FRC #5084
 
Join Date: Mar 2014
Location: Corunna
Posts: 27
Stappy is an unknown quantity at this point
Re: HC-SR04 Ultrasonic Distance Sensor wiring and programming

NI RoboRio Manual states:
DIO, PWM, and Relay Lines
The NI roboRIO provides the following DIO lines:
• 3.3 V general-purpose DIO lines on the MXP
• 3.3 V digital lines on the DIO, I2C, and SPI ports
• 5 V digital lines on the PWM and Relay ports.

HC-SR04 Specs State:
VCC = +5VDC
Trig = Trigger input of Sensor
Echo = Echo output of Sensor
GND = GND


Is the variation between 3.3v (roboRIO output) and 5v (sensor requirement) where the problem may lay?



Parameter Min Typ. Max Unit Operating Voltage
4.50 5.0 5.5 V
__________________
FridgeBot Inc
Providing robotic appliances since 2014!
Reply With Quote
  #6   Spotlight this post!  
Unread 27-01-2017, 16:10
rich2202 rich2202 is offline
Registered User
FRC #2202 (BEAST Robotics)
Team Role: Mentor
 
Join Date: Jan 2012
Rookie Year: 2012
Location: Wisconsin
Posts: 1,275
rich2202 has a reputation beyond reputerich2202 has a reputation beyond reputerich2202 has a reputation beyond reputerich2202 has a reputation beyond reputerich2202 has a reputation beyond reputerich2202 has a reputation beyond reputerich2202 has a reputation beyond reputerich2202 has a reputation beyond reputerich2202 has a reputation beyond reputerich2202 has a reputation beyond reputerich2202 has a reputation beyond repute
Re: HC-SR04 Ultrasonic Distance Sensor wiring and programming

If you need 5v, the AIO ports are 5 volts. Use 1v and 4v as the threshold, with 1-4 undefined.
__________________

Reply With Quote
Reply


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump


All times are GMT -5. The time now is 10:42.

The Chief Delphi Forums are sponsored by Innovation First International, Inc.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi