Connect IKEA Air Quality Sensor to Apache NuttX OS

đź“ť 12 Feb 2022

IKEA VINDRIKTNING Air Quality Sensor seated on Pine64 PineDio LoRa Gateway

IKEA VINDRIKTNING Air Quality Sensor seated on Pine64 PineDio LoRa Gateway

IKEA VINDRIKTNING is a $12 hackable Air Quality Sensor that measures PM 2.5 (Particulate Matter) with reasonable accuracy.

Let’s connect the IKEA Sensor to a RISC-V Microcontroller Board: Pine64 PineDio Stack BL604 (pic below) running on Apache NuttX operating system.

(Our code will run on ESP32 too)

Why are we doing this?

In a while we’ll dive into the code that talks to the IKEA Sensor…

But first let’s solder and wire up the IKEA Sensor!

Will it work with Arduino?

Check out these projects…

Pine64 PineDio Stack BL604 RISC-V Board

Pine64 PineDio Stack BL604 RISC-V Board

§1 About IKEA Air Quality Sensor

I found the VINDRIKTNING sensor at my local IKEA Store (IKEA Tampines Singapore) in the Lighting Section…

(Near the Air Purifiers. Wow IKEA has Air Purifiers now)

IKEA VINDRIKTNING Air Quality Sensor at IKEA Tampines Singapore in the Lighting Section near the Air Purifiers

Connect the sensor to a USB-C Power Cable (not included) and it lights up in Red, Amber or Green…

IKEA VINDRIKTNING Air Quality Sensor powered on

ColourPM 2.5 (ÎĽg/mÂł)Air Quality
Green0 - 35Good
Amber36 - 85OK
Red86 and aboveNot good

(Watch it in action on YouTube)

(IKEA VINDRIKTNING Manual)

Huh? This sensor outputs only 3 levels of Air Quality?

Actually the sensor is capable of measuring PM 2.5 from 0 to 1,000 μg/m³… Just that we need to wire it ourselves to get the PM 2.5 value.

The brilliant folks at the Home Assistant Project discovered that inside the IKEA Sensor is a PM1006 Infrared LED Particle Sensor…

PM1006 Infrared LED Particle Sensor

(From PM1006 Datasheet)

The PM1006 Sensor exposes a UART (Serial) Port that transmits the PM 2.5 value, encoded like so…

PM1006 Sensor inside IKEA VINDRIKTNING Air Quality Sensor transmits PM 2.5 over UART

(From PM1006 Datasheet)

To get the PM 2.5 data, let’s wire up the UART Port with a little soldering.

(FYI: Inside the IKEA Sensor is another microcontroller that talks to PM1006. Periodically it triggers the PM1006 command that measures PM 2.5)

(Caution: The UART Port runs at 5V, not 3.3V)

Inside the IKEA VINDRIKTNING Air Quality Sensor

§2 Solder UART Port

Follow these steps to solder the UART (Serial) Port on the IKEA VINDRIKTNING Sensor (so we can access the PM 2.5 data)…

  1. Unscrew the 4 screws on the back of the IKEA Sensor

  2. Flip open the Back Cover to reveal the Circuit Board

    (Pic above)

  3. Solder these Circular Pads on the Circuit Board…

    IKEA SensorUART PinWire Colour
    RESTTXBlue
    GNDGNDBlack

    (Pic below)

  4. Stay clear of the Surface Mounted Components!

    (Near the GND Pad)

  5. Pardon my horrid soldering…

    If you’re curious how I did it, check the Appendix for the Soldering Steps…

    “Solder UART Port on IKEA VINDRIKTNING Air Quality Sensor”

    (Hint: Use Sticky Tape and very fine Solder Wire)

  6. Test our handiwork with a Multimeter.

    Note that the REST and GND Pins are exposed as tiny strips at the top of the pic below. Perfect for Multimeter Testing!

  7. Optional: I used Bus Pirate to sniff the UART Port and inspect the data transmitted by the sensor. (See the details in the Appendix)

UART Port soldered to IKEA VINDRIKTNING Air Quality Sensor

§3 Connect to PineDio Stack BL604

Now that we have exposed the UART Port on IKEA Air Quality Sensor, let’s connect it to our Microcontroller Board: PineDio Stack BL604

FromToWire Colour
IKEA RESTResistor R1Blue
IKEA GNDPineDio GND
Pin 20
Black
Resistor R1Resistor R2(Breadboard)
Resistor R2Resistor R3(Breadboard)
Resistor R1PineDio RX
GPIO 3 / Pin 14
Red
Resistor R3PineDio GND
Pin 20
Green
(Unused)PineDio TX
GPIO 4 / Pin 13

(R1, R2 and R3 are 3 Resistors with the same resistance, like 2.2 kΩ in the pic below)

(“PineDio Pin” refers to the 20-pin GPIO Connector on PineDio Stack)

IKEA VINDRIKTNING Air Quality Sensor connected to Pine64 PineDio Stack BL604 RISC-V Board with Voltage Divider

Why the resistors?

That’s because IKEA Sensor’s UART Port runs at 5V, not 3.3V. (See this)

And our Microcontroller Board is not 5V Tolerant.

To convert the 5V UART Port to 3.3V, we connect 3 Resistors (of the same resistance) as a Voltage Divider…

IKEA VINDRIKTNING Air Quality Sensor connected to Pine64 PineDio Stack BL604 RISC-V Board with Voltage Divider

How did we get GPIO 3 and 4?

The GPIO Pin Numbers for the UART Port (UART1) are defined in board.h

#define BOARD_UART_1_RX_PIN \
  (GPIO_INPUT     | GPIO_PULLUP | \
   GPIO_FUNC_UART | GPIO_PIN3)

#define BOARD_UART_1_TX_PIN \
  (GPIO_INPUT     | GPIO_PULLUP | \
   GPIO_FUNC_UART | GPIO_PIN4)

(Which pins can be used? See this)

For ESP32: The GPIO Pin Numbers for the UART Port (UART1) are defined in Kconfig and menuconfig…

config ESP32_UART1_TXPIN
  int "UART1 Tx Pin"
  default 10
  range 0 39

config ESP32_UART1_RXPIN
  int "UART1 Rx Pin"
  default 9
  range 0 39

Connect the USB Ports of IKEA Sensor and PineDio Stack to our computer.

(Remember: Only One Power Source for both gadgets!)

It looks messy with 2 USB Cables hanging off our computer, but we’ll live with it for now.

§4 NuttX App

We’re all ready to read the PM 2.5 data from the IKEA Air Quality Sensor!

Let’s dive into the Source Code of our NuttX App that will read and process the PM 2.5 data…

But first: What’s inside the PM 2.5 data?

PM1006 Sensor inside IKEA VINDRIKTNING Air Quality Sensor transmits PM 2.5 over UART

(From PM1006 Datasheet)

§4.1 Sensor Data Frame

The IKEA Sensor transmits a stream of Sensor Data that looks like this…

16  11  0B  00  00  00  17  00  00  02  FF  00  00  00  21  02  00  00  0B  88
16  11  0B  00  00  00  17  00  00  02  FF  00  00  00  21  02  00  00  0B  88
16  11  0B  00  00  00  18  00  00  03  04  00  00  00  22  02  00  00  0B  80
16  11  0B  00  00  00  18  00  00  03  04  00  00  00  22  02  00  00  0B  80

(Watch the demo on YouTube)

See the pattern? The data comes in chunks of 20 bytes. Let’s call it a Sensor Data Frame.

Each Sensor Data Frame starts with this header…

16  11  0B

If we look back at the PM1006 Datasheet (pic above), we realise that the 20-byte Sensor Data Frame (“Response”) may be decoded like so…

FieldValue
Header16 11 0B
(Unused)00 00
PM 2.500 17
(Unused)00 00 02 FF 00 00
(Unused)00 21 02 00 00 0B
Checksum88

This gives the PM 2.5 value of 23 (0x0017).

20-byte Sensor Data Frames from IKEA VINDRIKTNING Air Quality Sensor

What about the Checksum?

To validate the Checksum, all 20 bytes must add up to 0.

We skip the Sensor Data Frames that don’t add up to 0.

Thus we have a plan for reading and processing the PM 2.5 data…

  1. Read the data into a 20-byte Sensor Data Frame

    (We shift the data into the 20-byte frame, byte by byte)

  2. Check the Header in the Sensor Data Frame

    (Header should be 16 11 0B)

  3. Validate the Checksum in the Sensor Data Frame

    (All bytes must add up to 0)

  4. Extract the PM 2.5 value from the Sensor Data Frame

    (And process the PM 2.5 value)

§4.2 Main Loop

This is the Main Loop that runs the steps above: ikea_air_quality_sensor_main.c

//  Current data in the Sensor Data Frame (20 bytes)
static uint8_t frame[20];

//  Read and process the Sensor Data from IKEA Air Quality Sensor
int main(int argc, FAR char *argv[]) {

  //  Open the UART port
  int fd = open("/dev/ttyS1", O_RDONLY);
  if (fd < 0) { printf("Unable to open /dev/ttyS1\n"); return 1; }

We begin by opening the UART Port at /dev/ttyS1.

Next we loop forever, reading bytes from the UART Port and handling them…

  //  Forever process bytes from the UART port
  for (;;) {
    //  Read a byte from the UART port
    char ch;
    read(fd, &ch, 1);
    printf("%02x  ", ch);

After reading a byte, we shift it into the Sensor Data Frame (20 bytes)…

    //  Append to Sensor Data Frame after shifting the bytes.
    //  We always append bytes to the frame (instead of replacing bytes)
    //  because UART is unreliable and bytes may be dropped.
    for (int i = 0; i < sizeof(frame) - 1; i++) {
      frame[i] = frame[i + 1];
    }
    frame[sizeof(frame) - 1] = ch;

We check if the Sensor Data Frame contains a valid Header and Checksum…

    //  If frame is complete and valid...
    if (frame_is_valid()) {
      //  Process the frame
      process_frame();
    }   

If the Sensor Data Frame is valid, we process the data in the frame.

Let’s jump into frame_is_valid and process_frame.

Main Loop

§4.3 Validate Sensor Data

This is how we validate the Sensor Data Frame: ikea_air_quality_sensor_main.c

//  Header for Sensor Data Frame
static const uint8_t PM1006_RESPONSE_HEADER[] = 
    { 0x16, 0x11, 0x0B };

//  Return true if we have received a complete and valid Sensor Data Frame
static bool frame_is_valid(void) {

  //  Check the header at frame[0..2]
  if (memcmp(frame, PM1006_RESPONSE_HEADER, sizeof(PM1006_RESPONSE_HEADER)) != 0) {
    //  Header not found
    return false;
  }

We verify that the Sensor Data Frame contains the Header: 16 11 0B

Next we sum up all the bytes in the Sensor Data Frame…

  //  Compute sum of all bytes in the frame
  uint8_t sum = 0;
  for (int i = 0; i < sizeof(frame); i++) {
    sum += frame[i];
  }

(Including the Checksum at the last byte)

And we verify that the sum is 0…

  //  All bytes must add to 0 (because of checksum at the last byte)
  if (sum != 0) {
    //  Invalid checksum
    printf("\nPM1006 checksum is wrong: %02x, expected zero\n", sum);
    return false;
  }

Now that the Sensor Data Frame is complete and valid…

  //  We have received a complete and valid response frame
  return true;
}

We proceed to process the PM 2.5 data inside the frame.

Validate Sensor Data

§4.4 Process Sensor Data

To process the Sensor Data Frame, we extract the PM 2.5 value from the frame: ikea_air_quality_sensor_main.c

//  Process the PM 2.5 data in the Sensor Data Frame
static void process_frame(void) {

  //  frame[3..4] is unused
  //  frame[5..6] is our PM2.5 reading
  //  In the datasheet, frame[3..6] is called DF1-DF4:
  //  https://github.com/arendst/Tasmota/files/7083662/PM1006_LED_PARTICLE_SENSOR_MODULE_SPECIFICATIONS.pdf

  const int pm_2_5_concentration = 
    frame[5] * 256 + 
    frame[6];

Right now we’re not really using the PM 2.5 data…

  //  TODO: Transmit the sensor data
  printf("\nGot PM2.5 Concentration: %d µg/m³\n", pm_2_5_concentration);
}

But in the next article we’ll transmit the data wirelessly over LoRaWAN to The Things Network.

(Thanks to the onboard LoRa Transceiver on PineDio Stack)

The code in our NuttX App was inspired by the Arduino and ESPHome modules for the IKEA Sensor.

Process Sensor Data

§5 Run NuttX App

We’re ready to run our NuttX App to read and process the PM 2.5 Sensor Data!

  1. Follow these steps to build, flash and run NuttX…

    “Build, Flash and Run NuttX”

    Remember to enable the UART1 Port /dev/ttyS1 and set it to 9,600 bps…

    Enable UART1 and set to 9,600 bps

    (Here’s how)

  2. At the NuttX Shell, enter this command…

    ls /dev
    

    We should see our UART Port configured at /dev/ttyS1…

    /dev:
    console
    null
    timer0
    ttyS1
    zero
    

    Which is connected to our IKEA Sensor.

  3. Enter this command to dump the output from our IKEA Sensor…

    cat /dev/ttyS1
    

    We should see some meaningless ASCII data…

    3(1>
    2'0A
    2%0C
    1$/F
    

    (Watch the demo on YouTube)

    But that’s OK, it means that our IKEA Sensor is alive.

  4. Finally enter this command to run our NuttX App for the IKEA Sensor…

    ikea_air_quality_sensor
    

    We should see the 20-byte Sensor Data Frames and the decoded PM 2.5 values…

    16  11  0b  00  00  00  17  00  00  02  ff  00  00  00  21  02  00  00  0b  88
    Got PM2.5 Concentration: 23 µg/m³
    
    16  11  0b  00  00  00  18  00  00  03  04  00  00  00  22  02  00  00  0b  80
    Got PM2.5 Concentration: 24 µg/m³
    
    16  11  0b  00  00  00  17  00  00  03  01  00  00  00  21  02  00  00  0b  85
    Got PM2.5 Concentration: 23 µg/m³
    

    (Watch the demo on YouTube)

Our NuttX App reads PM 2.5 data from IKEA VINDRIKTNING Air Quality Sensor

Congratulations we have successfully read the PM 2.5 values from the IKEA VINDRIKTNING Air Quality Sensor! 🎉

NuttX transmits a CBOR Payload to The Things Network Over LoRaWAN

§6 What’s Next

In the next article we shall transmit the PM 2.5 data wirelessly over LoRaWAN to The Things Network. (Thanks to the onboard LoRa Transceiver on PineDio Stack)

Imagine connecting a community of Air Quality Sensors miles apart (because of LoRa’s long range). That would be super interesting for Environment Monitoring!

(We’ll visualise the PM 2.5 data with Prometheus and Grafana)

Stay Tuned!

Many Thanks to my GitHub Sponsors for supporting my work! This article wouldn’t have been possible without your support.

Got a question, comment or suggestion? Create an Issue or submit a Pull Request here…

lupyuen.github.io/src/ikea.md

UART Port of IKEA VINDRIKTNING Air Quality Sensor runs at 5V, not 3.3V

§7 Notes

  1. This article is the expanded version of this Twitter Thread

  2. According to the PM1006 Datasheet, the UART Port runs at 5V Logic Level (instead of 3.3V, see pic above).

    Apparently some folks are using the 5V UART Port just fine without converting to 3.3V. (See this)

    But to protect our microcontroller (which is not 5V Tolerant) we need a Voltage Divider…

    Voltage Divider for UART Port of IKEA VINDRIKTNING Air Quality Sensor

    (With 3 resistors of the same value)

    The pic shows it’s not exactly 3.3V, but as long as our Logic High is above 2V, we should be fine. (See this)

  3. Each Sensor Data Frame has 20 bytes. Why are so many bytes unused?

    IKEA Air Quality Sensor uses the PM1006 Sensor, which is a cheaper version of PM1006K.

    On PM1006K we get more data fields: PM 1.0 and PM 10. These fields are not available on PM1006, hence we have unused bytes in the Sensor Data Frame.

    (PM1006K Datasheet)

Very Fine Solder Wire (0.38 mm diameter) and 22 AWG Solid Core Wire

§8 Appendix: Solder UART Port on IKEA VINDRIKTNING Air Quality Sensor

Here’s how I soldered the UART (Serial) Port on the IKEA VINDRIKTNING Air Quality Sensor.

(Sorry I’m terribly inexperienced with soldering 🙏)

I used very fine Solder Wire (0.38 mm diameter) because it creates very tiny, precise blobs of solder. And 22 AWG Solid Core Wire (Blue and Black).

(See pic above)

Here are the steps…

  1. Unscrew the Back Cover to reveal the Circuit Board

    (Here’s how)

    Inside the IKEA VINDRIKTNING Air Quality Sensor

  2. We’ll solder these Circular Pads on the Circuit Board…

    IKEA SensorUART PinWire Colour
    RESTTXBlue
    GNDGNDBlack

    (See the pic)

  3. We start with the REST Pad.

    Mask out with Sticky Tape all the parts around the REST Pad that should NOT be soldered.

    Mask out with Sticky Tape all the parts around the REST Pad on IKEA VINDRIKTNING Air Quality Sensor

  4. With our Soldering Iron, drop a tiny blob of Molten Solder on the REST Pad.

    (Very fine Solder Wire really helps)

  5. Carefully place our Blue Solid Core Wire (or similar) on top of the Solder Blob.

    (Now hardened)

  6. Gently tap our Soldering Iron on top of the wire.

    The wire should sink into the Molten Blob of Solder.

  7. Quickly adjust the wire to make sure it doesn’t touch any components on the Circuit Board.

    When cooled, the wire stays in the hardened Solder Blob.

  8. Now we solder the GND Pad.

    Mask out with Sticky Tape all the parts around the GND Pad that should NOT be soldered.

    (Especially the Surface Mounted Components near the GND Pad)

  9. Repeat the earlier steps to solder the GND Pad with our Black Solid Core Wire.

    Stay clear of the Surface Mounted Components!

    Soldered GND Pad

  10. Remove the Sticky Tape. We’re done!

    UART Port soldered to IKEA VINDRIKTNING Air Quality Sensor

  11. Bend the Solid Core Wires and bind them with Sticky Tape so they don’t get dislodged easily.

    Bend the Solid Core Wire soldered to IKEA VINDRIKTNING Air Quality Sensor

  12. Test our handiwork with a Multimeter.

    (The UART Port runs at 5V, not 3.3V)

    UART Port of IKEA VINDRIKTNING Air Quality Sensor runs at 5V, not 3.3V

§9 Appendix: Test with Bus Pirate

Before testing with Apache NuttX OS, we sniffed the UART Port on IKEA VINDRIKTNING Air Quality Sensor with Bus Pirate.

Connect Bus Pirate to the IKEA Sensor as follows…

Bus PirateIKEA SensorWire Colour
Data In (MISO)RESTBlue
GNDGNDBlack

IKEA VINDRIKTNING Air Quality Sensor connected to Bus Pirate

Connect the USB Ports of the IKEA Sensor and Bus Pirate to the same computer. Remember: Only One Power Source for both gadgets!

Enter these Bus Pirate commands to capture the UART output from the IKEA Sensor (9600 bps, 8 bits, no parity, 1 stop bit)…

HiZ> m

1. HiZ
2. 1-WIRE
3. UART
4. I2C
5. SPI
6. 2WIRE
7. 3WIRE
8. KEYB
9. LCD
10. PIC
11. DIO
x. exit(without change)
(1)> 3

Set serial port speed: (bps)
 1. 300
 2. 1200
 3. 2400
 4. 4800
 5. 9600
 6. 19200
 7. 38400
 8. 57600
 9. 115200
10. Input Custom BAUD
11. Auto-Baud Detection (Activity Required)
(1)> 5

Data bits and parity:
 1. 8, NONE *default 
 2. 8, EVEN 
 3. 8, ODD 
 4. 9, NONE
(1)>

Stop bits:
 1. 1 *default
 2. 2
(1)>

Receive polarity:
 1. Idle 1 *default
 2. Idle 0
(1)>

Select output type:
 1. Open drain (H=Hi-Z, L=GND)
 2. Normal (H=3.3V, L=GND)
(1)>

Clutch disengaged!!!
To finish setup, start up the power supplies with command 'W'
Ready

UART> W
POWER SUPPLIES ON
Clutch engaged!!!

(Watch the demo on YouTube)

(More about Bus Pirate interfacing with UART)

To see the ASCII Output from the IKEA Sensor, enter this Bus Pirate command…

UART> (2)
Raw UART input
Any key to exit
<@:
   <B:
:;8
:;8
9:7 
997!
987"

(Watch the demo on YouTube)

(See the complete log)

To see the Binary Output from the IKEA Sensor, enter this…

UART> {
UART LIVE DISPLAY, } TO STOP

We should see the 20-byte Sensor Data Frames with PM 2.5 encoded inside…

Bus Pirate shows the output from IKEA VINDRIKTNING Air Quality Sensor

(See the complete log)

(Another binary log)

§10 Appendix: Build, Flash and Run NuttX

(For BL602, BL604 and ESP32)

Below are the steps to build, flash and run NuttX on BL602, BL604 and ESP32.

The instructions below will work on Linux (Ubuntu), WSL (Ubuntu) and macOS.

(Instructions for other platforms)

(See this for Arch Linux)

§10.1 Download NuttX

To use the IKEA Air Quality Sensor with NuttX, download the modified source code for NuttX OS and NuttX Apps…

mkdir nuttx
cd nuttx
git clone --recursive --branch ikea https://github.com/lupyuen/nuttx nuttx
git clone --recursive --branch ikea https://github.com/lupyuen/nuttx-apps apps

Or if we prefer to add the IKEA Air Quality Sensor App to our NuttX Project, follow these instructions…

(For PineDio Stack BL604: The app is already preinstalled)

§10.2 Configure NuttX

Now we configure our NuttX project…

  1. Install the build prerequisites…

    “Install Prerequisites”

  2. Configure the build…

    cd nuttx
    
    ## For BL602: Configure the build for BL602
    ./tools/configure.sh bl602evb:nsh
    
    ## For PineDio Stack BL604: Configure the build for BL604
    ./tools/configure.sh bl602evb:pinedio
    
    ## For ESP32: Configure the build for ESP32.
    ## TODO: Change "esp32-devkitc" to our ESP32 board.
    ./tools/configure.sh esp32-devkitc:nsh
    
    ## Edit the Build Config
    make menuconfig 
    
  3. Enable UART1…

    For BL602 / BL604: Check the box for “System Type” → “BL602 Peripheral Support” → “UART1”

    For ESP32: Check the box for “System Type” → “ESP32 Peripheral Select” → “UART 1”

    Hit “Exit” until the Top Menu appears. (“NuttX/x64_64 Configuration”)

    Enable UART1 and set to 9,600 bps

  4. Set UART1 to 9,600 bps…

    Select “Device Drivers” → “Serial Driver Support” → “UART1 Configuration”

    Set “BAUD rate” to 9600

    Hit “Exit” until the Top Menu appears. (“NuttX/x64_64 Configuration”)

  5. Enable cat and ls commands…

    Select “Application Configuration” → “NSH Library” → “Disable Individual commands”

    Uncheck “Disable cat”

    Uncheck “Disable ls”

    Hit “Exit” until the Top Menu appears. (“NuttX/x64_64 Configuration”)

  6. Enable Logging and Assertion Checks…

    Select “Build Setup” → “Debug Options”

    Check the boxes for the following…

    Enable Debug Features
    Enable Error Output
    Enable Warnings Output
    Enable Debug Assertions
    

    Hit “Exit” until the Top Menu appears. (“NuttX/x64_64 Configuration”)

  7. Save the configuration and exit menuconfig

    (See the .config for BL602 and BL604)

The IKEA Sensor will be connected to NuttX at /dev/ttyS1

§10.3 Build NuttX

Follow these steps to build NuttX for BL602, BL604 or ESP32…

  1. To build NuttX, enter this command…

    make
    
  2. We should see…

    LD: nuttx
    CP: nuttx.hex
    CP: nuttx.bin
    

    (See the complete log for BL602 / BL604)

  3. For WSL: Copy the NuttX Firmware to the c:\blflash directory in the Windows File System…

    ##  /mnt/c/blflash refers to c:\blflash in Windows
    mkdir /mnt/c/blflash
    cp nuttx.bin /mnt/c/blflash
    

    For WSL we need to run blflash under plain old Windows CMD (not WSL) because it needs to access the COM port.

  4. In case of problems, refer to the NuttX Docs…

    “BL602 / BL604 NuttX”

    “ESP32 NuttX”

    “Installing NuttX”

Building NuttX

§10.4 Flash NuttX

For ESP32: See instructions here (Also check out this article)

For BL602 / BL604: Follow these steps to install blflash…

  1. “Install rustup”

  2. “Download and build blflash”

We assume that our Firmware Binary File nuttx.bin has been copied to the blflash folder.

Set BL602 / BL604 to Flashing Mode and restart the board…

For PineDio Stack BL604:

  1. Set the GPIO 8 Jumper to High (Like this)

  2. Disconnect the USB cable and reconnect

    Or use the Improvised Reset Button (Here’s how)

For PineCone BL602:

  1. Set the PineCone Jumper (IO 8) to the H Position (Like this)

  2. Press the Reset Button

For BL10:

  1. Connect BL10 to the USB port

  2. Press and hold the D8 Button (GPIO 8)

  3. Press and release the EN Button (Reset)

  4. Release the D8 Button

For Ai-Thinker Ai-WB2, Pinenut and MagicHome BL602:

  1. Disconnect the board from the USB Port

  2. Connect GPIO 8 to 3.3V

  3. Reconnect the board to the USB port

Enter these commands to flash nuttx.bin to BL602 / BL604 over UART…

## For Linux: Change "/dev/ttyUSB0" to the BL602 / BL604 Serial Port
blflash flash nuttx.bin \
  --port /dev/ttyUSB0 

## For macOS: Change "/dev/tty.usbserial-1410" to the BL602 / BL604 Serial Port
blflash flash nuttx.bin \
  --port /dev/tty.usbserial-1410 \
  --initial-baud-rate 230400 \
  --baud-rate 230400

## For Windows: Change "COM5" to the BL602 / BL604 Serial Port
blflash flash c:\blflash\nuttx.bin --port COM5

(See the Output Log)

For WSL: Do this under plain old Windows CMD (not WSL) because blflash needs to access the COM port.

(Flashing WiFi apps to BL602 / BL604? Remember to use bl_rfbin)

(More details on flashing firmware)

Flashing NuttX

§10.5 Run NuttX

For ESP32: Use Picocom to connect to ESP32 over UART…

picocom -b 115200 /dev/ttyUSB0

(More about this)

For BL602 / BL604: Set BL602 / BL604 to Normal Mode (Non-Flashing) and restart the board…

For PineDio Stack BL604:

  1. Set the GPIO 8 Jumper to Low (Like this)

  2. Disconnect the USB cable and reconnect

    Or use the Improvised Reset Button (Here’s how)

For PineCone BL602:

  1. Set the PineCone Jumper (IO 8) to the L Position (Like this)

  2. Press the Reset Button

For BL10:

  1. Press and release the EN Button (Reset)

For Ai-Thinker Ai-WB2, Pinenut and MagicHome BL602:

  1. Disconnect the board from the USB Port

  2. Connect GPIO 8 to GND

  3. Reconnect the board to the USB port

After restarting, connect to BL602 / BL604’s UART Port at 2 Mbps like so…

For Linux:

screen /dev/ttyUSB0 2000000

For macOS: Use CoolTerm (See this)

For Windows: Use putty (See this)

Alternatively: Use the Web Serial Terminal (See this)

Press Enter to reveal the NuttX Shell…

NuttShell (NSH) NuttX-10.2.0-RC0
nsh>

Congratulations NuttX is now running on BL602 / BL604!

(More details on connecting to BL602 / BL604)

Running NuttX

macOS Tip: Here’s the script I use to build, flash and run NuttX on macOS, all in a single step: run.sh

Script to build, flash and run NuttX on macOS

(Source)

Trekking 13 km to IKEA on the horizon in search of VINDRIKTNING

Trekking 13 km to IKEA on the horizon in search of VINDRIKTNING