Building an Arduino Controlled Animatronic System - Part 6: The Code

Поделиться
HTML-код
  • Опубликовано: 29 июн 2024
  • In this final part of the animatronic eyeball project, we get the arduino drivers running, load the code, calibrate the system, and run the final animatronics. I also give a run down of how the basic code works.
    You can get the two codes from the following links:
    Analog Pot Servo Calibration: www.dropbox.com/s/7e0wioezns4...
    Eyeball Demo to be Released: www.dropbox.com/s/auap3uugs5f...
    If you have questions, feel free to contact me on twitter @jimscuba2386

Комментарии • 44

  • @bid0u12345
    @bid0u12345 4 месяца назад

    The calibration is so smart. This series is really awesome to watch and explanations are very thorough! Thanks! 👏👏

  • @aPyroDesign
    @aPyroDesign 6 лет назад +3

    Dude this is awesomely in depth and while I'll probably never do this, you are doing great with this videos. It's interesting for sure.

  • @buildersmark
    @buildersmark 6 лет назад +2

    Great job Jim! Very well laid out & understandable.

  • @RV_There_Yet
    @RV_There_Yet 6 лет назад +1

    Keep up the videos. Great info!

  • @MakerDan55
    @MakerDan55 6 лет назад

    Hi Jim, I have been waiting for this one. Thanks for all your hard work. I love the way you explain things and comment on the code. I have watched this video only once so far but plan on seeing it a few more times to really figure it all out. My greatest hurdle is trying to figure out how IC2 programming works (how to assign programming to each servo). Maybe if you had time you could post a video on that! HaHa. I am off to DisneyWorld in a couple of weeks and then plan on making a whole lot of Animatronic characters when I get back using your setup.

    • @jim2386
      @jim2386  6 лет назад

      Dan Massey the beauty of Arduino is the background code supplied when you install the servo wing does it all for you. If you only use 1 wing, it’s simple. Adding more wings you need to address them which isn’t hard and I can explain sometime.
      With just 1 servo feather wing, you can drive 8 individual servos at once. That oughta be a good start! ;)

  • @bjs027
    @bjs027 6 лет назад

    One thing I noticed that would help make it faster is to put down a few extra letters to get it to jump to the position then one letter at a time to fine tune it. Example one "a" to move small steps "aaaa" to move bigger steps.
    Great program. I really want to learn how to add more servos. Another nice thing would be able to record one or two servos at a time. Hard to record many servos at once. Again thanks for sharing. Love your Tiki.

  • @ZeedijkMike
    @ZeedijkMike 3 года назад

    Just a very small tip. You might already know it by now as the video is a couple of years old.
    You can auto format your Arduino code with Ctrl-T so all indentations and curlies "{ }" are lined properly up.
    For some reason the menu item/shortcut is 'hidden away' under Tools instead of Edit.
    I have really enjoyed this Animatronic series. Educational and inspiring.

  • @Gl1kk3r
    @Gl1kk3r 4 года назад +1

    Coming late to this party, but I really enjoyed this series. I'm going to start my own animatronic after Christmas (other projects to finish before then), and it was great to see how low the barrier of entry is. Also, as a professional software engineer, I have to say no code is terrible if it works. Until someone else has to come in and change it, then it's terrible no matter what you did. ;)

    • @jim2386
      @jim2386  4 года назад

      Ben Taggart thank you! That means a lot! I hoped it would motivate lots of people to try animatronics. Teach a man to fish :)

  • @gkess7106
    @gkess7106 4 года назад

    Can more than one eyeball sequence be held in memory to be tripped by different relay closures? Would mouth movements be recorded at the same time as eyes?

  • @Workshopshed
    @Workshopshed 6 лет назад

    Hey Jim, just found the project and want to follow along from the beginning, any chance of you creating an eyeball playlist to make that a bit easier.

    • @jim2386
      @jim2386  6 лет назад +1

      Workshopshed yeah let me see if I can figure that out when I get to work. Good idea :)

    • @jim2386
      @jim2386  6 лет назад

      Workshopshed ruclips.net/p/PL6af5gMccd9KLyUOxHn8XRLhzpFvGFOA5 Try this :)
      I’ll add it to the thingiverse files

    • @Workshopshed
      @Workshopshed 6 лет назад

      Cheers. Got some fun watching to do

  • @margrottheengineer5342
    @margrottheengineer5342 6 лет назад +1

    Hey jim im a few days away from getting to the coding part, i watched the whole video and had a question. Is there a code that allows a live feed, I'd like to operate these puppets for kids at a hospital so i figured it would look more realistic if i could control the eye's in real time. Instead of having a preprogrammed routine. Does that make sense? Please and thank you jim!! Also i apologise for bothering you so much, ypur amazing! Thank you for your hard work you literally inspired me and I'm almost done with the assembling portion of the project. Once it's up and running, ill upload a few videos on youtube of me in the hospital and you'll be one of the first people to know. Yoir helping my dream come true and helping alot of sick kids get through some tough times. Thank you so much!

    • @margrottheengineer5342
      @margrottheengineer5342 6 лет назад

      I thought the first program would be it until i realized its just a program to initially create the dimensions for the eye movement to be based upon.

    • @jim2386
      @jim2386  5 лет назад

      margrot the engineer the code does a live feed's when you first record. In the code, you can comment out the Fram.write commands and change the outside loop from 0 to whatever time and just change it to a while loop where something is never true to it loops forever.
      If you choose not to hook up fram cards, make sure you comment out the fram board initializTion at the top of the code or else the code will stop because it can’t find the fram boards it’s looking for :)

    • @jim2386
      @jim2386  5 лет назад

      margrot the engineer give it a shot and if you really get stuck on getting it to play live forever, let me know.

    • @margrottheengineer5342
      @margrottheengineer5342 5 лет назад

      jim2386 yes sir will do thank you!!

  • @bjs027
    @bjs027 6 лет назад +1

    The switch and the led I think were missed in setup and wiring. Is there somewhere that you talked about it and I missed it? Thanks.

    • @jim2386
      @jim2386  6 лет назад

      Brad 44 you’re right. I must have added that after filming that segment. I’ll make a quick addendum video Friday on how to add it.
      Thanks!

    • @jim2386
      @jim2386  6 лет назад

      Brad, I’ve added the STL file for be button holder to the thingiverse page. Feel free to print that out and have it ready while I get the video filmed
      The Adafruit button you’ll use is product ID: 1440
      You’ll also need a 470ohm-ish resistor: product 2781
      I also use some shrink tubing in the video but it’s not technically required: product 1649
      That should be all you need to add it.
      Thanks again! Sorry you had to be the guinea pig :)

    • @jim2386
      @jim2386  6 лет назад

      ruclips.net/video/EGltZj8opkc/видео.html Here's the updated video, as promised! Thanks for catching that!

    • @bjcustoms
      @bjcustoms 6 лет назад +1

      jim2386 thanks for the the video and the stl. Files. I made it and it is fun to play with. Now I just need to learn how to make it record then replay on demand. I was thinking to add another switch and using that to record with then have another switch to activate it. Thanks for the inspiration.

    • @jim2386
      @jim2386  6 лет назад

      You've got it!
      To add a switch, in the Arduino IDE, go look under file: examples: digital: button. It shows you how to use a switch tied to a pin to activate the LED on the board.
      Once you get this, it's as simple as putting an IF statement around the stuff inside your "LOOP" function.
      var = digitalRead(PinUChoose);
      if (var = LOW) //Arduino can set the input pin to HIGH using the internal input pullup resistor. Tie the other end of your switch to ground.
      {
      Code to play your FRAM recorded movements
      }
      Here's an excellent writeup on why input pullup resistors should be used and what a floating connection means: www.baldengineer.com/arduino-internal-pull-up-resistor-tutorial.html
      Of course, you may want to add another switch so it knows if you want to record something new. Put an digitalREAD in your setup section and if the switch is low, put the code to record movements inside the IF statement. If the switch is HIGH, then the IF statement won't be true and the code will skip over the recording process. Remember to only put the recording functions inside the IF statement....the other setup commands need to be read every time to make sure all your drivers etc are set up.
      Hope that makes sense. Start with the switch example built into Arduino and the link I gave you and I think that'll make things much clearer. I'm glad the project served it's purpose. It got your brain juices flowing and is pushing you to learn more! :D
      If you could do me a big favor. If you haven't already, would you mind going on thingiverse and posting "I made one" under the eyeball mech and post a few pictures etc of your final project. It really helps other people know the project does indeed work if you follow the directions :D Thanks!

  • @steveg1784
    @steveg1784 4 года назад

    Hello Jim, I have just completed this build and everything works great I just have a question, I am creating this animatronic for a Halloween costume and after recording I would like it loop back until I turn it off or reset. I see in the code on line 177 it states ( Initialize Loop Counter for the number of times the programmed code should run) I change this but it does not go on a loop, What am I missing? Thank you very much for taking the time to create this excellent and in depth tutorial I have learned alot.

    • @jim2386
      @jim2386  4 года назад

      Steve G glad you liked it. I’ll take a look in the morning and see if I can give you some guidance :)

    • @steveg1784
      @steveg1784 4 года назад

      jim2386 Ok thank you very much Jim.

    • @jim2386
      @jim2386  4 года назад

      So I just ran the code on my setup (it's been a while!) and all you need to do is take the original code (with your upper and lower pot and servo limits written in.
      Go to line 179 where it says i++. This increments i by 1 each time it loops. If you comment out that line by putting two slashes in front of it:
      //i++ (it'll turn grey if you do it right)
      the counter never increments so the stop code at the bottom never reaches 3. It'll loop forever. Just tested it and it works fine.
      I imagine you want to program this once, then every time you power it up, you don't want to record, you just want it to play. That's a little trickier but not hard.
      On line 103 you'll see delay(1000). This delays 1 second (1000ms) before starting to record your movements. Change this to something larger like 30000 (30seconds). It'l take 30 seconds before you can start recording your motions but here's the key, if you comment out or delete the FOR loop (lines 109 to 167), it won't record anymore and it will go directly to playing what's in memory the last time you recorded.
      So here's the steps:
      1. comment out i++ to get it to loop forever.
      2. change the 1000 delay to 30000 or more
      3. Save this code as programming code or some file name so you know it will allow you to record new movements.
      4. Save a second version of the code with the delay set back to 1000 and the FOR loop commented out (so it won't record). Save this code with a filename like PlaybackOnly.
      5. Load the record code with the long delay and the i++ commented out onto the board. Power on and record your movements (remember it'll be 30 seconds or so before it starts recording just this one time.
      6. Check and make sure your movements loop infinitely now.
      7. Open the code that is Playbackonly. Plug in the USB into your arduino and immediately load the code. You need to get the code loaded within the 30 second delay so the old code doesn't start recording over your old movements.
      Once that code loads, they delay should be shortt again since it is set for 1000ms, it should skip over recording because you commented it out, and it should loop forever because you commented out i++.
      On my normal animatronics programming projects, I have a switch attached to one of the unused input pins and I put in an IF statement that says if the switch is on, then go into the record loop. If it's off skip over the record loop.
      Doing it the way I described above, you don't need any extra hardware. I hope this makes sense. If you need more live help, you can send me a direct message on twitter. I just tried it here and can confirm it works though so I think you should be all good!

    • @steveg1784
      @steveg1784 4 года назад

      jim2386 Wow you made it so clear thank you very much, I will try it a little bit later and I will send a picture of what I’m working on to your twitter account. I will let you know if I got it working.

    • @steveg1784
      @steveg1784 4 года назад

      @@jim2386 Hello Jim I tried out what you wrote and when i tried to upload the first code I get this error message. I tried a few different things i read but I am to new to coding. I sent the code where i get the error message to your twitter, maybe i imputed something wrong but i don't see how.
      Arduino: 1.8.8 (Windows 10), Board: "Adafruit Feather 32u4"
      C:\Users\steve\Desktop\Save_this_code_as_programming_code_or_some_file_name_so_you_kno\Save_this_code_as_programming_code_or_some_file_name_so_you_kno.ino: In function 'void loop()':
      Save_this_code_as_programming_code_or_some_file_name_so_you_kno:225:8: error: 'i' was not declared in this scope
      }while(i>=3);
      ^
      Multiple libraries were found for "Wire.h"
      Used: C:\Users\steve\AppData\Local\Arduino15\packages\adafruit\hardware\avr\1.4.13\libraries\Wire
      Not used: C:\Program Files (x86)\Arduino\hardware\arduino\avr\libraries\Wire
      exit status 1
      'i' was not declared in this scope
      This report would have more information with
      "Show verbose output during compilation"
      option enabled in File -> Preferences.

  • @dgililov
    @dgililov 2 года назад

    Hi Jim.
    For some reason during playback, servos sometimes vibrate, kind of jumping from desired recorded position to default servo values… During the recording mode everything runs smoothly and servos reflecting exact analog signals… Any known issue that can cause this? And how to fix?
    Thank you!!

    • @jim2386
      @jim2386  2 года назад +1

      went and looked at the code since it's been forever. If you're recording smoothly your code is fine in the setup section where it runs once (record section) and your problem is somewhere in the loop(){ section since that's where things play.
      My typical plan of attack is to use the Serial.println(); command to help debug.
      For example:
      Go down to the section where it says:
      LRintram = fram.read8(bLR);
      UDintram = fram.read8(bUD);
      Blinkintram = fram.read8(bBLINK);
      The software is reading the value from FRAM back into memory. So I would do
      Serial.println(LRintram); after that line and run the code. Do the numbers being displayed on screen look smooth or do they jump around when the eye jumps?
      If things look smooth, try doing the same for UDintram etc.
      If all those those look smooth, you know the data in FRAM is recorded fine and read fine.
      Move down the code:
      LRservovalue = map(LRintram,0,255,servoLRmin, servoLRmax);
      UDservovalue = map(UDintram,0,255,servoUDmin, servoUDmax);
      Blinkservovalue = map(Blinkintram, 0, 255, servoBlinkmin, servoBlinkmax);
      This section is where it's interpolating the value from 0 - 255 back to a servo value. Do a Serial.println(LRservovalue);
      and run the code again. Is the variable data smooth? If so, check the next varible.
      Since that data is sent directly to the servos, I'd expect one of those variables to be jumping. Once you figure out which value is jumping, you can trace the problem back.
      One other thing to check, back up in the:
      LRintram = fram.read8(bLR);
      UDintram = fram.read8(bUD);
      Blinkintram = fram.read8(bBLINK);
      section, you can also Serial.println(bLR);
      You can display bLR, bUD, and bBlink. These are memory address locations. You'll want to make sure each variable counts upwards and doesnt' skip any values.
      See which variable bounces around and then work backwards to find out why it's bouncing.
      One thought that comes to mind is if, if the fram address variable is skipping a value when recording (bLR,bUD, bBlink) when there's are memory locations that are never getting recorded with new data so when you read it back, it plays back locations that haven't been recorded.
      Sorry for the ramble but this is how you debug. Find out which variable is bouncing and work backwards. If the data being read immediately is bouncing we know we'll hae to go back and check how it's getting recorded. Baby steps.

    • @dgililov
      @dgililov 2 года назад +1

      @@jim2386 thank you the detailed answer! I will need to spend some time on debugging… i did modify your code
      1. to use a mirrored eye (in your project 2 eyes are the same layout..- in my project i need both eye lids levers to be oriented towards the nose of the head, so had to print and program a mirrored version
      2. Ive added a jaw to both, recording and runtime programs.. so there is also bJaw variable which allocates to and reads from memory right after bBlink
      So the eye lid joystick is used to record movements of the eye lids and then later jaw movements using the same soundtrack…
      Its pretty difficult and going to add more complexity as I add more eye lids and jaws that will play in the same scene.
      So another question is: how to better manage recording when need to record layers of movements for the same soundtrack using one joystick. In my example i am trying to make 2 heads having a conversation…
      Thanks for sharing your knowledge!

    • @dgililov
      @dgililov 2 года назад

      @@jim2386 i think i found the issue - in the runtime program servo frequency was not set to 60 Hz.
      Thanks for your help!!

  • @4pointbuck416
    @4pointbuck416 4 года назад

    were can you learn to prograhm arduino?

  • @musiccheetah8771
    @musiccheetah8771 2 года назад

    hey im getting this error when i try and upload the "eyeball demo to be released" sketch:
    Eyeball_Demo_to_be_released:5:10: fatal error: Adafruit_FRAM_I2C.h: No such file or directory
    Multiple libraries were found for "Wire.h"
    #include "Adafruit_FRAM_I2C.h"
    Used: C:\Users\JJBBD\AppData\Local\Arduino15\packages\adafruit\hardware\avr\1.4.14\libraries\Wire
    Not used: C:\Program Files (x86)\Arduino\hardware\arduino\avr\libraries\Wire
    ^~~~~~~~~~~~~~~~~~~~~
    compilation terminated.
    exit status 1
    Adafruit_FRAM_I2C.h: No such file or directory

    • @jim2386
      @jim2386  2 года назад

      Did you install the FRAM libraries and run the test examples?