Alternative to SerialEvent1()?


I am currently trying to read off a sensor (LPMS-ME1), an accelerometer that uses UART to send data to an Arduino Portenta H7, using the M7 core through serial communication.

The code below works perfectly on an Arduino Due and an Arduino Mega, but it does not work with the Portenta H7 because the Portenta does not support the *SerialEvent1()*function -- nor any of the SerialEvent#() functions. Is there a workaround without using the SerialEvent1() function?

I tried putting everything inside the SerialEvent1() function into void loop but it just completely froze the IDE -- and did not produce an error message. Additionally, I verified that I am using the correct TX & RX pins, and have previously established serial communication with the Portenta.

Any suggestion are appreciated,

  Code to test getting data from the LPMS-ME1 IMU sensor

  Modified from:

  Written by Cole

char inputdata[66];// reserve 66 bytes for the input data as a default message length is 66 bytes
bool dataComplete = false;  // whether the string is complete
union accZBytes {
  byte data[4];
  float fval;
} accZ;
union accYBytes {
  byte data[4];
  float fval;
} accY;
union accXBytes {
  byte data[4];
  float fval;
} accX;
float accZf;
float accYf;
float accXf;
float accMag;
int dataIter = 0;

void setup() {
  // initialize serial:
  Serial1.begin(19200); // Default datarate of LPMS sensor is 115200 from PC/USB testing
  // Prep LEDs

void loop() {
  // print the string when a newline arrives:
  if (dataComplete) {
    // Serial.println(inputString);
    // Parse the input data (just yoink the z acceleration for now)[0] = inputdata[31];[1] = inputdata[32];[2] = inputdata[33];[3] = inputdata[34];[0] = inputdata[27];[1] = inputdata[28];[2] = inputdata[29];[3] = inputdata[30];[0] = inputdata[23];[1] = inputdata[24];[2] = inputdata[25];[3] = inputdata[26];
    accZf = accZ.fval;
    accYf = accY.fval;
    accXf = accX.fval;
    accMag = sqrt(sq(accZf) + sq(accYf) + sq(accXf));
    // Print the resulting acceleration to the serial monitor
    Serial.print("Acceleration is: [");
    Serial.print("Magnitude : ");
    // clear the string:
    dataIter = 0;
    dataComplete = false;

  SerialEvent occurs whenever a new data comes in the hardware serial RX. This
  routine is run between each time loop() runs, so using delay inside loop can
  delay response. Multiple bytes of data may be available.
void serialEvent1() {
  if (Serial1.available()) {
    // get the new byte:
    char inChar = (char);
    // add it to the inputString:
    inputdata[dataIter] = inChar;
    // if the packet is done, reset
    if (inChar == '\n') { // \n is 0x0A, the temination character for the data packet
      dataComplete = true;
      dataIter = 0;

When did the IDE freeze? Was it during compilation, or during upload, or after upload when you had Serial Monitor open, or some other time???

It froze right after it finished compiling and when it was uploading to the Portenta

Can you post that code?

It's already posted on the topic

Hello, Patoz
Did you solve the communication with LPMS-ME1?

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