I'm trying to get the histogram data from the OPC-R2 Sensor from Alphasense.
Unfortunatelly there is no library for the OPC-R2 to just use with the Arduino Framework.
So I've written my own code to get the data with SPI Commands that are documented in the datasheet. The histogram data is 64 bytes long and I'm storing it in an unsigned char array.
The datatypes vary from float values occupying 4 bytes to unsigned 8bit integers occupying 1 byte and also unsigned 16bit integers occupying 2 bytes.
Im using pointers to store the values and print them to the serial monitor.
uint16_t *pUInt16;
float *pFloat;
The single byte 8bit integers Im printing directly without storing them.
The code is working fine with an Arduino UNO but as soon as I use the same code with the ESP32 I get too high values!?
Example output with ESP32:
16523,1660,312,2,0,0,0,0,0,0,0,0,0,0,0,0,0,38.33,0.00,0.00,0.00,4.400,25.6,30.9,0.289,141,0,145.865,164.662,164.698,27971
Checksum OK
Example output with Arduino UNO:
25970,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,56.67,0.00,0.00,0.00,4.500,25.2,29.8,0.285,1,0,0.245,0.299,0.299,59154
Checksum OK
The Datalabels are:
Time(ms),Bin00,Bin01,Bin02,Bin03,Bin04,Bin05,Bin06,Bin07,Bin08,Bin09,Bin10,Bin11,Bin12,Bin13,Bin14,Bin15,MToF Bin1,MToF
Bin3,MToF Bin5,MToF Bin7,SFR,Temp(C),RH(%),Sampling Period(s),Reject count Glitch,Reject count Long,PM_A(ug/m3),PM_B(ug/
m3),PM_C(ug/m3),Checksum
Especially the penultimate three values (PM1, PM2.5, PM10 values) and the first few Bins are way too high on the ESP32.
Here is an example of how I store the values inside the pointers:
port.print(F("M_B (Particle mass Concentration B),"));
pFloat = (float *)&SPI_in[13];
port.println(*pFloat, 2);
Does this have anything to do with the architecture of the processors? (UNO=8bit esp32=32bit)
My Code is on Github: