Hi @roboteer Many thanks for your clear explanation of the serial port configuration. It entirely solved my confusion on this. I also modified my code as you suggested. However, I still have this issue.
My code is like below:
//Adafruit section
#include <Wire.h>
#include “Adafruit_MPRLS.h”
#define RESET_PIN -1 // set to any GPIO pin # to hard-reset on begin()
#define EOC_PIN -1 // set to any GPIO pin to read end-of-conversion by pin
Adafruit_MPRLS mpr = Adafruit_MPRLS(RESET_PIN, EOC_PIN);
#include <RC100.h>
RC100 Controller;
uint16_t RcvData = 0;
#include <Dynamixel2Arduino.h>
// Please modify it to suit your hardware.
#if defined(ARDUINO_AVR_UNO) || defined(ARDUINO_AVR_MEGA2560) // When using DynamixelShield
#include <SoftwareSerial.h>
SoftwareSerial soft_serial(7, 8); // DYNAMIXELShield UART RX/TX
#define DXL_SERIAL Serial
#define DEBUG_SERIAL soft_serial
const int DXL_DIR_PIN = 2; // DYNAMIXEL Shield DIR PIN
#elif defined(ARDUINO_OpenRB) // When using OpenRB-150
//OpenRB does not require the DIR control pin.
#define DXL_SERIAL Serial1
#define DEBUG_SERIAL Serial
// const int DXL_DIR_PIN = -1;
const int DXL_DIR_PIN = 5;
#else // Other boards when using DynamixelShield
#define DXL_SERIAL Serial1
#define DEBUG_SERIAL Serial
const int DXL_DIR_PIN = 2; // DYNAMIXEL Shield DIR PIN
#endif
Dynamixel2Arduino dxl(DXL_SERIAL, DXL_DIR_PIN);
using namespace ControlTableItem;
const float DXL_PROTOCOL_VERSION = 2.0;
const uint8_t gr_ID = 1;
const uint8_t rt_ID = 2;
const uint8_t df_ID = 3;
const uint8_t fd_ID = 4;
double gr_CP, gr_DP, gr_initial, rt_CP, rt_DP, rt_initial, df_CP, df_DP, df_initial, fd_CP, fd_DP, fd_initial;
void setup(){
//Adafruit section
Serial.begin(115200);
Serial.println(“MPRLS Simple Test”);
if (! mpr.begin()) {
Serial.println(“Failed to communicate with MPRLS sensor, check wiring?”);
while (1) {
delay(10);
}
}
Serial.println(“Found MPRLS sensor”);
Controller.begin(2);
// Set Port baudrate to 57600bps. This has to match with DYNAMIXEL baudrate.
dxl.begin(57600);
dxl.setPortProtocolVersion(DXL_PROTOCOL_VERSION);
// Get DYNAMIXEL information
dxl.ping(gr_ID);
dxl.ping(rt_ID);
dxl.ping(df_ID);
dxl.ping(fd_ID);
// Turn off torque when configuring items in EEPROM area, set PWM mode
dxl.torqueOff(gr_ID);
dxl.setOperatingMode(gr_ID, OP_EXTENDED_POSITION);
dxl.torqueOn(gr_ID);
dxl.writeControlTableItem(PROFILE_VELOCITY, gr_ID, 50);
dxl.torqueOff(rt_ID);
dxl.setOperatingMode(rt_ID, OP_POSITION);//limit rotation angle
dxl.torqueOn(rt_ID);
dxl.writeControlTableItem(PROFILE_VELOCITY, rt_ID, 50);
dxl.torqueOff(df_ID);
dxl.setOperatingMode(df_ID, OP_EXTENDED_POSITION);
dxl.torqueOn(df_ID);
dxl.writeControlTableItem(PROFILE_VELOCITY, df_ID, 50);
dxl.torqueOff(fd_ID);
dxl.setOperatingMode(fd_ID, OP_EXTENDED_POSITION);
dxl.torqueOn(fd_ID);
dxl.writeControlTableItem(PROFILE_VELOCITY, fd_ID, 50);
}
void loop(){
// MPRLS section
float pressure_hPa = mpr.readPressure();
Serial.print("Pressure (hPa): "); Serial.println(pressure_hPa/10);
delay(50);
RcvData = 0;
if (Controller.available()){
RcvData = Controller.readData();
}
if(RcvData == (RC100_BTN_L)){
gr_CP = dxl.getPresentPosition(gr_ID, UNIT_DEGREE);
gr_DP = gr_CP + 5;
dxl.setGoalPosition(gr_ID, gr_DP, UNIT_DEGREE);
}
if(RcvData == (RC100_BTN_R)){
gr_CP = dxl.getPresentPosition(gr_ID, UNIT_DEGREE);
gr_DP = gr_CP - 5;
dxl.setGoalPosition(gr_ID, gr_DP, UNIT_DEGREE);
}
if(RcvData == (RC100_BTN_1)){
df_CP = dxl.getPresentPosition(df_ID, UNIT_DEGREE);
df_DP = df_CP + 5;
dxl.setGoalPosition(df_ID, df_DP, UNIT_DEGREE);
}
if(RcvData == (RC100_BTN_3)){
df_CP = dxl.getPresentPosition(df_ID, UNIT_DEGREE);
df_DP = df_CP - 5;
dxl.setGoalPosition(df_ID, df_DP, UNIT_DEGREE);
}
}
The baud rates of these actuators are all set as 57600.
-
When I comment the Adafruit section in both void setup() and void loop(), my RC100 controller can control all actuators successfully via BT210 assembled on the OpenRB150;
-
When I comment the Adafruit section in only the void loop(), it still works but the serial port displays nothing;
-
When I keep the Adafruit section in both void setup() and void loop(), the actuators can not be controlled via BT210 but the serial port displays sensor data successfully;
It looks like something conflicts between the two, but not the serial port setup? What do you think about this?