Crates.io | df2301q |
lib.rs | df2301q |
version | 0.1.0 |
source | src |
created_at | 2023-09-06 04:36:20.241219 |
updated_at | 2023-09-06 04:36:20.241219 |
description | DF2301Q Gravity Offline Voice Recognition Module Rust Driver |
homepage | |
repository | https://github.com/Cosmic-Bee/df2301q.rs |
max_upload_size | |
id | 965018 |
size | 86,000 |
This is a rust driver for the DF2301Q Gravity Voice Recognition Module from DFRobot.
For Python and C++ libraries see the associated DFRobot repository.
This module allows a user over i2c or uart to connect and monitor for a set of preset command words or even train their own for triggering behaviors.
Make sure you install the dependencies for embedded rust and install all of the tooling where needed.
To build, flash, and monitor with the espflash cargo command as such:
cargo espflash flash --monitor
let peripherals = Peripherals::take().unwrap();
let tx = peripherals.pins.gpio43;
let rx = peripherals.pins.gpio44;
let config = Config::new().baudrate(Hertz(9600));
let uart = UartDriver::new(
peripherals.uart1,
tx,
rx,
Option::<gpio::Gpio0>::None,
Option::<gpio::Gpio1>::None,
&config,
)
.unwrap();
let (tx, rx) = uart.split();
let mut df2301q = df2301q::Df2301qUART::new(rx, tx);
df2301q.play_by_command_word(CommandWord::OpenCurtain).unwrap();
loop {
let command_word = df2301q.get_command_word().unwrap();
match command_word {
CommandWord::TurnOnTheLight => {
println!("TurnOnTheLight: Turning On Light");
},
CommandWord::TurnOffTheLight => {
println!("TurnOffTheLight: Turning Off Light");
},
CommandWord::Reset => df2301q.reset().unwrap(),
CommandWord::Silence => (), // Do nothing
_ => println!("Found: {command_word:?}")
}
}
let peripherals = Peripherals::take().unwrap();
let sda = peripherals.pins.gpio5;
let scl = peripherals.pins.gpio6;
let config = Config::new().baudrate(Hertz(115200));
let i2c = I2cDriver::new(
peripherals.i2c0,
sda,
scl,
&config,
)
.unwrap();
let mut df2301q = df2301q::Df2301qI2C::new(i2c);
df2301q.play_by_command_word(CommandWord::OpenCurtain).unwrap();
loop {
let command_word = df2301q.get_command_word().unwrap();
match command_word {
CommandWord::TurnOnTheLight => {
println!("TurnOnTheLight: Turning On Light");
},
CommandWord::TurnOffTheLight => {
println!("TurnOffTheLight: Turning Off Light");
},
CommandWord::Reset => df2301q.reset().unwrap(),
CommandWord::Silence => (), // Do nothing
_ => println!("Found: {command_word:?}")
}
}