I got the SRF-01 ultrasonic sensor a while ago, as it comes with a grommet, easy-to-use JST connector, and can sense from 0-600cm (many ultrasonic sensors can’t sense the first 15-20cm).
I made use of the Arduino library here, and used the ParticleSoftSerial library to replace Arduino’s SoftwareSerial. However, I’m unsure how to proceed from here. The ParticleSoftSerial library states that it can be used on two digital GPIOs. However, the SRF-01 communicates through a single pin.
Is the ParticleSoftSerial library unsuited for this? Is there any other way I can make this sensor work on an Electron?
I actually had written that library to support half-duplex communication (also for an ultra sonic sensor) since the HW implementation on the Particel devices had some issues with half-duplex.
So pretty sure the current version does still support it. I’d have to see how, but one thing I’d imagine is that providing the same pin as RX and TX should do the trick.
So right now I have the following code. I wired the TX/RX pin of the SRF-01 to D1.
I’m not really sure what your equivalent for SoftwareSerial.listen() is though (line 27); if I leave it out and run the code, I’m not receiving any serial messages.
But I see there library I used for that had some extra method to send the break signal required for the sensor which isn’t in the contributed version.
I’ll see where I got that version, but not today
Update:
I just went back and looked at previous versions of the lib in Web IDE and for some reason I removed several features from the lib that were still in 0.0.3.
Have a try with this one https://go.particle.io/shared_apps/5ab1783e8665ba507b0019e4
I'll have to have a test for myself. I do remember that I got correct readings.
You could try changing this line
//SoftSer.sendBreak(); // this uses the default break of 5 bit length
SoftSer.sendBreak(12); // found one source that mentions 12 bit length instead
But about that
AFAIK single transducers won't be able to sense the first few centimeters reliably due to the latency in switching from transmitter to receiver mode and the physical ringing of the housing after a transmission cycle.
That’s what I figured as well, however on the official datasheet it states that it has an Advanced Mode, where after acquiring 5 measurements beyond 30cm, it will be able to to sense objects as close as just a few centimeters. The process of acquiring 30+ measurements needs to be repeated every now and then however.
I think the regression happened when I migrated the library to the new library structure but must have taken an old version for the migration
But since I’ll have to update the library for the upcoming mesh devices and 0.8.0 will bring some faster interrupts to accomodate for higher baudrates, I’ll probably not push an updated version till then.