Example Code for Arduino-UART Communication

Last revision 2026/01/08

The article provides a comprehensive guide on setting up UART communication using Arduino with Beetle RP2350 and GR10-30 gesture sensor, including hardware requirements, software setup, wiring diagram, and sample code for effective communication integration.

Hardware Preparation

Software Preparation

Wiring Diagram

Connection

Mainboard Pin name Module Pin name
Beetle RP2350 GND Analog Angle Sensor GND
Beetle RP2350 3V3 Analog Angle Sensor VCC
Beetle RP2350 8 Analog Angle Sensor RX
Beetle RP2350 9 SIM7600G 4G Module TX

Sample Code

#include "DFRobot_GR10_30.h"

DFRobot_GR10_30 gr10_30(GR10_30_DEVICE_ADDR, &Serial2);

void setup() {
  Serial2.begin(9600);
  Serial.begin(115200);
  
  while(gr10_30.begin() != 0){
    Serial.println(" Sensor initialize failed!!");
    delay(1000);
  }
  
  Serial.println(" Sensor  initialize success!!");
  gr10_30.enGestures(GESTURE_UP|GESTURE_DOWN|GESTURE_LEFT|GESTURE_RIGHT|GESTURE_FORWARD|GESTURE_BACKWARD|GESTURE_CLOCKWISE|GESTURE_COUNTERCLOCKWISE|GESTURE_CLOCKWISE_C|GESTURE_COUNTERCLOCKWISE_C);
}

void loop() {
  if(gr10_30.getDataReady()){
    uint16_t  gestures = gr10_30.getGesturesState();
    if(gestures&GESTURE_UP){
      Serial.println("Up");
    }
    if(gestures&GESTURE_DOWN){
      Serial.println("Down");
    }
    if(gestures&GESTURE_LEFT){
      Serial.println("Left");
    }
    if(gestures&GESTURE_RIGHT){
      Serial.println("Right");
    }
    if(gestures&GESTURE_FORWARD){
      Serial.println("Forward");
    }
    if(gestures&GESTURE_BACKWARD){
      Serial.println("Backward");
    }
    if(gestures&GESTURE_CLOCKWISE){
      Serial.println("Clockwise");
    }
    if(gestures&GESTURE_COUNTERCLOCKWISE){
      Serial.println("Contrarotate");
    }
    if(gestures&GESTURE_CLOCKWISE_C){
      Serial.println("Continuous clockwise");
    }
    if(gestures&GESTURE_COUNTERCLOCKWISE_C){
      Serial.println("Continuous counterclockwise");
    }
  }
  delay(1);
}

Result

Open the Arduino IDE serial monitor, the monitor window correctly printed out the sensor data.

Additional Information

In the Arduino development environment, the Beetle RP2350 defaults to 2 sets of UART communication interfaces: UART1, UART2

The following is the definition of the UART interface in the RP2350:

#define PIN_SERIAL1_TX (0u)
#define PIN_SERIAL1_RX (1u)

#define PIN_SERIAL2_TX (8u)
#define PIN_SERIAL2_RX (9u)

Was this article helpful?

TOP