"The sensor features advanced gesture detection, proximity detection and digital ambient light sensing. Gesture detection can accurately sense "up, down, left and right" and more complex movements."
Unfortunately, Mind+ does not support the gesture sensor.
However, an Arduino sketch can readily make use of the gesture sensor's functions.
We'll use this as an opportunity to learn about creating Arduino sketches for the Bittle.
Details: [https://docs.petoi.com/extensible-modules/gesture-sensor]
Caution: There is in error in the Software Setup instructions. (The Arduino library in gesture.zip does not work with the Petoi gesture sensor.)
Follow the demo instructions below:
Download Arduino_APDS9960-1.0.4-Petoi.zip. Do not unzip the file; just download the entire file as-is by clicking on the "Download" button. It looks like the icon to the right:
Be sure to remember where you saved the file.
In the Arduino IDE menu: Sketch ... Include Library ... Add .ZIP library
and select the Arduino_APDS9960-1.0.4-Petoi.zip file you downloaded.
Download gesture_tone.ino. Be sure to remember where you saved the file.
Connect your Petoi Bluetooth Adapter to your Bittle.
Turn on the Bittle battery.
Arduino IDE: File ... Open and select the gesture_tone.ino file you downloaded.
Arduino IDE: Sketch ... Upload
Wait for the sketch to compile and uploa to the Bittle.
"avrdude done. Thank you."
Arduino IDE: Tools ... Serial Monitor
On the lower right of the screen, change the "baud rate" to 115200
Complete the Hardware setup instructions to connect the gesture sensor to your Bittle.
Move your hand in front the gesture sensor (up, down, left, right) and see if the gesture sensor has detected the motion.
The sensor is also a "proximity" sensor which indicates if there is an object near the sensor, with a value representing the distance.
You might consider using this in a Bittle Arduino sketch to avoid bumping into walls, for example.
To demonstrate the proximity function:
File ... Examples ... Examples from Custom Libraries ...Arduino_APDS990 ... Proximity Sensor
Compile and Upload the sketch
In the Serial Monitor, change the baud rate to 9600.
Move you hand in front of the sensor and observe the value of the proximity sensor.
What number indicates the closest distance to the sensor?
The farthest? (How far is that distance?)
Try the other examples from the Arduino_APDS990 library.
This sensor can also detect the color of an object in front of it.
Maybe you have some ideas for a Bittle project that uses this sensor?
As we've been creating Mind+ programs, the Bittle has been running the OpenCat firmware.
In fact, OpenCat is an Arduino sketch. It's open source, so you can download it and modify it.
It's a very complex Arduino sketch compared to the gesture examples we've seen so far.
But, you can easily check it out:
Go to the OpenCat github page: https://github.com/PetoiCamp/OpenCat.
Click on the "Code" button and "Download ZIP" and save the OpenCat-main.zip file
Unzip the file
Change the folder name from OpenCat-main to OpenCat.
Arduino IDE: File ... Open. Navigate to the OpenCat folder you just downloaded and unzipped and select OpenCat.ino.
Change the following line:
//#define GESTURE //for Gesture module
to
#define GESTURE //for Gesture module
The "//" characters make the line a comment, not code. Removing the "//" makes the line code by "uncommenting" it.
Make sure your Bittle is in a secure place with some room to move, as the OpenCat sketch with the gesture sensor enabled
will cause it to move!
Arduino IDE: Sketch ... Upload
to compile and upload the OpenCat sketch.
In the Serial Monitor, change the baud rate to 115200
Try up, down, left, right gestures.
The remote control that is included with the Bittle kit works with the OpenCat sketch.
Place your Bittle on the floor in an open space. Try all the buttons. Careful: Some of the buttons
will make Bittle trot/walk/run away from you!
And, all the remote controls are the same, so find your own place to experiment.
Do not aim your remote control at someone else's Bittle or chaos will ensue! :-)
You can also use the Petoi App on your Android or iOS smartphone.
Details: [https://docs.petoi.com/mobile-app/introduction]
How does this gesture code work? You can read it by adding a file to the Arduino IDE.
Sketch ... Add File ... src ... gesture.h
(Note that the OpenCat folder includes many source code files -- these are all compiled to build the "firmware."
You'll see "gesture.h" in another tab in the Arduino IDE. Click on the "gesture.h" tab. Like this:
If you some Arduino coding experience, you might want to try to modify gesture.h.
You might want to change the tones associated with the gestures.
You can change the Skills (motions) for the gestures.
For example, GESTURE_UP runs the "High five" skill with this code:
tQueue->addTask('k', "fiv", 2000);
Refer to https://docs.petoi.com/apis/serial-protocol to learn the commands for the other Skills included in OpenCat.