Banging my head against the wall - Arduino keeps Hanging

Hello,

I'm really hoping someone can tell me what I'm doing wrong here but I've banged my head against the wall on this now for weeks.

As an exercise in learning about Arduino and the ESP8266 I am trying to build a WiFi enabled Cat toy. Basically the concept I have is this:

  • Two servos (X and Y)
  • Laser pointer (5v)
  • ESP8266
  • ATMega326PU

The idea is basically this: I have an ESP8266 programmed to connect to my WiFi and run a micro HTTP server. When you visit http://ipaddress/power/on it turns GPIO2 on the ESP8266 ON, and when you visit http://ipaddress/power/off it turns it off. Then on the ATMega side, the sketch inits the servos, and monitors the ESP8266's GPIO 2 pin to go high. Once it does, it runs it's program to turn on the laser (attached to another ATMega GPIO) and start moving the servos around.

I built this all out on a breadboard and it worked. My problem is I put together a prototype board with the circuit and now when I run it, it runs fine until you try to turn the servos on. Then it might move them once or twice before apparently freezing and no longer accepting any commands. I have a status LED which blinks in different patterns in different status so I can monitor the chip and everything seems fine until I turn on the servos at which point the LED freezes high and everything stops working (except the ESP8266, that keeps working fine)

My power supply is a 3A 5v, which I use a L1117 to step-down to 3.3V for the ESP8266.

Prior to building the entire circuit, I first built just a "breadboard Arduino" on my prototype board and plugged in the chip running Blink. When I powered everything up the ATMega chip ran fine and did what it was supposed to. So I am confident my wiring of the ATMega chip itself is in good shape.

Other information: Servos are controller by pins 8 and 9, I have a status LED running on PIN 13, the laser is powered by pin 11, and the GPIO2 of the ESP8266 is connected to pin 10. I of course am speaking to pin numbers you'd find on an Uno board (not the pin #s of the ATMega chip which are 13, 15, 19, 17 and 16 respectively)

I'm attaching photos of my board as well. Any help anyone can provide in solving this mystery would be much appreciated!

Hi,
Quick possibilities:

  • Common Ground: Get the servo ground very directly to the power supply - terminal..
  • Bypass capacitors on 5V and 3.3V on your protoboard??

Can you post a circuit diagram?

Op's pics:

I don't have a diagram to share because I didn't make one, but I will put one together and post it.

I tried connecting the Servo grounds directly to the power supply ground via a clip and it didn't address it. This feels like a power supply issue to me (although 3A certainly should be sufficient?) -- does anyone have any debug tips that I might try? Also the fact this didn't happen when I was on a breadboard is very frustrating.

It does seem like a power supply issue, and 3A may well be enough although it depends how it's configured. I can't see that from those photos, and that's exactly what promoted me to ask for a circuit diagram. It needn't be a posh CAD one ;), just do it by hand and snap with your phone.

Are the servos directly on that supply, or through the Arduino 5V pin? If the latter, then you won't be able to supply the 3A even though it's available to the Arduino. Even micro servos like the ones you have can draw the better part of an amp each and that's way more than you can supply from the Arduino.

It's okay I really was planning on doing a schema anyway.

Here's the circuit. I've never used this tool before, and I just whipped this up so if something looks wrong I might have just messed up the diagram. My ESP8266 is a ESP8266-01 not ESP8266-07 so I only have two GPIO pins.

The Servo's power are wired directly into the 5v, with pulse going to 8 and 9.

Hi,
Look up the data sheet for your L1117 and you will find it needs capacitors around it for stability.

You need bypass capacitors across the power input pins of the 328 and the 8226, 0.1uF as bypass as well as 10uF 16V.
OPs circuit

Tom.... :slight_smile:

Hi,
L1117.jpg
Tom... :slight_smile:

Thank you for all your help.. forgive me though because I'm a total n00b here.

The most practical question I have is this: Is the diagram you provided the entire modification I need to make the the circuit? I believe the answer is yes.

Can you explain to me why the L1117, which in my head is only powering the ESP8266 (the one thing that is consistently working), is causing the Arduino to freeze?

Bonus kudos if you're willing to point me toward an explanation of why I need to do this. Obviously I know a bit because I was able to get all this put together on my own without anyone's help, but I don't understand certain aspects (i.e. why you put 22nF caps to ground for each crystal pin, and why I need the two different value caps to ground across the LD1117.

I'll put these caps in and see if it helps for sure though, I really appreciate your help!

Just for sanity checking, I've attached my updated schema which I believe should do the trick, correct?

Unfortunately my proto-board blew up on me. I got careless with my power supply and accidentally shorted it out on my worktable and fried one or more components on the proto board (UGH). So now I've got to re-build it from scratch :frowning:

Before I do, I just wanted someone to confirm what I've changed here around the L1117 should in theory correct the hanging issue I've been having! (I'm planning on using a 1uF not 100nF cap though, as it's what I have available -- 16V).

If you have to start from scratch, why not just buy an ESP with more GPIO and ditch the Arduino?

Because I want to figure out why this didn't work!

So I'm still stuck :frowning: I installed a 1uf cap on the L1117 input and a 10uF cap on the 3.3 output. Exact same behavior - it works completely fine while the servos and laser are off and then freezes when they turn on. (I know it doesn't freeze until then because I have a status led that blinks when off)

Please help! More suggestions?

See what happens if you temporarily disconnect the laser pointer. Maybe the laser pointer is trying to draw too much power from the arduino and making the arduino reset itself etc.

You might need to take the PWM output of the arduino and feed that signal to a switching system that can deliver more power ...... which can then feed the laser.

Could also use something (like a multimeter or an oscilloscope) to measure the output of your PWM pin of the arduino (without the laser pointer) to see if the output is doing the right thing...... such as correctly producing PWM.

Hmm it seems the servo I am using is to blame. Using what parts I have laying around I had a analog servo and a digital one. I hooked up both identically but the analog one seems to cause the chip to crash. If I have just that plugged in it crashes, but if I have the other AND the laser it works fine!

Have I missed something critical that could be separating these two servos from each other? Or do I possibly Sjust have a defective servo?

coogle:
Using what parts I have laying around I had a analog servo and a digital one. I hooked up both identically but the analog one seems to cause the chip to crash.

That's very interesting, since it's pretty much exactly what another member observed in this thread.

My thought there was that since afaik analog and digital servos look the same from the outside (ie are controlled the same) although clearly are different inside, that his analog servo might be stuffed.

Quite a coincidence, though.

Nice that you traced the issue down to the servo. The idea was certainly to remove/temporarily disconnect particular parts.... and see if the situation improved.

The main thing is ..... so the components (eg. servos) you used for your prototype were not the same as the one you used for your second version?

Yeah something is wonky with the analog servo and the chip I think.

In my tests:

  • Just analog plugged in works for a few loops then crashes
  • Digital plugged in with laser works fine

Just to be safe I tried both servos in both motor hookups as well.

I'm a bit out of my league to explain why, but everything I'm seeing from the outside seems to indicate analog servos != digital servos.

And to answer your other question Southpark...

Both my original and second build used the exact same primary parts. Same ATMega chip, same ESP8266 and same servos. The only differences between my first version and second version were the addition of the caps around L1117 per this thread.

I suspect my problem has been this servo all along. I just ordered a pack of digital servos of the same model as the working one and when Amazon delivers them later this week I will test and hopefully have identified the cause. I'll post here if/when I am successful.

Who would have thought a cat-toy would be so educational. My cat has been stalking my work room looking for the little red dot on the walls -- I think he's getting impatient for me to complete this thing.

You should have ordered another identical analog one too :wink: , to help track the fault down to the individual servo, or analog servos in general. (I lean to the former, since there must be a gazillion analog servos in play, all working as advertised.)

Seeing as I have been debugging a stupid cat-toy for about a month now in my spare time, I'd like to get it actually working and off my workbench before I start diagnosing the trials and tribulations of analog servo controllers!