Forum >SOLVED : ROMEO BLE MINI coding problem
RoboticsGeneral

SOLVED : ROMEO BLE MINI coding problem

userHead Ghedjati Nabil 2016-09-03 07:53:17 4160 Views3 Replies
Hi everyone, sorry for my english :)

I'm using a Romeo BLE mini board (SKU:DFR0351) and a MPU-6050 (accelerometer + gyro + temperature sensor) built on a GY-521 board, both inside a spherical robot toy. I want the arduino to execute some code (actionning the motors) when the rotation speed exceeds a specific value. The sensor is linked through the i2C interface.

I use this sketch :
('', '
#include <Wire.h>

#include <Romeo_m.h>
const int MPU_addr=0x68; // I2C address of the MPU-6050
int16_t AcX,AcY,Tmp,AcZ,GyX,GyY,GyZ;
void setup(void)
{
Wire.begin();
Wire.beginTransmission(MPU_addr);
Wire.write(0x6B); // PWR_MGMT_1 register
Wire.write(0); // set to zero (wakes up the MPU-6050)
Wire.endTransmission(true);
Romeo_m.Initialise();
Serial.begin(9600); //Set Serial Baud
}
void loop(void)
{
Wire.beginTransmission(MPU_addr);
Wire.write(0x3B); // starting with register 0x3B (ACCEL_XOUT_H)
Wire.endTransmission(false);
Wire.requestFrom(MPU_addr,14,true); // request a total of 14 registers
AcX=Wire.read()<<8|Wire.read(); // 0x3B (ACCEL_XOUT_H) & 0x3C (ACCEL_XOUT_L)
AcY=Wire.read()<<8|Wire.read(); // 0x3D (ACCEL_YOUT_H) & 0x3E (ACCEL_YOUT_L)
AcZ=Wire.read()<<8|Wire.read(); // 0x3F (ACCEL_ZOUT_H) & 0x40 (ACCEL_ZOUT_L)
Tmp=Wire.read()<<8|Wire.read(); // 0x41 (TEMP_OUT_H) & 0x42 (TEMP_OUT_L)
GyX=Wire.read()<<8|Wire.read(); // 0x43 (GYRO_XOUT_H) & 0x44 (GYRO_XOUT_L)
GyY=Wire.read()<<8|Wire.read(); // 0x45 (GYRO_YOUT_H) & 0x46 (GYRO_YOUT_L)
GyZ=Wire.read()<<8|Wire.read(); // 0x47 (GYRO_ZOUT_H) & 0x48 (GYRO_ZOUT_L)
Serial.print(" GyX = "); Serial.print(GyX/131);
Serial.print(" | GyY = "); Serial.print(GyY/131);
Serial.print(" | GyZ = "); Serial.println(GyZ/131);
delay(333);

if((GyX/131) < -100 || (GyY/131) < -100 || (GyZ/131) < -100)
{
Romeo_m.motorControl(Forward,200,Forward,200);
delay(1000);
Romeo_m.motorStop();
delay(2000);
};

}[/code]

My problem is that this sketch works fine only when the board is running on batteries AND linked to the PC through USB.
When I try to use it only with batteries, it does'nt seem to work : the motors don't "move". I'm wondering why.

This original sketch from the product wiki works fine, when using it with the same batteries :
[code]#include <Romeo_m.h>
void setup(void)
{
Romeo_m.Initialise();
Serial.begin(115200); //Set Serial Baud
}
void loop(void)
{
char val;
if(Serial.available()>0)
{
val = Serial.read();
}
switch(val){
case 'a'://Go forward
Romeo_m.motorControl(Forward,200,Forward,200);
break;
case'b'://Go back
Romeo_m.motorControl(Reverse,100,Reverse,100);
break;
case'c'://Turn left
Romeo_m.motorControl(Forward,100,Reverse,100);
break;
case'd'://Turn right
Romeo_m.motorControl(Reverse,200,Forward,100);
break;
case'e'://Stop
Romeo_m.motorStop();
break;
default: break;
}
}[/code]')

Thanks for reading ;)
2016-09-19 23:28:24 ;):) userHeadPic Wendy.Hu
2016-09-17 14:26:55 ('('('('('('('[quote="Wendy.Hu"]Hi

When you used the code from our product wiki, the motor works fine, it proves the romeo mini is good.

Did you try to delete the if sentence in your own code, then look at if the motor is going to turn. If the motor works fine, it suggests that the voltage of the motor disturbed the I2C protocol. If the motor still dont move, maybe you can parallel connect a 47 uF capacitor to the VCC and GND of the motor or change other better motor.[/quote]')')')')')')')

Hi, thanks for the answer,

I think you're right, my whole configuration is only powered by 6v batteries (the minimum is 6,5) but due to a lack of room, I can't add more batteries for the moment. Before, i could turn the motors at a speed of 200 because there was no i2c module, so the only solution I have is to use a slower speed. And it works :

('', ' if((GyX/131) < -100 || (GyY/131) < -100 || (GyZ/131) < -100)
{
Romeo_m.motorControl(Forward,100,Reverse,100);
delay(500);
Romeo_m.motorControl(Reverse,100,Forward,100);
delay(500);
Romeo_m.motorControl(Forward,100,Reverse,100);
delay(500);
Romeo_m.motorControl(Reverse,100,Forward,100);
delay(400);
Romeo_m.motorStop();
delay(2000);
};[/code]

But I have now another problem and I don't know if it's still because of the power : I want the piece of code running the motors to be declared into a function (and then to fit the functions names into an array to be randomly run).

But when I just first try to put the "action" code into its own function, it doesn't work :
('', 'void loop(void)
{
Wire.beginTransmission(MPU_addr);
Wire.write(0x3B); // starting with register 0x3B (ACCEL_XOUT_H)
Wire.endTransmission(false);
Wire.requestFrom(MPU_addr,14,true); // request a total of 14 registers
AcX=Wire.read()<<8|Wire.read(); // 0x3B (ACCEL_XOUT_H) & 0x3C (ACCEL_XOUT_L)
AcY=Wire.read()<<8|Wire.read(); // 0x3D (ACCEL_YOUT_H) & 0x3E (ACCEL_YOUT_L)
AcZ=Wire.read()<<8|Wire.read(); // 0x3F (ACCEL_ZOUT_H) & 0x40 (ACCEL_ZOUT_L)
Tmp=Wire.read()<<8|Wire.read(); // 0x41 (TEMP_OUT_H) & 0x42 (TEMP_OUT_L)
GyX=Wire.read()<<8|Wire.read(); // 0x43 (GYRO_XOUT_H) & 0x44 (GYRO_XOUT_L)
GyY=Wire.read()<<8|Wire.read(); // 0x45 (GYRO_YOUT_H) & 0x46 (GYRO_YOUT_L)
GyZ=Wire.read()<<8|Wire.read(); // 0x47 (GYRO_ZOUT_H) & 0x48 (GYRO_ZOUT_L)
Serial.print(" GyX = "); Serial.print(GyX/131);
Serial.print(" | GyY = "); Serial.print(GyY/131);
Serial.print(" | GyZ = "); Serial.println(GyZ/131);
delay(333);

if((GyX/131) < -100 || (GyY/131) < -100 || (GyZ/131) < -100)
{
action1;
};

}

void action1(void)
{
Romeo_m.motorControl(Forward,100,Reverse,100);
delay(500);
Romeo_m.motorControl(Reverse,100,Forward,100);
delay(500);
Romeo_m.motorControl(Forward,100,Reverse,100);
delay(500);
Romeo_m.motorControl(Reverse,100,Forward,100);
delay(400);
Romeo_m.motorStop();
delay(2000);
}
[/code]')')

The rest of the sketch didn't change. Thank you for your help. ;)

Edit : forget about it, I've just forgotten the brackets after calling the function. Humans do errors :D
userHeadPic Ghedjati Nabil
2016-09-08 02:18:39 Hi

When you used the code from our product wiki, the motor works fine, it proves the romeo mini is good.

Did you try to delete the if sentence in your own code, then look at if the motor is going to turn. If the motor works fine, it suggests that the voltage of the motor disturbed the I2C protocol. If the motor still dont move, maybe you can parallel connect a 47 uF capacitor to the VCC and GND of the motor or change other better motor.
userHeadPic Wendy.Hu