Ultrasonic Sensor

Function introduction

Petoi RGB Ultrasonic Sensor is a new module that integrates RGB LED and ultrasonic ranging. Only one GPIO is needed to operate the ultrasonic transceiver. While the ultrasonic probe measures the distance, the other GPIO pin can drive RGB LEDs with various light effects.

The previous one:

NyBoard

Hardware setup

Connecting to the NyBoard with wire as shown in the following picture:

The previous one:

Attach the ultrasonic sensor to Nybble's eye.

Software setup

There are two methods to upload the ultrasonic mode firmware :

  • Using the Petoi Desktop App

  • Using the Arduino IDE

Petoi Desktop App

  • You can use the Firmware Uploader within the Petoi Desktop App. Please select the correct Product type, Board version, and Serial port according to your actual use. The mode should be Ultrasonic, so press the Upgrade the Firmware button. For example, Nybble, NyBoard_V1_2, COM5 as follows:

Arduino IDE

  • You can use Arduino IDE to upload and modify the source code.

Use the latest OpenCat code to finish the setup. For example, to modify the code for Nybble as shown below:

If you have already uploaded the latest OpenCat code to make Nybble walk, you only need to uncomment the #define ULTRASONIC at the beginning of OpenCat.ino, then upload the code.

If you are unsure, you need to finish the upload process for the standard mode (Step 1 to Step 10) to ensure everything is configured correctly, then upload the code in the Ultrasonic mode.

If the Ultrasonic code is uploaded correctly, you can see success messages printed on the serial monitor of Arduino IDE. As shown below:

Arduino code demo

Ultrasonic module code realization function: The probe inside the ultrasonic module lights up with different-colored lights according to the different distances monitored by the ultrasonic module in real-time, and Nybble will make different action responses at the same time.

The demo video is as follows:

Mind+ demo code

https://github.com/PetoiCamp/Petoi_MindPlusLib/blob/main/examples/NyBoard/avoidObs_NyBoard.mp

BiBoard

Hardware setup

BiBoard V0

Take Bittle X for example, connecting to the BiBoard with a wire as shown in the following picture:

The dial switch on the bottom of the BiBoard extension hat is dialed to UART2 .

BiBoard V1

The sensor should connect to the first Grove socket from the top.

Software setup

There are two methods to upload the firmware :

  • Using the Petoi Desktop App

  • Using the Arduino IDE

Petoi Desktop App

  • You can use the Firmware Uploader within the Petoi Desktop App. Please select the correct Product type, Board version, and Serial port according to your actual use. The mode should be Standard, so press the Upgrade the Firmware button. For example, Bittle, BiBoard_V0_2, COM5 as follows:

Arduino IDE

  • You can use Arduino IDE to upload the sketch(OpenCatEsp32.ino). Use the latest OpenCatESP32 code to finish the setup. For example, to modify the code for Bittle as shown below:

After uploading, there are two methods to activate/deactivate the ultrasonic mode:

  • Serial Monitor

    • Open the serial monitor and use the serial command "XU" to activate the ultrasonic mode.

    • Open the serial monitor and use the serial command "Xu" to deactivate the ultrasonic mode.

  • Mobile App

    • Create a mobile app command called "Activate ultrasonic" and use the code: X85

    • Create a mobile app command called "Deactivate ultrasonic" and use the code: X117

Mind+ demo code

https://github.com/PetoiCamp/Petoi_MindPlusLib/blob/main/examples/BiBoard/avoidObs_BiBoard.mp

Last updated

Was this helpful?