[Microbit-Python] Help - ultrasound hcsr04 sensor

Jim Mussared jim at groklearning.com
Sat Jul 22 11:00:41 EDT 2017


Hi Tim,

Here's a tested and somewhat calibrated code sample that works with
the current Mu / uFlash firmware.
https://gist.github.com/jimmo/14c6194578f721477c5c88e5dbbcfcef

Some things to be aware of:
 - This won't work on a bit:bot (can't use pin15)
 - This requires that ECHO and TRIG are separate pins.
 - You need to supply the HC-SR04 with 5V Vcc -- you can't power it
from the micro:bit.
 - To make the echo output 3.3V safe to connect to the micro:bit, you
need to use a level shifter (or a simple voltage divider, e.g.
18k/10kOhm -- "ECHO ---10k--- pin1 ---18k--- GND")

The bit:bot does those last two things for you of course.

Jim


On 22 July 2017 at 22:34, T Gamble
<tgamble941 at dalriada.ballymoney.ni.sch.uk> wrote:
> @Jim Mussared
>
>
>
> Yes Jim, I'm happy to use whatever means to get the HCSR04 sensor working. I
> will download uFlash now and see if that makes any difference.
>
>
>
> In the code I submitted, what edits do I need to make?
>
>
>
> thanks
>
>
>
> tim
>
> ________________________________
>
> From: Microbit [microbit-bounces+tgamble941=c2kni.net at python.org] on behalf
> of David Whale [david at thinkingbinaries.com]
> Sent: 21 July 2017 10:29
> To: For Pythonic MicroBit related discussions
> Subject: Re: [Microbit-Python] Help - ultrasound hcsr04 sensor
>
> There is an issue where if you turn the bitbot on or reset it while it is on
> a surface, both the line sensors are wired to the buttons.
>
> The workflow is that if you hold both buttons while powering up or reset,
> this initiates bluetooth pairing mode.
>
> 4tronix Gareth is aware of this.
>
> Best thing is hold it in the air when you power it on.
>
>
> ___________________________________________________________
> David Whale, B.Sc (Hons), MIET
> Software Engineer and IET Schools Liaison Officer, Essex
>
>
> On 21 July 2017 at 05:15, Jim Mussared via Microbit <microbit at python.org>
> wrote:
>>
>> The bit:bot is totally amazing - we just got one for the office here. :D
>>
>> I actually got the ultrasonic sensor working earlier this week (using
>> a similar approach to the temp/humidity sensor in the previous thread,
>> and also similar to the code you linked to), but it required changes
>> to the micropython firmware. I'm happy to share a hex file that works
>> if you're happy to use uFlash (or manually patch the uflash.py in Mu).
>>
>> FYI, If you're using the latest firmware in Mu / uFlash, you might
>> also notice crashes when controlling the robot and using the radio at
>> the same time. This is actually fixed, but there hasn't been a
>> firmware release since then. However I noticed that the latest
>> firmware breaks support for NeoPixels -- I have a fix for this too but
>> I don't understand why it broke. It's on my list for this weekend to
>> investigate and raise some bugs / send some PRs to the micro:bit
>> micropython repo.
>>
>> On 21 July 2017 at 13:17, Nicholas H.Tollervey <ntoll at ntoll.org> wrote:
>> > I believe this is a known problem and will be fixed in the next release
>> > (in the not-too-distant-future).
>> >
>> > N.
>> >
>> > On 21/07/17 00:00, T Gamble wrote:
>> >> Hi,
>> >>
>> >> The MicroPython solution posted here on
>> >> GitHub https://github.com/fizban99/microbit_hcsr04 will not enable me
>> >> to
>> >> use the Mirco:Bit and Bit:Bot (seeBit:Bot
>> >> <http://4tronix.co.uk/blog/?p=1490>) and HC-SR04 ultra sound sensor.
>> >> The
>> >> bit:bot provides pin15 for accessory connections, whereas the posted
>> >> solution uses multiple pins. (I am restricted to pin15 on my bit:bot)
>> >>
>> >> I've tried this on Microsoft MakeCode (block editor) and it works ok -
>> >> setting ping trig and echo both to pin 15, from sonar block
>> >> package/module.
>> >>
>> >> I've been troubleshooting thus for hours on end & all I get on the
>> >> MicroBit's LED matrix is the value '  -11 ' or 'Pairing Mode' weirdly!
>> >>
>> >> Please help. Thanks.
>> >>
>> >> Tim
>> >>
>> >>
>> >> The opinions expressed are those of the individual and not the school.
>> >> Internet communications are not secure and therefore the school does
>> >> not accept legal responsibility for the content of this message. If the
>> >> reader of this message is not the intended recipient, or the user
>> >> responsible for delivering this communication to the intended
>> >> recipient,
>> >> you are hereby notified that any disclosure, distribution or copying of
>> >> this communication is strictly prohibited.
>> >>
>> >>
>> >>
>> >> _______________________________________________
>> >> Microbit mailing list
>> >> Microbit at python.org
>> >> https://mail.python.org/mailman/listinfo/microbit
>> >>
>> >
>> >
>> > _______________________________________________
>> > Microbit mailing list
>> > Microbit at python.org
>> > https://mail.python.org/mailman/listinfo/microbit
>> >
>> _______________________________________________
>> Microbit mailing list
>> Microbit at python.org
>> https://mail.python.org/mailman/listinfo/microbit
>
>
>
> _______________________________________________
> Microbit mailing list
> Microbit at python.org
> https://mail.python.org/mailman/listinfo/microbit
>


More information about the Microbit mailing list