The operating current is 8mA for the Grove Ultrasonic Sensor…
The BBB, per pin, can supply about 4mA. Is one to believe that this sensor will no work for three pins on the BBB, e.g. 3.3v, GND, GPIO (being the 4mA reference here)?
I was just going to attach things and see what happens but…
I am trying to make sure I do no break things.
This is not a HC-SR04.
I have more sensors but the BBB in question should live on!
#!/usr/bin/python3
#import os
#from pathlib import Path
from time import sleep
ms = 250
pin = '0'
IIOPATH = '/sys/bus/iio/devices/iio:device0/in_voltage' + pin + '_raw'
print('Ctrl-C to stop ')
f = open(IIOPATH, 'r')
try:
while True:
f.seek(0)
data = f.read()[:-1] # What does the [:-1] do in this line?
print('data = ' + data)
sleep(ms / 1000)
except KeyboardInterrupt:
f.close()
I am not sure but I found this source on the docs. pages. The ADC pin is listed as P9_39. I have a resistor attached to P9_39.
I am receiving values in the one digit format so far. Anyway, a bit lost but trying here!
Update
I figured out what slicing is currently for taking out the last line for data = f.read()[:-1] # What does the [:-1] do in this line?
But…what is it slicing? ()? Is it slicing () which is empty? Does this go back to the first section of somewhere…see lost a bit.
Have you considered C. It is the best way to go if you are using GPIO. Nothing wrong with python and in certain applications it is much better than C. However, when you need to communicate with the real world C is the best option. Besides, you can hit everything yourself and don’t depend on others to create a library. You can include C in your python code, however that requires C coding so you still need to know C.
I have read many of your posts and what you are trying to do will be more fruitful if you switched over to C. Just plain old C and gcc not C# or C++.
Okay. Whelp, C it is. I am a very entry level programmer w/ years of experience but w/out making things from scratch, I have little experience making things. Redundant chat here…
Thank you…I will try w/ C and/or Python3 time permitting.
Seth
P.S. I am going to review the docs. again to look over ideas and see if I can configure something from the docs.beagleboard.org instructions.
gomer disagrees. NO language running on linux is capable of the microsecond timing needed to get accurate readings from these devices… The only BBB solution is to use the PRU. See Derek Molloy excellent example in his ‘Exploring BeagleBone’ book.
If your sensor is not a HC-SR04, it sure looks like one, and seems to act like one. check the output closely from the link that you provided:
ansonhe@Ansons-Macbook-Pro ~:aip shell -n -c “runfile /Users/ansonhe/Desktop/ArduPy-ultrasonic.py”
Positional argument (/dev/cu.usbmodem1413101) takes precedence over --open.
Connected to ardupy
The distance to obstacles in front is: 3 centimeter
The distance to obstacles in front is: 1 inches
The distance to obstacles in front is: 7 centimeter
The distance to obstacles in front is: 2 inches
The distance to obstacles in front is: 6 centimeter
The distance to obstacles in front is: 2 inches
The distance to obstacles in front is: 6 centimeter
The distance to obstacles in front is: 2 inches
the first reading should be all you need to know. 3 centimeters is well over 2 inches yet it is reporting it as 1 (one) inch… ouch
then the next two readings report that 2 inches is BOTH equivalent to 6 AND 7 centimeters … OUCH!
it is all a matter of how accurate a measurement you need.
If it helps, try to flesh it out using blocks. Break the blocks apart and write a function for that block.
Secret to winning is do small steps, first function works, then move on to the second.
Also,
Learn to do this
//my comments go here
Six months later all you will do is stare at the monitor…
So, bi-directional GPIO is not used here. Okay. I see you say it is a timing issue. No worries. I will try another route.
I have an oscilloscope, i.e. Rigol (cheap version). It is a DS1102E. Anyway, I have a couple of these Seeed Studio versions and wanted to use them. Are you saying I should use HC-SR04 instead for the sensors?
Seth
P.S. It may take time on my part to retrieve the HC-SR04s. So, even though I may no reply w/ the current needed hardware, I can reply w/ other ideas in the meantime.
That is a FINE scope, more than adequate. With the two channels, you can see both the triggering and the echo.
I don’t have any experience with these, but from the link that you provided earlier, they use one pin for BOTH triggering and echo… It is just an additional complication that someone ELSE might be able to help you with. I’ve done multiple projects with the hc-sr04, and they only cost a few dollars. Just a suggestion.
Using the scope, you’ll see the raw data of what your MCU (BBB) will eventually see. This makes it less likely that you will blame the (cheap) sensor for what is an issue with the MCU (given that many try to use this sensor with linux… will never work accurately as I’ve already brayed.)