Movatterモバイル変換


[0]ホーム

URL:


Skip to content
DEV Community
Log in Create account

DEV Community

Cover image for Self-Aligning Dish in Rust: Command Application
Ian Ndeda
Ian Ndeda

Posted on

Self-Aligning Dish in Rust: Command Application

This part of the series will be an application of the preceding part, which enabled our project to receive commands remotely via Bluetooth.

Table of Contents

Requirements

  • 1 x Raspberry Pi Pico board
  • 1 x USB Cable type 2.0
  • 1 x HC-05 Bluetooth module
  • 10 x M-M jumper wires
  • 2 x Mini Breadboards
  • Serial Bluetooth Terminal App

Implementation

command-loop

In themain part of the program, under the super loop, we need to check whether we are inauto ormanual mode. We'll also need to enter a critical section since shared variables will be used. 

Add handles foruart_cmd anddirection.

cortex_m::interrupt::free(|cs|{letmutdirection=DIRECTION.borrow(cs).borrow_mut();letmutuart_cmd=UARTCMD.borrow(cs).borrow_mut();ifAUTO.borrow(cs).get(){// Auto mode}else{// Manual mode}});
Enter fullscreen modeExit fullscreen mode

Then add the following under theauto andmanual arms respectively:

writeln!(&mutserialbuf,"auto mode").unwrap();transmit_uart_cmd(uart_cmd.as_mut().unwrap(),serialbuf);writeln!(&mutserialbuf,"manual mode").unwrap();transmit_uart_cmd(uart_cmd.as_mut().unwrap(),serialbuf);
Enter fullscreen modeExit fullscreen mode

Undermanual mode, we'll add the below code that applies our algorithm.

// manual modematchdirection.as_mut(){Some(Direction::Cw)=>{*direction=None;// reset directionwriteln!(&mutserialbuf,"manual mode: cw").unwrap();transmit_uart_cmd(uart_cmd.as_mut().unwrap(),serialbuf);},Some(Direction::Ccw)=>{*direction=None;writeln!(&mutserialbuf,"manual mode: ccw").unwrap();transmit_uart_cmd(uart_cmd.as_mut().unwrap(),serialbuf);},Some(Direction::Up)=>{*direction=None;writeln!(&mutserialbuf,"manual mode: up").unwrap();transmit_uart_cmd(uart_cmd.as_mut().unwrap(),serialbuf);},Some(Direction::Down)=>{*direction=None;writeln!(&mutserialbuf,"manual mode: down").unwrap();transmit_uart_cmd(uart_cmd.as_mut().unwrap(),serialbuf);},Some(Direction::Zero)=>{*direction=None;writeln!(&mutserialbuf,"manual mode: position zero").unwrap();transmit_uart_cmd(uart_cmd.as_mut().unwrap(),serialbuf);},None=>{},}
Enter fullscreen modeExit fullscreen mode

Connections

The connections will remain the same as from the previous part of the series.

command-connections

Results

After rearranging our code we will getthis final copy.

Here are highlights of changes from the previous program.

Running this program will flash it into the Pico, and we'll be set to receive commands remotely via Bluetooth.

We can see that while inauto mode any further received commands other thanA are not consequential.

command-results-1

Inmanual mode the system responds appropriately to further commands.

command-results-2

Next we will set up our system to receive GPS data from the Neo-6m GPS module.

Top comments(0)

Subscribe
pic
Create template

Templates let you quickly answer FAQs or store snippets for re-use.

Dismiss

Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment'spermalink.

For further actions, you may consider blocking this person and/orreporting abuse

Embedded Developer
  • Joined

More fromIan Ndeda

DEV Community

We're a place where coders share, stay up-to-date and grow their careers.

Log in Create account

[8]ページ先頭

©2009-2025 Movatter.jp