Offline Voice recognition SEN0539-EN - How to Learn New Words on MakeCode (micro:bit)
![userHead](https://dfimg.dfrobot.com/667119e8aa9508d63a43c295/makelog/5b603126024d8783a20607788d45b26d_150x150.jpg)
Hello,
How do I (e.g. press button A) and learn a new wake word using MakeCode for SEN0539-EN connected to a micro:bit via I2C
To teach a new wake word using the SEN0539-EN (a voice recognition module) connected to a micro:bit via I2C, you'll need to interact with the module's functionality through commands sent over the I2C bus. Here’s a general approach to achieve this using MakeCode:
### Prerequisites
1. **Hardware Setup**:
- Ensure your SEN0539-EN module is connected correctly to the micro:bit via I2C. This typically involves connecting the SDA (data) and SCL (clock) lines between the micro:bit and the module.
- Power both the micro:bit and the SEN0539-EN module appropriately.
2. **MakeCode Editor**:
- Open the MakeCode editor for micro:bit at [makecode.microbit.org](https://makecode.microbit.org/).
### Steps to Teach a New Wake Word
1. **Initialize I2C Communication**:
- In your MakeCode project, you'll need to use the `I2C` blocks to communicate with the SEN0539-EN module. Initialize the I2C interface with the appropriate address of the module.
```blocks
let i2cAddr = 0x54; // Example address of SEN0539-EN module
// Initialize I2C
pins.i2cFrequency(100000); // Set I2C speed to 100kHz
```
2. **Teach the Wake Word**:
- Voice recognition modules like SEN0539-EN typically provide commands or APIs to teach new wake words. These commands usually involve recording a sample of the wake word and saving it for later recognition.
```blocks
// Teach a new wake word
input.onButtonPressed(Button.A, function () {
// Send command to SEN0539-EN to start teaching mode
pins.i2cWriteNumber(i2cAddr, 0x01, NumberFormat.UInt8LE);
// Wait for confirmation or response from SEN0539-EN
basic.pause(100); // Adjust delay as needed
// Assuming you need to send additional commands to start recording or teaching process
// Example: pins.i2cWriteNumber(i2cAddr, commandByte, NumberFormat.UInt8LE);
});
```
- Replace `0x01` and `commandByte` with the appropriate commands as per the SEN0539-EN module’s documentation. These commands should trigger the module to enter teaching mode and start recording a new wake word sample.
3. **Confirm Teaching Process**:
- After sending the commands to initiate teaching mode and potentially start recording, wait for confirmation or a specific response from the SEN0539-EN module indicating the completion of the process https://www.zouser.com/.
4. **Testing and Debugging**:
- Use the `basic.showString()` or `serial.writeLine()` blocks in MakeCode to debug and display messages received from the SEN0539-EN module over I2C. This helps you verify the module’s response to your commands.
### Notes:
- **Command Details**: Refer to the datasheet or documentation of the SEN0539-EN module for the specific I2C commands and their parameters required to initiate teaching mode and record a new wake word.
- **Error Handling**: Implement error handling and timeouts in your code to handle scenarios where the module does not respond as expected.
- **Integration**: Integrate the wake word recognition functionality into your main program logic once the wake word has been successfully taught and recognized by the SEN0539-EN module.
By following these steps and customizing the I2C commands based on the module’s requirements, you should be able to teach a new wake word using the SEN0539-EN module connected to the micro:bit via MakeCode. Adjust timings, commands, and logic based on your specific module’s capabilities and integration needs.
![userHeadPic](https://dfimg.dfrobot.com/dfPortrait2.png)