https://github.com/mnishiguchi/dypa01
Use DYP-A01 ultrasonic distance sensor in Elixir
https://github.com/mnishiguchi/dypa01
distance-sensor dyp-a01 elixir elixir-lang elixir-language nerves nerves-project sensor sensors
Last synced: 12 months ago
JSON representation
Use DYP-A01 ultrasonic distance sensor in Elixir
- Host: GitHub
- URL: https://github.com/mnishiguchi/dypa01
- Owner: mnishiguchi
- License: mit
- Created: 2021-08-28T23:57:09.000Z (over 4 years ago)
- Default Branch: main
- Last Pushed: 2021-09-04T21:36:02.000Z (over 4 years ago)
- Last Synced: 2025-02-04T00:25:56.562Z (about 1 year ago)
- Topics: distance-sensor, dyp-a01, elixir, elixir-lang, elixir-language, nerves, nerves-project, sensor, sensors
- Language: Elixir
- Homepage: https://dev.to/mnishiguchi/use-dyp-a01-ultrasonic-distance-sensor-in-elixir-bp4
- Size: 21.5 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# DYP-A01
[](https://hex.pm/packages/dypa01)
[](https://hexdocs.pm/dypa01)
[](https://github.com/mnishiguchi/dypa01/actions/workflows/ci.yml)
[](https://github.com/mnishiguchi/dypa01/actions/workflows/publish.yml)
Use [DYP-A01](https://www.adafruit.com/product/4664) ultrasonic distance sensor in Elixir.
## Usage
```elixir
# List available serial ports
iex> Circuits.UART.enumerate
%{
"ttyAMA0" => %{},
"ttyS0" => %{},
"ttyUSB0" => %{
description: "CP2102 USB to UART Bridge Controller",
manufacturer: "Silicon Labs",
product_id: 60000,
serial_number: "0001",
vendor_id: 4292
}
}
# Start a gen server for interacting with a DYP-A01 sensor on port ttyAMA0
iex> {:ok, pid} = DYPA01.start_link(port_name: "ttyAMA0")
{:ok, #PID<0.1407.0>}
# Measure the current distance
iex> DYPA01.measure(pid)
{:ok, %DYPA01.Measurement{distance_mm: 1680, timestamp_ms: 321793}}
```
## Wiring
This library assumes the "UART auto output" mode, which is enabled when the sensor's "RX" cable is unused.
For example, when connecting the sensor to Raspberry Pi's GPIO pins, use only the following three pins.
| Cable number | Cable name | Raspberry Pi |
| ------------ | ---------- | ------------ |
| 1 | VCC | GPIO 4 (5V) |
| 2 | GND | GPIO 6 (GND) |
| 3 | RX | |
| 4 | TX | GPIO 8 (RX) |