The Camera module allows you to use your mobile camera for different activities like recording videos, capturing images, color detection, and face detection. Depending on the type of activities you want to do with your mobile camera the module is further divided into four modules each capable of executing a specific activity.
These modules are:
- Camera and Videos
- Color Detector
- Line Follower (Coming Soon)
- Face Detector (Coming Soon)
Camera and Video Module
Like any general camera application present in mobile this module also allows you to take pictures and videos but it also allows you to handle these activities by sending the command from your hardware.
You can send the command from your board to:
- Record videos
- Capture images
- Flip camera to front or rear
- Change the flash mode to ON, OFF or Auto
- Change zoom scaling
- Set camera quality to High or Low.
Control of the same things is also possible from icons present in the module. You can view the images or videos captured through this module by clicking on the gallery icon present in middle at the top right corner of your screen beside the connect icon.
Arduino IDE Functions
To include the Camera and Video module in the Arduino program, you have to include the following header:
After defining the above mention headers, you have to include the dabble library:
You can download the zip of Arduino Library for
depending on the board you are using.
Enabling Bluetooth Communication
To enable Bluetooth communication, you have to initialize serial communication using the following code:
- For evive and Arduino Mega, Uno and Nano
Here Baud_Rate is the baud rate set for the Bluetooth module. With evive, you normally get 115200 baud rate modules.
- For ESP32
In place of Bluetooth_Name enter name that you want to keep for Bluetooth of ESP32. Default name given in the library is “MyEsp32”.
Refreshing the data
To refresh the data that the device has got from the mobile app, you have to use the following line of code:
This function also change the state and the brightness of the LED automatically and you don’t have to do anything.
Following are the function available for the Camera and Video module:
- captureImage() – Sends command to click images.
- startRecording() – Sends command to start video.
- stopRecording() – Sends command to stop video.
- flipTo(direction) – This function sends the command to rotate the camera to front or rear. There are two constants namely FRONT and REAR defined in the library to change camera direction. Pass either of constant as an argument in place of “direction” in the function.
- setQuality(quality) – This function sends the command to set the quality of the camera. Using this function the quality of the camera can be set to high or low. There are two constants namely HIGH_QUALITY and LOW_QUALITY. Pass either of constant as an argument in place of “quality” in the function.
- flashMode(modeName) – This function sends the command to set flash mode. Using this command flash can be set to On, Off or Auto mode. There are three constants namely ON, OFF and AUTO. Pass either of the constant as an argument in place of “modeName” in the function.
- zoom(value) – Enter a value between 0 – 100 for setting that much percentage zoom on your mobile camera.
- setParameters(Direction, flash, quality, zoom) – This function allows you to set all basic camera settings before taking image or video. The direction of the camera, the flash status, quality and zoom value are passed as arguments to this function in sequential order as written. All these parameters are constants mentioned in the above functions.
PictoBlox (Scratch) Blocks
There are three blocks in this module. All three blocks are explained below:
- “set camera flash to” is a stacked block used for changing flash settings, camera quality and zoom settings of the camera. The block consists of two drop-down and a numeric entry section each helps in setting a unique parameter of Camera.
First drop-down is for flash setting, it allows you to set the flash mode to On, Off or Auto.
Second drop-down is for setting quality, it allows you to set camera quality to high or low. Enter zoom percent between 0 to 100 in the text field of zoom for getting that much % of zoom for camera.
- “rotate camera to” is a stacked block used to rotate the camera in the module. Its drop-down contains two option namely “rear” and “front” for rotating the camera to the front or rear side.
- “capture image on camera” is a stacked block used to send command for clicking image, starting the video and stopping the video in the camera module. Its drop-down consists of three options namely “Capture Image”, “Start Video” and “Stop Video”.
In this example, you will capture images and record video with different camera settings.
Follow these steps:
- Copy code as per your board in Arduino IDE
- Upload code
- Connect with Dabble and open Camera and Video module
Following activities occur while pressing slide switch and tactile switches on evive:
- On pressing Tactile Switch 1 – a High-quality image is captured from the front camera.
- On pressing Tactile Switch 2 – a Low-quality image is captured in auto flash mode from the rear camera.
- On sliding up Slide Switch 1 – a High-quality video recording starts from the rear camera with 50% zoom.
Mega, Uno, and Nano
After uploading code open serial monitor. you will be able to see instructions printed on Serial Monitor asking you to enter any number between 1 to 4. For each number, there is a task mentioned that will be executed.
After uploading code open serial monitor and reset your board once. You will be able to see instructions on serial monitor follow them to capture images and videos from Camera Module.
There are two scripts given below, out of which one is for capturing the image and one is for recording a 30-second video. Both the scripts are made for Stage Mode in PictoBlox. Both the scripts will work for evive and Arduino Uno, Nano, and Mega. Currently PictoBlox does not support ESP32; however, its support will be added soon.