Skip to main content

RAK12004 WisBlock MQ2 Gas Sensor Module Quick Start Guide

Prerequisite

What Do You Need?

Before going through each and every step on using RAK12004 WisBlock MQ2 module, make sure to prepare the necessary items listed below:

Hardware

Software

  • Download and install Arduino IDE.
  • To add the RAKwireless Core boards on your Arduino project, install the RAKwireless Arduino BSP. Follow the steps in the RAKwireless Arduino BSP.

Product Configuration

Hardware Setup

RAK12004 module is part of the WisBlock Sensor category and extends the WisBlock system with a gas sensor alert system. The RAK12004 connects to the WisBlock Base Board through the IO slot. The Figure 1 shows the assembly of a WisBlock Core highlighted in green and the module RAK12004 highlighted in red. Also, always secure the connection of the WisBlock module by using the compatible screws. For more information about RAK12004, refer to the Datasheet.

Figure 2238: RAK12004 connection to WisBlock Base Board

Assembling and Disassembling of WisBlock Modules

Assembling

As shown in Figure 2, the location for the IO slot is properly marked by silkscreen. Follow carefully the procedure defined in WisBlock Base board assembly/disassembly instructions to attach a WisBlock module. Once attached, carefully fix the module with one or more pieces of M1.2 x 3 mm screws depending on the module.

Figure 2239: RAK12004 connection to WisBlock Base Board
Disassembling

The procedure in disassembling any type of WisBlock modules is the same.

  1. First, remove the screws.
Figure 2240: Removing screws from the WisBlock module
  1. Once the screws are removed, check the silkscreen of the module to find the correct location where force can be applied.
Figure 2241: Detaching silkscreen on the WisBlock module
  1. Apply force to the module at the position of the connector, as shown in Figure 5, to detach the module from the baseboard.
Figure 2242: Applying even forces on the proper location of a WisBlock module
NOTE

If you will connect other modules to the remaining WisBlock Base slots, check on the WisBlock Pin Mapper tool for possible conflicts. RAK12004 uses I2C and IO pins it can cause possible conflict especially on some IO modules.

After all this setup, you can now connect the battery and USB cable to start programming your WisBlock Core.

warning
  • Batteries can cause harm if not handled properly.
  • Only 3.7-4.2 V Rechargeable LiPo batteries are supported. It is highly recommended not to use other types of batteries with the system unless you know what you are doing.
  • If a non-rechargeable battery is used, it has to be unplugged first before connecting the USB cable to the USB port of the board to configure the device. Not doing so might damage the battery or cause a fire.
  • Only 5 V solar panels are supported. Do not use 12 V solar panels. It will destroy the charging unit and eventually other electronic parts.
  • Make sure the battery wires match the polarity on the WisBlock Base board. Not all batteries have the same wiring.

Software Configuration and Example

The RAK12004 has an electronic sensor used for sensing the concentration of gases in the air. It contains a sensing material whose resistance changes when it comes in contact with the gas. Concentrations of gas is measured using a voltage divider network present in the sensor. The output of the sensing element is connected to a 12-bit ADC (ADC121C021) which communicates through I2C to the application.

Initial Test of the RAK12004 WisBlock Module

  1. Install the RAKwireless Arduino BSP for WisBlock by using the package_rakwireless_index.json board installation package. The WisBlock Core should now be available on the Arduino IDE.

  2. You need to select first the WisBlock Core you have.

RAK4631 Board

Figure 2243: Selecting RAK4631 as WisBlock Core

RAK11200 Board

Figure 2244: Selecting RAK11200 as WisBlock Core

RAK11310 Board

Figure 2245: Selecting RAK11310 as WisBlock Core
  1. Install the RAKwireless MQx Library using Arduino Library Manager.

  2. On the Arduino IDE, select Sketch -> Include Library -> Manage Libraries, as shown in Figure 9.

  3. On the Library Manager text area, type RAKwireless MQx.

Figure 2246: Arduino Library Manager
  1. To finish the installation, click on the Install button, as shown in Figure 10.
Figure 2247: Finish RAK-MQx library Installation
  1. Once the library is installed, open the RAK12004_MQ2_Sampling example.

  2. On the Arduino IDE, select File -> Examples -> RAKWireless MQx Libraries -> RAK12004_MQ2_Sampling, as shown in Figure 11.

Figure 2248: Open RAK12004 MQ2 Sampling Sketch
NOTE

If you experience any error in compiling the example sketch, check the updated code for the RAK12004 WisBlock MQ2 Gas Sensor Module that can be found on the RAK12004 WisBlock Example Code Repository.

  1. You can now select the right serial port and upload the code, as shown in Figure 12 and Figure 13.
Figure 2249: Selecting the correct Serial Port
Figure 2250: Uploading the RAK12004 example code on RAK4631

To extend the use of the RAK-MQx library, check the link RAK-MQx Library methods

Build RAK12004 Example on PlatformIO IDE (optional)

NOTE

This procedure was tested only on Windows 10 and Ubuntu.

  1. Install the original PlatformIO platform, as shown in PlatformIO First Install section.
  • For WisBlock Core RAK4631, install Nordic nRF52 platform.
  • For WisBlock Core RAK11200, install Espressif 32 platform.
  • For WisBlock Core RAK11310, install Raspberry Pi RP2040 platform.
  1. Open a project example that uses the new installed platform.

  2. Launch Visual Studio Code and select PlatformIO PIO Home.

  3. On PIO Home, click on Project Examples.

  4. Choose arduino-blink project, then click on Import button.

Figure 2251: Import arduino-blink project
  1. Click the Yes button on the trust window.
Figure 2252: PlatformIO trust authors
  1. Build the project and ignore warnings and errors.

  2. Download and install the RAK Patch script.

  3. Unzip the contents of RAK_PATCH.zip into the folder RAK_PATCH in your PlatformIO installation folder.

The table below shows the PlatformIO installation directory for each operating system:

PlatformIO path on different OS
Windows 10%UserProfile%\.platformio\
Linux~/.platformio/
MacOS/Users/{Your_User_id}/.platformio/

Figure 16 shows the PlatformIO installation directory on Windows 10.

Figure 2253: RAK patch folder on Windows
  1. Open a command prompt in %UserProfile%.platformio\RAK_PATCH folder and execute python ./rak_patch.py.
Figure 2254: RAK patch installed on Windows
warning

In case of any platform update on PlatformIO, the RAK_PATH script must be executed again after the platform update.

  1. Import the RAK12004 Arduino Project to PlatformIO.

  2. Open PlatformIO PIO Home and select Import Arduino Project, as shown in Figure 18.

Figure 2255: Import RAK12004 Arduino Project
  1. Select your preferred WisBlock Core and check "Use Libraries installed by the Arduino IDE" option, as shown in Figure 19.

  2. Then choose the directory of the original RAK12004 Arduino Project.

Figure 2256: Select Board and check Import Libraries
  1. To finish the import, click on the Import button, as shown in Figure 20.
Figure 2257: Select Board and check Import libraries
  1. Build the imported project on the PlatformIO.

Now, you can build the project by clicking on the highlighted icon, as shown in Figure 21.

Figure 2258: Build Arduino imported project
  1. Upload the imported project on the PlatformIO.

  2. To upload the project on the target board, click on the highlighted icon, as shown in Figure 22.

Figure 2259: Upload Arduino imported project