MegaPi and Makeblock Gripper not working


#1

I have tried to run Makeblock Gripper on MegaPi, and I use the arduino IDE on windos.
I have problem in run some simple test.The gripper is not working.
I don’t know how to make it work.Please help.

Here is my code.


And here is my work.


#2

Normally, the Port 4B is a name defined by Graphical program software mBlock, it can’t point to correct port on the megapi in arduino code.

You may program the following program on mBlock and then upload it into arduino to check the correct arduino code, below is an picture for reference, hope you can figure out more:


#3

Thank for reply. It can work now.


#4

I have problem using the solution from tec_support.
I have Ultimate 2 kit and I built Robotic Arm Tank.
All motors are connected to MegaPi as in instructions.
Gripper motor is connected exactely as in photo of @ccan.

image

Program written like below is not functioning. I can here only a sound changing the pitch every second.

I saw that next code is moving the gripper:

But the motor does not stop when the gripper is completely open.
If I try the following:

The gripper close and motor stop after the gripper is completely closed.
I tried to stop the motor during gripper opening with next code but nothing is happening. Code does not function.

How is possible to completely control the gripper?


#5

Hi bombicri,

I have tested the same program again and it works okay.
image
For the program you met, please kindly test it again.
During the test, make sure you have connected the proper battery to MegaPi. Besides, make sure the power switch on MegaPi is turned on.


#6

I made as following:

  1. Power button from MegaPi shut down
  2. Connect USB cable between MegaPi and computer with Windows 10 (mBlock is last version)
  3. Connect/Serial Port/COM9 (on mBlock, on Scripts panel, the dot aligned with MegaPi is green)

From mBlock I made:

  1. Connect/Reset Default Program/MegaPi (successfully finished)
  2. Connect/Upgrade Firmware (successfully finished)
  3. Select Edit/Arduino Mode
  4. Compoze the sketch from your answer (verified not to be any mistake)
  5. From right panel I made Upload to Arduino (successfully finished)
  6. Disconnect USB cable
  7. Switch on the power button from MegaPi (I installed 6 new fresh batteries in the battery holder and the holder is connected to MegaPi)

The result is that the gripper motor is not turning at all but is making a thin sound.

I try, in the same way:

image

Same result, motor is not working but is making a thin sound.

Turning to the first try, the sound coming out from motor maybe is showing that something in motor command is not good, maybe frequency or something else.
Trying the next:

image

The thin sound coming out from motor last only 1 second (as there is no loop).
I should like to show how is looking the above command in Arduino, maybe you can find something wrong there.


#include <Arduino.h>
#include <Wire.h>
#include <SoftwareSerial.h>

#include <MeMegaPi.h>

//Encoder Motor
MeEncoderOnBoard Encoder_1(SLOT1);
MeEncoderOnBoard Encoder_2(SLOT2);
MeEncoderOnBoard Encoder_3(SLOT3);
MeEncoderOnBoard Encoder_4(SLOT4);

void isr_process_encoder1(void)
{
if(digitalRead(Encoder_1.getPortB()) == 0){
Encoder_1.pulsePosMinus();
}else{
Encoder_1.pulsePosPlus();
}
}

void isr_process_encoder2(void)
{
if(digitalRead(Encoder_2.getPortB()) == 0){
Encoder_2.pulsePosMinus();
}else{
Encoder_2.pulsePosPlus();
}
}

void isr_process_encoder3(void)
{
if(digitalRead(Encoder_3.getPortB()) == 0){
Encoder_3.pulsePosMinus();
}else{
Encoder_3.pulsePosPlus();
}
}

void isr_process_encoder4(void)
{
if(digitalRead(Encoder_4.getPortB()) == 0){
Encoder_4.pulsePosMinus();
}else{
Encoder_4.pulsePosPlus();
}
}

void move(int direction, int speed)
{
int leftSpeed = 0;
int rightSpeed = 0;
if(direction == 1){
leftSpeed = -speed;
rightSpeed = speed;
}else if(direction == 2){
leftSpeed = speed;
rightSpeed = -speed;
}else if(direction == 3){
leftSpeed = speed;
rightSpeed = speed;
}else if(direction == 4){
leftSpeed = -speed;
rightSpeed = -speed;
}
Encoder_1.setTarPWM(rightSpeed);
Encoder_2.setTarPWM(leftSpeed);
}
void moveDegrees(int direction,long degrees, int speed_temp)
{
speed_temp = abs(speed_temp);
if(direction == 1)
{
Encoder_1.move(degrees,(float)speed_temp);
Encoder_2.move(-degrees,(float)speed_temp);
}
else if(direction == 2)
{
Encoder_1.move(-degrees,(float)speed_temp);
Encoder_2.move(degrees,(float)speed_temp);
}
else if(direction == 3)
{
Encoder_1.move(degrees,(float)speed_temp);
Encoder_2.move(degrees,(float)speed_temp);
}
else if(direction == 4)
{
Encoder_1.move(-degrees,(float)speed_temp);
Encoder_2.move(-degrees,(float)speed_temp);
}

}

double angle_rad = PI/180.0;
double angle_deg = 180.0/PI;
MeMegaPiDCMotor motor_12(12);

void setup(){
//Set Pwm 8KHz
TCCR1A = _BV(WGM10);
TCCR1B = _BV(CS11) | _BV(WGM12);
TCCR2A = _BV(WGM21) | _BV(WGM20);
TCCR2B = _BV(CS21);

motor_12.run(100);
_delay(1);
motor_12.run(0);

}

void loop(){

_loop();

}

void _delay(float seconds){
long endTime = millis() + seconds * 1000;
while(millis() < endTime)_loop();
}

void _loop(){

}


Please note that the gripper motor is connected as in below image:

image

The Christmas Eve is coming and I really need help to be able to offer this wonderful robot to my grandson.


#7

SOLVED.
For an unknown reason the gripper was stuck closed. This is why I heard that thin sound. Was the sound of the motor trying to unstuck the gripper. I demount the gripper and I unstuck the motor rotating its ax. Now the command:

image

is working like a charm.
I am sorry that I bored your head with such a stupid stuck gripper motor.
I have only two more questions:
When the robot has to rise an object I have to take care of the tightness of the gripper or the internal fuse will stop the motor when reach enough grip?
Same question for when I want to open the gripper. I have to take care to stop motor before reaching the maximum opening?
Thanks.


#8

Hi bombicri,

When you close the gripper, the inner motor will stop automatically when reach enough grip.
When you open the gripper, the inner motor still still rotate when reaching the maximum opening, you need to stop it manually by releasing the button or set 0 value to its speed.


#9

Now it is all very clear for me.
Thank you.


#10