What's happening with my robot?

Hello all

My robot now is using a mega2560.

It has 2 servos (both TowerPro 9g SG90), a relay and a GSM module.

I made my own power supply for the whole robot. Attached is the schema.

The problem I have is when the GSM gets ready and registers to network, my servos start shaking alone…

Here is the code:

#include <Servo.h>

extern char resp[28];

Servo servo_dir, servo_meat;
#define gsm Serial1
#define dbg Serial
#define SERVO_DIR_PIN 8
#define SERVO_MEAT_PIN 9
void setup() {
  pinMode(35, OUTPUT);
  pinMode(37, OUTPUT);
  dbg.begin(19200);
  gsm.begin(19200);
  servo_dir.attach(SERVO_DIR_PIN);
  servo_meat.attach(SERVO_MEAT_PIN);
  servo_dir_move(0);
  servo_meat_move(0);
}

void loop() {
  gsm_read_resp();
  gsm_read_resp();
  gsm_read_resp();
  gsm_read_resp();
  if (strcmp(resp, "Call Ready") == 0) {
    dbg.println("gsm rdy.");
    
    while (true) {
      delay(400);
      gsm.print("AT+CREG?\r");
      gsm_read_resp();
      if (strcmp(resp, "+CREG: 0,1") == 0 || strcmp(resp, "+CREG: 0,5") == 0) {
        gsm_read_resp();
        break;
      }
      gsm_read_resp();
    }
    
    dbg.println("gsm registered.");
  
    while (true) {
      delay(400);
      gsm.print("AT+CGATT?\r");
      gsm_read_resp();
      if (strcmp(resp, "+CGATT: 1") == 0) {
        gsm_read_resp();
        break;
      }
      gsm_read_resp();
    }
    
    dbg.println("gsm/gprs rdy.\r\n");
    
    gsm.print("AT+CIPSHUT\r");
    gsm_read_resp();
    gsm.print("AT+CSTT=\"internet\",\"\",\"\"\r");
    gsm_read_resp();
    gsm.print("AT+CIICR\r");
    gsm_read_resp();
    gsm.print("AT+CIFSR\r");
    gsm_read_resp();
    gsm.print("AT+CIPSTART=\"TCP\",\"sorry_i_dont_show_this\",\"12345\"\r");
    gsm_read_resp();
    gsm_read_resp();
    dbg.println(resp);
    
    do {
      gsm.print("AT\r");
      gsm_read_resp();
      delay(200);
    } while (true);
    
  }
}
char buf[32], resp[28];
unsigned char buf_len, resp_len;

char gsm_read() {
  char b;
  
  while (gsm.available() <= 0) {
    delay(1);
  }
  
  b = gsm.read();
  return b;
}

unsigned char gsm_read_until(char c, unsigned char off) {
  char b;
  
  buf_len = off;
  do {
    b = gsm_read();
    buf[ buf_len ] = b;
    buf_len ++;
  } while (b != c);
  
  return buf_len;
}

void gsm_read_resp() {
  gsm_read_until('\r', 0);
  gsm_read_until('\n', buf_len);
  gsm_read_until('\r', buf_len);
  gsm_read_until('\n', buf_len);
  memcpy(resp, buf + 2, buf_len - 2);
  resp_len =  buf_len - 4;
  resp [ resp_len ] = 0;
}

void servo_dir_move(char angle) {
  int pulsewidth = map(angle, -100, 100, 544, 2400);
  servo_dir.writeMicroseconds(pulsewidth);
}

void servo_meat_move(char angle) {
  int pulsewidth = map(angle, -100, 100, 544, 2400);
  servo_meat.writeMicroseconds(pulsewidth);
}

the relay coil is connected to +5V of Arduino.

Everything else is connected as the schema says.

Thanks.

If the servos shake, there is usually a problem with the power supply. Tell us more about the relay - what does it do, how much current does the coil draw, and do you have a flyback diode across it?

Using linear regulators to produce 5V from a 16V LiPo battery is a bad idea. You waste 2/3 of the power, just producing heat.

Hi!

Thanks for the answer, I was waiting since 7 am !

The relay just starts motors, at the moment is not being used in the code and if I disconnect it, doesn’t work well (still shaking).
Ayway I give you info: http://www.seeedstudio.com/wiki/Grove_-_SPDT_Relay(30A)

Yeah, I heard it before (about linear regu. and lipo), but I just need to power servos which consume <450 mA in worst case, and a gsm module which ups to 2A when signal is very low. So in the worst case, I am loosing very low power. And the arduino. But it at least 0.7 Ampers usually…

Can you explain me which kind of error my pwr supply has? I am really interested in solve the problem, please any help is appreciated. Really.

Thanks for your answer, hope you can help me again. (only the answer made me happy).

Abel.

pd.
If you want to know, I used TimerOne.h library for using .pwm function instead of Servo.h, and still shaking when issuing startup commands to module (gsm).

Please, any help is appreciated.

I have no problem with my supply. I’ve tested twenty times, it works fine. I measured outputs, and tested with load. It just works.

The problem comes when I power on the GSM shield and it starts to register network and init gprs… but I don’t know how to fix it!

If I run only the servos, they’r rolling fine but once I start GSM shield… it start shaking

Please, help…

Servo shakes without any load (please remove any load and test) means its timing is off. I suspect once your gsm shield is registered in the network, you get a lot of stuff printed into your GSM serial port in big chunks, say many characters at a time? If that is the case, each read blocks interrupt that is used by the servo for timing and could throw off timing resulting shaking.

I just need to power servos which consume <450 mA in worst case

This is not correct. The specification for the stall current for that servo is 650 mA at 5 V, and each briefly consumes the stall current when it starts moving, regardless of load. But your regulators should handle that, so do investigate the possibility of a timing problem first.

liudr:
Servo shakes without any load (please remove any load and test) means its timing is off. I suspect once your gsm shield is registered in the network, you get a lot of stuff printed into your GSM serial port in big chunks, say many characters at a time? If that is the case, each read blocks interrupt that is used by the servo for timing and could throw off timing resulting shaking.

Servo shakes without any load? No, It doesn't. When I connect it without GSM shield it works fine. Really fine.
Yeah, I I receive and send chunks of data by HardwareSerial port on the GSM pins.
The interrupts for hardware serial tx & rx doesn't let servo's timer to pulse the width enough.
So, how to fix it? I need the GSM shield for remote control, on the FLY. And I developed a pure C code for Arduino Pro Mini, but this is a pain in the ass, because each time I must recalibrate all the code. And powering 6V instead of 5.

So, how can I do this? I tried to set the maximum baudrate to the GSM shield, it is 57600bps. But still having shakes. So, tried with 9600bps. And the same. With the pure C code on Mini and 6V to the servo, I found the way of making it to shake the less possible by software improvements. But,

  1. the servo's voltage is 4.8 ~ 5V.
  2. Pure C is a pain in the ass. ( sorry for underage people ).

Then, what can I do my friends? I just fantastically happy with your answers. Please, keep helping me... THANKS!

Abel.

jremington:

I just need to power servos which consume <450 mA in worst case

This is not correct. The specification for the stall current for that servo is 650 mA at 5 V, and each briefly consumes the stall current when it starts moving, regardless of load. But your regulators should handle that, so do investigate the possibility of a timing problem first.

Oh, I haven’t noticed before. I just used a multimeter to measure current peaks. And maybe so fast for the resolution of the machine (multimeter). But, it’s ok, if it’s just at power on, there’s no a lot of problematic. I think… just havin 100 mA - 120 of normal current peaking I think is not very hard.

Anyway, the L7805CV is able to source up to 1.5A. It is not the common LM7805.

Cheers,

Thanks for your worries.

Abel.

Can you do a simple program that registers your gsm shield and don't send anything over the network at all? If the shake is gone, then it is the shield receiving/sending stuff that caused it. Also, your servo wires may be picking up interference from GSM serial lines.

Ehlo!

I'm not sending anything over the network, the shaking starts when I power on the GSM and then I send the checking commands: AT+CREG? and AT+CGATT? then starts shaking. While sending simple AT commands, (after the saids before) only shakes sometimes...

So, maybe is a power thing? I don't think so. It's also because servo works better with 6V. And with my power supply I am giving 5V. But it is a timing trouble. While serial receives more than 5 bytes in a chunk, then it's 5 bytes * 8 bits/each byte * 204 uS which is > than higher pulse...

Thanks a lot, hope you can help me.

Abel.

liudr:
Can you do a simple program that registers your gsm shield and don't send anything over the network at all? If the shake is gone, then it is the shield receiving/sending stuff that caused it. Also, your servo wires may be picking up interference from GSM serial lines.

Hello,

I did it. It registered on the network and servo still shaking.

I had an idea for solving the thread issue. I put 2 uC communicated by 9 wires, for tx the parameters for the servo. And worked like a charm. But I can't connect GSM shield to the same power supply of both CPUs... If I do, then it's shaking.

I don't understand well why this happens. Just I used the LiPo with the 3A regulator to connect the module, and then connected both CPUs in the USB ports. And communicated by the 9 wires, and its ok. It works fine.

How can I solve the power supply problem without using more than 1 baterry?

Thanks a lot mates, you made me happy today too.

Abel.

Basically, sometimes it worked with my first tests because the signal quality was good, then didn't consumed so much current and the servo with the external battery, it was enough for working without shaking... but these days are windy and cloudy so probably it's shaking because 400mA from the VCC weren't enough.
What I don't understand well, is how with a LiPo of 16.8V and 20-30C of discharge I can not to power supply the whole circuit just by using 3 regulators... I can understand it's a problem of not enough current, but how can it be working bad with 1.5A per servo and 3A for 2 cpus and 1 shield of 2A max current...?

If I am not bad at maths, arduino pro mini is pico so no more than 100 - 200 mA are need. If we have 2, then its 400mA max. If the shield takes 2A sometimes, it's 2.5A max... so 3.0 - 2.5 A = 0.5 A remaining... I can't understand this... I'm going crazy with this project.
I recognize I am not really experienced in electronics, I started it a year ago as a hobby, but... this is ... omg.

please, help.

thanks in advance.

Try powering the Arduino separately from the GSM module -- use a battery for tests and if that works, if necessary use a fourth regulator. Power supply problems (and proper decoupling thereof) have been issues since electricity was discovered.

Edit: the LM350 is rated for 3 amperes ONLY if Vi-Vo is less than 10 volts. Your circuit exceeds that so the regulator may be going into thermal shutdown when the GSM module transmits. A heat sink may help.

In any case, using linear regulators like you are doing is a very bad idea for battery power supplies.

jremington:
Try powering the Arduino separately from the GSM module -- use a battery for tests and if that works, if necessary use a fourth regulator. Power supply problems (and proper decoupling thereof) have been issues since electricity was discovered.

Edit: the LM350 is rated for 3 amperes ONLY if Vi-Vo is less than 10 volts. Your circuit exceeds that so the regulator may be going into thermal shutdown when the GSM module transmits. A heat sink may help.

In any case, using linear regulators like you are doing is a very bad idea for battery power supplies.

I did it and works fine separated. But I need one battery.
A guy from another forum told me to use fat capacitors in the power rails for helping the decoupling generated by the gsm module bursts.

The heat sink can help too. Thanks for that info.

Where is said that about output current? Intelligent Power and Sensing Technologies | onsemi

Hope an answer mate.

Thanks.

Where is said that about output current? Intelligent Power and Sensing Technologies | onsemi

In the data sheet, Electrical Characteristics, Maximum Output Current.

So now I am getting 1A max, isn't it? :((

Which regulator up to >= 2A do you recommend me for this job? It would be fine if I can buy in my favorite shop :slight_smile:

Thanks dude!

EDIT: well... in my favorite shop there's only fixed 1.5A and the LM350, the others are for more than 5V and between 100mA - 1.5 A...

What do you suggest me? What's about using 90% efficiency regulators? which ones?

Thanks dude.. sorry so much questions... hehehe

EDIT: Are buck boost regulators what you were suggesting me?

Oh, really nice.

Thanks a lot!

What's about decoupling? Should I add capacitors by my own? Or these regulators are coupling safe? Sorry I don't understand so much about electronics.. hehe.

EDIT: how should I regulate the different outputs? Must I use one regulator for each hardware piece?

For example, can it be:
2.5A -> GSM shield
0.6 -> servo1
0.6 -> servo2
0.5 -> both Arduino Pro Mini

??

Thanks mate... really thanks.

EDIT: Or could I use just a 5A regulator for everything and use big capacitors on each power rail??
EDIT:
http://www.pololu.com/product/2865 this would be enough for all the hardware?

Google “power supply decoupling” for the proper techniques. It is a big subject. Also, use proper grounding: heavy wire and a star ground.

OMG dude, I can’t believe what I was reading… OMG

How is this supposed to be done by a hobbist like me? LOL

I have seen Doctors who went crazy with graphs and plots, OMG… I just want to power my holly GSM module with same power supply which the servo’s one! LOL I went crazy man.

Well, two guys told me to just use huge caps on each power rail. They told me 1k uF but I’ve read about putting lot of 0.1uF.
Also to put 100uF with 10nF ceramic. Does anyone know which the problem is? I guess nobody has a solution as the Ohm’s Law says for basic electronics: V=IR. That’s all mate, no complication on that… Why so much more info about that subject? I don’t even know from where to where the current and voltage goes from… LOL

Thanks anyway man, you were so helpful. But going more deep, can you give me more accurate information? Just to disturb you a bit more :slight_smile:

Thanks!

Abel.