HM330X Sensor, Grove "Example" failure

Hardware:
--Arduino Due (genuine)
--Seeed HM330X sensor board for PM2.5

Seems to be straightforward, but nooooooo.....!

When I ran the supplied Example sketch, I get this error (which I cannot interpret)
(I just downloaded the Seeed/Grove HM330X Library today, which includes the problematic Example,

/*
 * basic_demo.ino
 * Example for Seeed PM2.5 Sensor(HM300)
 *
 * Copyright (c) 2018 Seeed Technology Co., Ltd.
 * Website    : www.seeed.cc
 * Author     : downey
 * Create Time: August 2018
 * Change Log :
 *
 * The MIT License (MIT)
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 * THE SOFTWARE.
 */

#include "Seeed_HM330X.h"

#ifdef  ARDUINO_SAMD_VARIANT_COMPLIANCE
#define SERIAL_OUTPUT SerialUSB
#else
#define SERIAL_OUTPUT Serial
#endif


HM330X sensor;
u8 buf[30];


const char *str[]={"sensor num: ","PM1.0 concentration(CF=1,Standard particulate matter,unit:ug/m3): ",
                   "PM2.5 concentration(CF=1,Standard particulate matter,unit:ug/m3): ",
                   "PM10 concentration(CF=1,Standard particulate matter,unit:ug/m3): ",
                   "PM1.0 concentration(Atmospheric environment,unit:ug/m3): ",
                   "PM2.5 concentration(Atmospheric environment,unit:ug/m3): ",
                   "PM10 concentration(Atmospheric environment,unit:ug/m3): ",
};

HM330XErrorCode print_result(const char* str,u16 value)
{
    if(NULL==str)
        return ERROR_PARAM;
    SERIAL_OUTPUT.print(str);
    SERIAL_OUTPUT.println(value);
    return NO_ERROR;
}

/*parse buf with 29 u8-data*/
HM330XErrorCode parse_result(u8 *data)
{
    u16 value=0;
    if(NULL==data)
        return ERROR_PARAM;
    for(int i=1;i<8;i++)
    {
        value = (u16)data[i*2]<<8|data[i*2+1];
        print_result(str[i-1],value);

    }

    return NO_ERROR;
}

HM330XErrorCode parse_result_value(u8 *data)
{
    if(NULL==data)
        return ERROR_PARAM;
    for(int i=0;i<28;i++)
    {
        SERIAL_OUTPUT.print(data[i],HEX);
        SERIAL_OUTPUT.print("  ");
        if((0==(i)%5)||(0==i))
        {
            SERIAL_OUTPUT.println(" ");
        }
    }
    u8 sum=0;
    for(int i=0;i<28;i++)
    {
        sum+=data[i];
    }
    if(sum!=data[28])
    {
        SERIAL_OUTPUT.println("wrong checkSum!!!!");
    }
    SERIAL_OUTPUT.println(" ");
    SERIAL_OUTPUT.println(" ");
    return NO_ERROR;
}


/*30s*/
void setup()
{
    SERIAL_OUTPUT.begin(115200);
    delay(100);
    SERIAL_OUTPUT.println("Serial start");
    if(sensor.init())
    {
        SERIAL_OUTPUT.println("HM330X init failed!!!");
        while(1);
    }

}



void loop()
{
    if(sensor.read_sensor_value(buf,29))
    {
        SERIAL_OUTPUT.println("HM330X read result failed!!!");
    }
    parse_result_value(buf);
    parse_result(buf);
    SERIAL_OUTPUT.println(" ");
    SERIAL_OUTPUT.println(" ");
    SERIAL_OUTPUT.println(" ");
    delay(5000);
}


*In file included from /tmp/.arduinoIDE-unsaved20241120-5918-11vhycz.0p09/basic_demo/basic_demo.ino:32:0:*
*/home/mikegee/Arduino/libraries/Grove_-_Laser_PM2.5_Sensor_HM3301/Seeed_HM330X.h:77:58: error: 'u32' has not been declared*
*     HM330XErrorCode IIC_read_bytes(u8 start_reg,u8 *data,u32 data_len);*
*                                                          ^*
*/home/mikegee/Arduino/libraries/Grove_-_Laser_PM2.5_Sensor_HM3301/Seeed_HM330X.h:91:48: error: 'u32' has not been declared*
*     HM330XErrorCode read_sensor_value(u8 *data,u32 data_len);*
*                                                ^*
*/tmp/.arduinoIDE-unsaved20241120-5918-11vhycz.0p09/basic_demo/basic_demo.ino:43:1: error: declaration does not declare anything [-fpermissive]*
* *
* ^*

*exit status 1*

*Compilation error: declaration does not declare anything [-fpermissive]*

I would guess your processor does not support u32 and the compiler knows that.

You should. Why make us go track it down? You're the one asking for free help.

Also, include the complete compilation results from the IDE, not just the section you think is important.

That IS the complete compilation result.
I've added the "Example" sketch. I figured that anybody who might reply, is already familiar with the Seeed library and its example file, and would have it on their computer. I am not trying to make things difficult for anybody.

Please elaborate on what "u32" means in this context. Is there a work-around? Supposedly this Seeed sensor board will work on a Uno, so the Due should be powerful enough to perform the tasks. Or perhaps that is a naiive assumption.

Perhaps you selected the wrong board definition in the Arduino IDE. In any case, you don't have all the definitions required by that code.

Go through the Getting Started guide for that sensor and follow all the steps very carefully.

"u32" is shorthand for unsigned long integer (32 bits), defined elsewhere as uint32_t.

There is definitely more, that doesn't even show the targe board. Did you scroll up in the window? There's an IDE option to copy the entire error message. On IDE v.1.8.x, it's as shown in the picture below. It may be in a different place on v2.x. Also, go into preferences and set the compilation logging to "Verbose". Then we'll be able to see all the files being compiled (including libraries).

I am using the ide v2.3.4
I was unaware of the verbose option.
I had previously used the "copy compilation error message" function, but as the IDE was not set to "verbose mode", I only posted what I saw. Here is the "verbose" version, thanks...

loading library from /home/mikegee/Arduino/libraries/FunctionGenerator: invalid library: no header files foundloading library from /home/mikegee/Arduino/libraries/newLCD: invalid library: no header files found
FQBN: arduino:sam:arduino_due_x_dbg
Using board 'arduino_due_x_dbg' from platform in folder: /home/mikegee/.arduino15/packages/arduino/hardware/sam/1.6.12
Using core 'arduino' from platform in folder: /home/mikegee/.arduino15/packages/arduino/hardware/sam/1.6.12

Detecting libraries used...
/home/mikegee/.arduino15/packages/arduino/tools/arm-none-eabi-gcc/4.8.3-2014q1/bin/arm-none-eabi-g++ -c -g -Os -w -std=gnu++11 -ffunction-sections -fdata-sections -nostdlib -fno-threadsafe-statics --param max-inline-insns-single=500 -fno-rtti -fno-exceptions -w -x c++ -E -CC -mcpu=cortex-m3 -mthumb -DF_CPU=84000000L -DARDUINO=10607 -DARDUINO_SAM_DUE -DARDUINO_ARCH_SAM -D__SAM3X8E__ -mthumb -DUSB_VID=0x2341 -DUSB_PID=0x003e -DUSBCON -DUSB_MANUFACTURER="Arduino LLC" -DUSB_PRODUCT="Arduino Due" -I/home/mikegee/.arduino15/packages/arduino/hardware/sam/1.6.12/system/libsam -I/home/mikegee/.arduino15/packages/arduino/hardware/sam/1.6.12/system/CMSIS/CMSIS/Include/ -I/home/mikegee/.arduino15/packages/arduino/hardware/sam/1.6.12/system/CMSIS/Device/ATMEL/ -I/home/mikegee/.arduino15/packages/arduino/hardware/sam/1.6.12/cores/arduino -I/home/mikegee/.arduino15/packages/arduino/hardware/sam/1.6.12/variants/arduino_due_x /home/mikegee/.cache/arduino/sketches/6EFB50A201FBCB1F7BE3A280AC07A749/sketch/basic_demo.ino.cpp -o /dev/null
Alternatives for Seeed_HM330X.h: [Grove - Laser PM2.5 Sensor HM3301@1.0.2]
ResolveLibrary(Seeed_HM330X.h)
  -> candidates: [Grove - Laser PM2.5 Sensor HM3301@1.0.2]
/home/mikegee/.arduino15/packages/arduino/tools/arm-none-eabi-gcc/4.8.3-2014q1/bin/arm-none-eabi-g++ -c -g -Os -w -std=gnu++11 -ffunction-sections -fdata-sections -nostdlib -fno-threadsafe-statics --param max-inline-insns-single=500 -fno-rtti -fno-exceptions -w -x c++ -E -CC -mcpu=cortex-m3 -mthumb -DF_CPU=84000000L -DARDUINO=10607 -DARDUINO_SAM_DUE -DARDUINO_ARCH_SAM -D__SAM3X8E__ -mthumb -DUSB_VID=0x2341 -DUSB_PID=0x003e -DUSBCON -DUSB_MANUFACTURER="Arduino LLC" -DUSB_PRODUCT="Arduino Due" -I/home/mikegee/.arduino15/packages/arduino/hardware/sam/1.6.12/system/libsam -I/home/mikegee/.arduino15/packages/arduino/hardware/sam/1.6.12/system/CMSIS/CMSIS/Include/ -I/home/mikegee/.arduino15/packages/arduino/hardware/sam/1.6.12/system/CMSIS/Device/ATMEL/ -I/home/mikegee/.arduino15/packages/arduino/hardware/sam/1.6.12/cores/arduino -I/home/mikegee/.arduino15/packages/arduino/hardware/sam/1.6.12/variants/arduino_due_x -I/home/mikegee/Arduino/libraries/Grove_-_Laser_PM2.5_Sensor_HM3301 /home/mikegee/.cache/arduino/sketches/6EFB50A201FBCB1F7BE3A280AC07A749/sketch/basic_demo.ino.cpp -o /dev/null
Alternatives for Wire.h: [Wire@1.0]
ResolveLibrary(Wire.h)
  -> candidates: [Wire@1.0]
/home/mikegee/.arduino15/packages/arduino/tools/arm-none-eabi-gcc/4.8.3-2014q1/bin/arm-none-eabi-g++ -c -g -Os -w -std=gnu++11 -ffunction-sections -fdata-sections -nostdlib -fno-threadsafe-statics --param max-inline-insns-single=500 -fno-rtti -fno-exceptions -w -x c++ -E -CC -mcpu=cortex-m3 -mthumb -DF_CPU=84000000L -DARDUINO=10607 -DARDUINO_SAM_DUE -DARDUINO_ARCH_SAM -D__SAM3X8E__ -mthumb -DUSB_VID=0x2341 -DUSB_PID=0x003e -DUSBCON -DUSB_MANUFACTURER="Arduino LLC" -DUSB_PRODUCT="Arduino Due" -I/home/mikegee/.arduino15/packages/arduino/hardware/sam/1.6.12/system/libsam -I/home/mikegee/.arduino15/packages/arduino/hardware/sam/1.6.12/system/CMSIS/CMSIS/Include/ -I/home/mikegee/.arduino15/packages/arduino/hardware/sam/1.6.12/system/CMSIS/Device/ATMEL/ -I/home/mikegee/.arduino15/packages/arduino/hardware/sam/1.6.12/cores/arduino -I/home/mikegee/.arduino15/packages/arduino/hardware/sam/1.6.12/variants/arduino_due_x -I/home/mikegee/Arduino/libraries/Grove_-_Laser_PM2.5_Sensor_HM3301 -I/home/mikegee/.arduino15/packages/arduino/hardware/sam/1.6.12/libraries/Wire/src /home/mikegee/.cache/arduino/sketches/6EFB50A201FBCB1F7BE3A280AC07A749/sketch/basic_demo.ino.cpp -o /dev/null
/home/mikegee/.arduino15/packages/arduino/tools/arm-none-eabi-gcc/4.8.3-2014q1/bin/arm-none-eabi-g++ -c -g -Os -w -std=gnu++11 -ffunction-sections -fdata-sections -nostdlib -fno-threadsafe-statics --param max-inline-insns-single=500 -fno-rtti -fno-exceptions -w -x c++ -E -CC -mcpu=cortex-m3 -mthumb -DF_CPU=84000000L -DARDUINO=10607 -DARDUINO_SAM_DUE -DARDUINO_ARCH_SAM -D__SAM3X8E__ -mthumb -DUSB_VID=0x2341 -DUSB_PID=0x003e -DUSBCON -DUSB_MANUFACTURER="Arduino LLC" -DUSB_PRODUCT="Arduino Due" -I/home/mikegee/.arduino15/packages/arduino/hardware/sam/1.6.12/system/libsam -I/home/mikegee/.arduino15/packages/arduino/hardware/sam/1.6.12/system/CMSIS/CMSIS/Include/ -I/home/mikegee/.arduino15/packages/arduino/hardware/sam/1.6.12/system/CMSIS/Device/ATMEL/ -I/home/mikegee/.arduino15/packages/arduino/hardware/sam/1.6.12/cores/arduino -I/home/mikegee/.arduino15/packages/arduino/hardware/sam/1.6.12/variants/arduino_due_x -I/home/mikegee/Arduino/libraries/Grove_-_Laser_PM2.5_Sensor_HM3301 -I/home/mikegee/.arduino15/packages/arduino/hardware/sam/1.6.12/libraries/Wire/src /home/mikegee/Arduino/libraries/Grove_-_Laser_PM2.5_Sensor_HM3301/Seeed_HM330X.cpp -o /dev/null
/home/mikegee/.arduino15/packages/arduino/tools/arm-none-eabi-gcc/4.8.3-2014q1/bin/arm-none-eabi-g++ -c -g -Os -w -std=gnu++11 -ffunction-sections -fdata-sections -nostdlib -fno-threadsafe-statics --param max-inline-insns-single=500 -fno-rtti -fno-exceptions -w -x c++ -E -CC -mcpu=cortex-m3 -mthumb -DF_CPU=84000000L -DARDUINO=10607 -DARDUINO_SAM_DUE -DARDUINO_ARCH_SAM -D__SAM3X8E__ -mthumb -DUSB_VID=0x2341 -DUSB_PID=0x003e -DUSBCON -DUSB_MANUFACTURER="Arduino LLC" -DUSB_PRODUCT="Arduino Due" -I/home/mikegee/.arduino15/packages/arduino/hardware/sam/1.6.12/system/libsam -I/home/mikegee/.arduino15/packages/arduino/hardware/sam/1.6.12/system/CMSIS/CMSIS/Include/ -I/home/mikegee/.arduino15/packages/arduino/hardware/sam/1.6.12/system/CMSIS/Device/ATMEL/ -I/home/mikegee/.arduino15/packages/arduino/hardware/sam/1.6.12/cores/arduino -I/home/mikegee/.arduino15/packages/arduino/hardware/sam/1.6.12/variants/arduino_due_x -I/home/mikegee/Arduino/libraries/Grove_-_Laser_PM2.5_Sensor_HM3301 -I/home/mikegee/.arduino15/packages/arduino/hardware/sam/1.6.12/libraries/Wire/src /home/mikegee/.arduino15/packages/arduino/hardware/sam/1.6.12/libraries/Wire/src/Wire.cpp -o /dev/null
Generating function prototypes...
/home/mikegee/.arduino15/packages/arduino/tools/arm-none-eabi-gcc/4.8.3-2014q1/bin/arm-none-eabi-g++ -c -g -Os -w -std=gnu++11 -ffunction-sections -fdata-sections -nostdlib -fno-threadsafe-statics --param max-inline-insns-single=500 -fno-rtti -fno-exceptions -w -x c++ -E -CC -mcpu=cortex-m3 -mthumb -DF_CPU=84000000L -DARDUINO=10607 -DARDUINO_SAM_DUE -DARDUINO_ARCH_SAM -D__SAM3X8E__ -mthumb -DUSB_VID=0x2341 -DUSB_PID=0x003e -DUSBCON -DUSB_MANUFACTURER="Arduino LLC" -DUSB_PRODUCT="Arduino Due" -I/home/mikegee/.arduino15/packages/arduino/hardware/sam/1.6.12/system/libsam -I/home/mikegee/.arduino15/packages/arduino/hardware/sam/1.6.12/system/CMSIS/CMSIS/Include/ -I/home/mikegee/.arduino15/packages/arduino/hardware/sam/1.6.12/system/CMSIS/Device/ATMEL/ -I/home/mikegee/.arduino15/packages/arduino/hardware/sam/1.6.12/cores/arduino -I/home/mikegee/.arduino15/packages/arduino/hardware/sam/1.6.12/variants/arduino_due_x -I/home/mikegee/Arduino/libraries/Grove_-_Laser_PM2.5_Sensor_HM3301 -I/home/mikegee/.arduino15/packages/arduino/hardware/sam/1.6.12/libraries/Wire/src /home/mikegee/.cache/arduino/sketches/6EFB50A201FBCB1F7BE3A280AC07A749/sketch/basic_demo.ino.cpp -o /tmp/3165867850/sketch_merged.cpp
/home/mikegee/.arduino15/packages/builtin/tools/ctags/5.8-arduino11/ctags -u --language-force=c++ -f - --c++-kinds=svpf --fields=KSTtzns --line-directives /tmp/3165867850/sketch_merged.cpp
Compiling sketch...
/home/mikegee/.arduino15/packages/arduino/tools/arm-none-eabi-gcc/4.8.3-2014q1/bin/arm-none-eabi-g++ -c -g -Os -w -std=gnu++11 -ffunction-sections -fdata-sections -nostdlib -fno-threadsafe-statics --param max-inline-insns-single=500 -fno-rtti -fno-exceptions -MMD -mcpu=cortex-m3 -mthumb -DF_CPU=84000000L -DARDUINO=10607 -DARDUINO_SAM_DUE -DARDUINO_ARCH_SAM -D__SAM3X8E__ -mthumb -DUSB_VID=0x2341 -DUSB_PID=0x003e -DUSBCON "-DUSB_MANUFACTURER=\"Arduino LLC\"" "-DUSB_PRODUCT=\"Arduino Due\"" -I/home/mikegee/.arduino15/packages/arduino/hardware/sam/1.6.12/system/libsam -I/home/mikegee/.arduino15/packages/arduino/hardware/sam/1.6.12/system/CMSIS/CMSIS/Include/ -I/home/mikegee/.arduino15/packages/arduino/hardware/sam/1.6.12/system/CMSIS/Device/ATMEL/ -I/home/mikegee/.arduino15/packages/arduino/hardware/sam/1.6.12/cores/arduino -I/home/mikegee/.arduino15/packages/arduino/hardware/sam/1.6.12/variants/arduino_due_x -I/home/mikegee/Arduino/libraries/Grove_-_Laser_PM2.5_Sensor_HM3301 -I/home/mikegee/.arduino15/packages/arduino/hardware/sam/1.6.12/libraries/Wire/src /home/mikegee/.cache/arduino/sketches/6EFB50A201FBCB1F7BE3A280AC07A749/sketch/basic_demo.ino.cpp -o /home/mikegee/.cache/arduino/sketches/6EFB50A201FBCB1F7BE3A280AC07A749/sketch/basic_demo.ino.cpp.o
In file included from /tmp/.arduinoIDE-unsaved20241120-5918-ajpmjn.sp4e5/basic_demo/basic_demo.ino:32:0:
/home/mikegee/Arduino/libraries/Grove_-_Laser_PM2.5_Sensor_HM3301/Seeed_HM330X.h:77:58: error: 'u32' has not been declared
     HM330XErrorCode IIC_read_bytes(u8 start_reg,u8 *data,u32 data_len);
                                                          ^
/home/mikegee/Arduino/libraries/Grove_-_Laser_PM2.5_Sensor_HM3301/Seeed_HM330X.h:91:48: error: 'u32' has not been declared
     HM330XErrorCode read_sensor_value(u8 *data,u32 data_len);
                                                ^

Using library Grove - Laser PM2.5 Sensor HM3301 at version 1.0.2 in folder: /home/mikegee/Arduino/libraries/Grove_-_Laser_PM2.5_Sensor_HM3301 
Using library Wire at version 1.0 in folder: /home/mikegee/.arduino15/packages/arduino/hardware/sam/1.6.12/libraries/Wire 
exit status 1

Compilation error: exit status 1

So looking in "Seeed_HM330X.h", I see that the u32 type is only defined for AVR Architectures (which the Due is not):

#if defined(__AVR__)
typedef long unsigned int u32;
#endif
typedef int s32;
typedef unsigned char u8;
typedef unsigned short u16;

It seems very odd that the other types (s32, u8, u16) are defined for all architectures. I have no idea why the library's author chose to do that or what they expect to happen on non-AVR architectures. You might try entering a GitHub issue for this. But, looking at the dates there, I wonder if it's being actively supported.

I did get it to compile for the Due by commenting out the conditional compilation. Whether or not it will work is a different question ....

//#if defined(__AVR__)
typedef long unsigned int u32;
//#endif
typedef int s32;
typedef unsigned char u8;
typedef unsigned short u16;

It seems that you compiled unsaved sketch:

I have encountered several times that saved and temporary projects compile differently.
Try saving the example under a new name before compiling

Brilliant! I changed the lines of code in "SeedHM330X.h", and ran the file, and seems to work without any problems now.
Thanks for all your help.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.