Home
JAQForum Ver 24.01
Log In or Join  
Active Topics
Local Time 11:44 19 Nov 2025 Privacy Policy
Jump to

Notice. New forum software under development. It's going to miss a few functions and look a bit ugly for a while, but I'm working on it full time now as the old forum was too unstable. Couple days, all good. If you notice any issues, please contact me.

Forum Index : Microcontroller and PC projects : Picomite: SR04P Ultrasonic Distance Sensor?

Author Message
lizby
Guru

Joined: 17/05/2016
Location: United States
Posts: 3478
Posted: 05:53pm 20 Jul 2021
Copy link to clipboard 
Print this post

Riddle me this.

I got one of the neat SR04P Ultrasonic Distance Sensor with 7-Segment displays.

The display shows the distance in centimeters--tracking very nicely as I move my hand back and forth. At 9600 baud, it's supposed to transmit distance in the form of D:nnn from a few to about 400cm.

On my Picomite, I entered
SetPin 21,uart0tx:SetPin 22,uart0rx : Open "com0:9600" As #1
do: if loc(#1)>7 then: a$=input$(7,#1): ?a$;: endif: loop

I get either dashes or garbage: "jR[]" (where [] is a solid block).

I connected it to my laptop with a CH341 serial ttl module. In TeraTerm, it displays the distances. I connected it to an F4, and that displays the distances. I made a 3-way splitter and while connected to the Picomite, also connected to the PC with the CH341, and both Teraterm and the Picomite display the distances.

Do I need a pullup or pulldown on the Picomite? Why?

Note: the website documentation says the module is 5V, but the 7-segment display is fine with the Picomite 3v3, and the serial is fine with 3V3 on both the F4 and the CH341. (Some websites say that the newer version (which I probably have) works fine on 3V3.)

~
Edited 2021-07-21 03:55 by lizby
PicoMite, Armmite F4, SensorKits, MMBasic Hardware, Games, etc. on fruitoftheshed
 
phil99

Guru

Joined: 11/02/2018
Location: Australia
Posts: 2831
Posted: 12:55am 21 Jul 2021
Copy link to clipboard 
Print this post

As TTL serial is active low, try a 4k7 to 10k pullup and see what happens. It can't hurt to try.
 
lizby
Guru

Joined: 17/05/2016
Location: United States
Posts: 3478
Posted: 01:33am 21 Jul 2021
Copy link to clipboard 
Print this post

  phil99 said  As TTL serial is active low, try a 4k7 to 10k pullup and see what happens. It can't hurt to try.

10K pullup did the trick. Thanks very much.

Now the question is, why, when the CH341 and F4 didn't need it, and an ESP-01 works perfectly on the same picomite serial port.
PicoMite, Armmite F4, SensorKits, MMBasic Hardware, Games, etc. on fruitoftheshed
 
matherp
Guru

Joined: 11/12/2012
Location: United Kingdom
Posts: 10610
Posted: 07:57am 21 Jul 2021
Copy link to clipboard 
Print this post

Please try the attached without the pullup resistor


PicoMiteV5.07.00b4.zip


Most versions of MMBasic enable an internal pullup on serial RX. This isn't part of the spec and shouldn't be necessary but I think I've added it to the Picomite although the datasheet is a bit unclear as to whether special functions like serial and pullups are mutually exclusive
 
lizby
Guru

Joined: 17/05/2016
Location: United States
Posts: 3478
Posted: 11:41am 21 Jul 2021
Copy link to clipboard 
Print this post

  matherp said  Please try the attached without the pullup resistor

That worked--thank you very much.

This prints the distance whenever it changes:
PicoMite MMBasic Version 5.07.00b4
Copyright 2011-2021 Geoff Graham
Copyright 2016-2021 Peter Mather
SetPin 21,uart0tx:SetPin 22,uart0rx : Open "com0:9600" As #1 ' (ultrasonic module)
do: if loc(#1)>7 then: a$=input$(7,#1): if b$<>a$ then: b$=a$: ?a$;: endif: endif: loop


D:333
D:249
D:025
D:020
D:016
D:015
D:056
D:019
D:036
D:018
D:050
D:011
D:014
D:012
D:010

PicoMite, Armmite F4, SensorKits, MMBasic Hardware, Games, etc. on fruitoftheshed
 
Print this page


To reply to this topic, you need to log in.

The Back Shed's forum code is written, and hosted, in Australia.
© JAQ Software 2025