Hi! Thanks for the response!
The hardware is an MH-SD Card Module.
I used the SPI and SD library following this tutorial :
https://randomnerdtutorials.com/guide-to-sd-card-module-with-arduino/.
The problem that i found is to identify the target variables to “print” on the dataFile into the codification of the PM2.5 sensor:
#include “Seeed_HM330X.h”
#ifdef ARDUINO_SAMD_VARIANT_COMPLIANCE
#define SERIAL SerialUSB
#else
#define SERIAL 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): ",
};
err_t print_result(const char* str,u16 value)
{
if(NULL==str)
return ERROR_PARAM;
SERIAL.print(str);
SERIAL.println(value);
return NO_ERROR;
}
/parse buf with 29 u8-data/
err_t parse_result(u8 *data)
{
u16 value=0;
err_t NO_ERROR;
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);
}
}
err_t parse_result_value(u8 *data)
{
if(NULL==data)
return ERROR_PARAM;
for(int i=0;i<28;i++)
{
SERIAL.print(data[i],HEX);
SERIAL.print(" “);
if((0==(i)%5)||(0==i))
{
SERIAL.println(” “);
}
}
u8 sum=0;
for(int i=0;i<28;i++)
{
sum+=data[i];
}
if(sum!=data[28])
{
SERIAL.println(“wrong checkSum!!!”);
}
SERIAL.println(” “);
SERIAL.println(” ");
return NO_ERROR;
}
/30s/
void setup()
{
SERIAL.begin(115200);
delay(100);
SERIAL.println(“Serial start”);
if(sensor.init())
{
SERIAL.println(“HM330X init failed!!!”);
while(1);
}
}
void loop()
{
if(sensor.read_sensor_value(buf,29))
{
SERIAL.println(“HM330X read result failed!!!”);
}
parse_result_value(buf);
parse_result(buf);
SERIAL.println(" “);
SERIAL.println(” “);
SERIAL.println(” ");
delay(5000);
}