Sensors Range Finder
Demonstrates reading data from a range finder connected to a device UART.
- SDK directory:
apps/sensors/range_finder
API Features Demonstrated
Platforms
This app works on:
- AMW004 - Zentri Mackerel evaluation board
- AMW106 - Zentri Moray evaluation board
- AVN4343 - Avnet IoT Starter Kit
- NXP-SCCK - NXP Secure Cloud Connectivity Kit
Requirements and Prerequisites
This app requires a ZentriOS evaluation board. See the Platforms list above.
This app requires a Digilent Pmod MAXSONAR range finder.
Description
This app demonstrates reading range finding data from a Digilent Pmod MAXSONAR, connected to a device UART.
Usage Instructions
Connect the range finder to the device UART.
Open a ZentriOS serial terminal to the device. See Getting Started, Opening a ZentriOS Terminal.
Run the app.
The app displays range finder data on the terminal.
Implementation
zn_app_init
- Calls zn_event_enable_irq_events to allow UART interrupt events
- Calls
initialize_uart
to set up the UART
initialize_uart
- Sets up a UART config for 9600 baud, width 8 bits, no parity, 1 stop bit and no flow control.
- Calls zn_uart_configure to configure the UART with the config.
- Calls
zn_uart_register_rx_callback
to set up the UART rx callback function asuart_rx_irq_callback
uart_rx_irq_callback
- Calls
zn_event_issue
to fire off theuart_rx_event_handler
. This is necessary to move processing out of the hardware IRQ context ofuart_rx_irq_callback
and back into the ZAP context ofuart_rx_event_handler
. See Development, Execution Content.
uart_rx_event_handler
- Calls zn_uart_peek_bytes to check for available data
- Loops, calling zn_uart_receive_bytes to receive a byte at a time, until byte is
R
character - Calls zn_uart_receive_bytes to receive integer range value as 3 ASCII digits.
- Displays range value if in range, or an out of range notification.
- Displays result on terminal.
Source
See: