element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • About Us
  • Community Hub
    Community Hub
    • What's New on element14
    • Feedback and Support
    • Benefits of Membership
    • Personal Blogs
    • Members Area
    • Achievement Levels
  • Learn
    Learn
    • Ask an Expert
    • eBooks
    • element14 presents
    • Learning Center
    • Tech Spotlight
    • STEM Academy
    • Webinars, Training and Events
    • Learning Groups
  • Technologies
    Technologies
    • 3D Printing
    • FPGA
    • Industrial Automation
    • Internet of Things
    • Power & Energy
    • Sensors
    • Technology Groups
  • Challenges & Projects
    Challenges & Projects
    • Design Challenges
    • element14 presents Projects
    • Project14
    • Arduino Projects
    • Raspberry Pi Projects
    • Project Groups
  • Products
    Products
    • Arduino
    • Avnet Boards Community
    • Dev Tools
    • Manufacturers
    • Multicomp Pro
    • Product Groups
    • Raspberry Pi
    • RoadTests & Reviews
  • Store
    Store
    • Visit Your Store
    • Choose another store...
      • Europe
      •  Austria (German)
      •  Belgium (Dutch, French)
      •  Bulgaria (Bulgarian)
      •  Czech Republic (Czech)
      •  Denmark (Danish)
      •  Estonia (Estonian)
      •  Finland (Finnish)
      •  France (French)
      •  Germany (German)
      •  Hungary (Hungarian)
      •  Ireland
      •  Israel
      •  Italy (Italian)
      •  Latvia (Latvian)
      •  
      •  Lithuania (Lithuanian)
      •  Netherlands (Dutch)
      •  Norway (Norwegian)
      •  Poland (Polish)
      •  Portugal (Portuguese)
      •  Romania (Romanian)
      •  Russia (Russian)
      •  Slovakia (Slovak)
      •  Slovenia (Slovenian)
      •  Spain (Spanish)
      •  Sweden (Swedish)
      •  Switzerland(German, French)
      •  Turkey (Turkish)
      •  United Kingdom
      • Asia Pacific
      •  Australia
      •  China
      •  Hong Kong
      •  India
      •  Korea (Korean)
      •  Malaysia
      •  New Zealand
      •  Philippines
      •  Singapore
      •  Taiwan
      •  Thailand (Thai)
      • Americas
      •  Brazil (Portuguese)
      •  Canada
      •  Mexico (Spanish)
      •  United States
      Can't find the country/region you're looking for? Visit our export site or find a local distributor.
  • Translate
  • Profile
  • Settings
Raspberry Pi
  • Products
  • More
Raspberry Pi
Raspberry Pi Forum Helicopter animation using a Raspberry Pi
  • Blog
  • Forum
  • Documents
  • Quiz
  • Events
  • Polls
  • Files
  • Members
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
Join Raspberry Pi to participate - click to join for free!
Featured Articles
Announcing Pi
Technical Specifications
Raspberry Pi FAQs
Win a Pi
Raspberry Pi Wishlist
Actions
  • Share
  • More
  • Cancel
Forum Thread Details
  • Replies 32 replies
  • Subscribers 665 subscribers
  • Views 5435 views
  • Users 0 members are here
  • raspberry_pi
  • pi animation
  • programming in python
Related

Helicopter animation using a Raspberry Pi

colporteur
colporteur over 5 years ago

We are being encouraged by our leaders to practice social distancing and/or isolate ourselves where possible during this COVID19 crisis. To avoid going stir crazy while isolated in my home, I dug up an old project I have mulled over many times.

 

I would like to use a Pi to construct an helicopter animation. The best way to understand the goal of the project is let you take a look at the video. https://www.youtube.com/watch?v=Hl5--7g3jO0&t=112s

 

My first task is to build the light sequence. My light sequence is slightly different because it matches aviation specifications. There will be cabin lighting, landing lighting(front), position lighting (left/right/rear) and strobe lighting (top/bottom). All lights are either on or off with the strobes flashing when on. The lighting is being done with LEDs. Once I master the lights, I will integrate the audio and then tackle motor control. The Pi is responsible for running the whole show. I am looking to use python to accomplish the task. No, I am not interested in doing the project with an Arduino or in another programming language. Pi and python are my toolset. Hopefully I don't discover it is not possible.

 

What I am hoping for is some direction to developing the solution. I have no doubt this is programming 101 for many of you. I have much experience in programming. I have met and worked with people that have the skills to call themselves a programming. I am not a programmer.

 

The series of LED’s repeats the following sequence:

turn LED1 on solid

turn LED2 on flashing

turn LED3 on solid

turn LED4 on solid

turn LED4 off

turn LED3 off

turn LED2 off

turn LED1 off

cycle starts again.

 

My difficultly is creating the flashing LED within the sequence. I can turn all the LED's on and off. I can flash LED2 on its own. When I add flashing to the sequence LED2 flashes once and then the sequence continues with no more flashes. I require LED2 to flash continuous until it is turned off. I’m thinking I need to have a LED flashing routine (? another script) that is called in the parent script and continues to run (flash) until it is called to stop. I want to call it a fire and forget routine but that is my lack of programming terminology understanding.

 

I had this thought, write a code for a python module that flashes an led. Call the module in another python script giving it the pin number. The module should have a start and stop. Well that simple understanding of writing a module exceeds my knowledge. Since I'm not sure if what I am looking for is actually a solution, my research is proving difficult. If a module is what I need and you have a resource to assist in writing it, please let me know.

 

I'm not looking for someone to write the code but rather guide me to developing the code myself. Care to provide some insight into my helicopter animation COVID19 Isolation Project. There is no badge or points awarded, just a brain share. I look forward to your responses.

  • Sign in to reply
  • Cancel
Parents
  • glennvanderveer
    glennvanderveer over 5 years ago

    What I think you need for flashing led2 is a timer routine.  In theory, when you wanted the LED2 to start flashing, you would clear a counter(if needed), and start the timer.  When the time expires (this could be you flashing rate) the timer routine would toggle the LED2 GPIO pin, reset the counter(if using), and exit.  Then when you wanted to stop the LED2 flashing, you would just have to stop the timer.  No threading or multiprocessing needed...

    • Cancel
    • Vote Up +1 Vote Down
    • Sign in to reply
    • Cancel
  • colporteur
    colporteur over 5 years ago in reply to glennvanderveer

    Thank for your input.

     

    I have developed a routine that results in a LED2 flash that simulates a strobe. Varying the on and off times gives me the strobe effect I was looking for. When the routine is called, using my programming skills, the strobes either flash but the other LED's don't change or all the LEDs light up and nothing after that.

     

    House  isolation gives me the time to keep programming. Keep the suggestions coming.

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Cancel
  • glennvanderveer
    glennvanderveer over 5 years ago in reply to colporteur

    Try looking here for hints on how to use a timer:  https://www.geeksforgeeks.org/timer-objects-python/

     

    Is this what you want to do:

     

    LED1 on

    LED2 start flashing

    LED3 on, LED2 keep flashing

    LED4 on, LED2 keep flashing

    <time passess>LED2 keep flashing

    LED4 off, LED2 keep flashing

    LED3 off, LED2 keep flashing

    LED2 off, LED2 stop flashing

    LED1 off, LED2 still off

    repeat...

    • Cancel
    • Vote Up +1 Vote Down
    • Sign in to reply
    • Cancel
  • balearicdynamics
    balearicdynamics over 5 years ago in reply to glennvanderveer

    Probably, this is the most elegant and efficient solution. The possible alternative I see is managing interrupts chained so every state set to a different state in the others but this is tricky and not interesting in this case. A real alternative, instead, at least in my opinion, is creating a dictionary in Python collecting every change in a different boolean variable. Then a single function will set/reset the LEDs on/off as well as the motor, sound, and any other part that should be included in the animation. This optimizes the code and makes easier to change the pattern of the animation.

    In the main infinite cycle while true if using a json file with different animation patterns these can be randomly looped to get a more interesting effect.

     

    Enrico

    • Cancel
    • Vote Up +1 Vote Down
    • Sign in to reply
    • Cancel
  • colporteur
    colporteur over 5 years ago in reply to balearicdynamics

    Sorry M, you're going to have to dummy down your response for me to process. I'm the dummy:) I'm inputting at the rate of a paper tape reader punch and your outputting at the rate of SCSI 2 interface.

     

    I see some benefit to the concept of "Then a single function will set/reset the LEDs on/off as well as the motor, sound, and any other part that should be included in the animation." Understand the goal is to integrate the three components of animation, lights, sound and motions is important.  Unfortunately, I don't have the knowledge level to extrapolate what I need to do to accomplish this.

     

    I'm stuck on the simple concept of concurrency. Two tasks operating independently. On and off LED's and LED strobe on and LED strobe off. How do I do that?

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Cancel
  • colporteur
    colporteur over 5 years ago in reply to glennvanderveer

    Yes V Squared the additional commentary in the sequence is correct! Your additional commentary enhances to detail of what I am trying to accomplish.

     

    The pilots are in the helicopter running through a startup checklist. More than one thing happen at the same time. Lights will come on solid and some will flash. engines will start later generating sound and motor will engage rotors to turn.. The viewer on the outside just sees lights, hears engines and witnesses motion of the blades.

     

    My goal is to create this sequence using a Pi running python.

    • Cancel
    • Vote Up +1 Vote Down
    • Sign in to reply
    • Cancel
  • dougw
    dougw over 5 years ago in reply to colporteur

    Your problem could be handled with concurrent processes and it seems simple enough that you have a few things that might be independently occurring, but when you dive into implementing concurrency in a computer, it rapidly becomes a very complex topic. I doubt it could be distilled down to a paragraph of advice that would avoid a big learning curve.

    If you want to describe your problem a bit more theoretically than just the mechanics of loops, you could look into state machines. This problem can be described as a system that has different states at different times and the states follow a sequence. At any given time some, things are on and others are off - that defines the state of the system at that time. The loop counter we mentioned above is a way to implement a state machine. Every quarter second the system enters a new state. You just need to decide what needs to be on and what needs to be off in each quarter second.

    • Cancel
    • Vote Up +1 Vote Down
    • Sign in to reply
    • Cancel
  • glennvanderveer
    glennvanderveer over 5 years ago in reply to colporteur

    So this is what I whipped up quickly.  I have not tested or compiled this, but it works great in my head...image

    import threading
    import RPi.GPIO as GPIO
    
    
    def LED2_Blinker():
    if GPIO.input (LED2_PIN): #read teh led2 pin and if it is high, set it low
    GPIO.output (LED2_PIN, GPIO.LOW)
    else: #was not high, set it so...
    GPIO.output (LED2_PIN,GPIO.HIGH)
    
    LED1_PIN = XX #change XX to be proper pin number on PI
    LED2_PIN = XX #change XX to be proper pin number on PI
    LED3_PIN = XX #change XX to be proper pin number on PI
    LED4_PIN = XX #change XX to be proper pin number on PI
    
    
    GPIO.setup (LED1_PIN, GPIO.OUT)
    GPIO.setup (LED2_PIN, GPIO.OUT)
    GPIO.setup (LED3_PIN, GPIO.OUT)
    GPIO.setup (LED4_PIN, GPIO.OUT)
    
    
    #set all pins low to start....
    GPIO.output (LED1_PIN,GPIO.LOW)
    GPIO.output (LED2_PIN,GPIO.LOW)
    GPIO.output (LED3_PIN,GPIO.LOW)
    GPIO.output (LED4_PIN,GPIO.LOW)
    
    
    #setup the timer.  Number is for amount of time between timer activating...
    timer = threading.Timer(0.25,LED2_Blinker)
    
    
    # and now the looping sequence...
    while True:
    GPIO.output (LED1_PIN,GPIO.HIGH)
    time.sleep(3)
    timer.start() #starts the timer so that LED 2 will blink automagically
    GPIO.output (LED3_PIN,GPIO.HIGH)
    time.sleep(3)
    GPIO.output (LED4_PIN,GPIO.HIGH)
    time.sleep(3)
    #done startup sequence...
    GPIO.output (LED4_PIN,GPIO.LOW)
    time.sleep(3)
    GPIO.output (LED3_PIN,GPIO.LOW)
    time.sleep(3)
    timer.cancel() #stops the tiemr from firing until restarted...
    GPIO.output (LED2_PIN,GPIO.LOW) #ensure that LED2 is off (just in case)
    GPIO.output (LED1_PIN,GPIO.LOW)
    time.sleep(3)

     

    This should repeat forever, until you power it off...

    • Cancel
    • Vote Up +1 Vote Down
    • Sign in to reply
    • Cancel
  • balearicdynamics
    balearicdynamics over 5 years ago in reply to glennvanderveer

    I have just a doubt. The timer should be started inside the loop?

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Cancel
Reply
  • balearicdynamics
    balearicdynamics over 5 years ago in reply to glennvanderveer

    I have just a doubt. The timer should be started inside the loop?

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Cancel
Children
  • glennvanderveer
    glennvanderveer over 5 years ago in reply to balearicdynamics

    I don't think there is anything wrong with starting a timer in a loop because LED2 can't start blinking until after LED1 is has been on for 3 seconds.  The timer was setup before the while loop started, so when the timer expires/fires, it will run the LED2_Blinker routine and then exit and wait for another timeout.  This way returns the control back to the main while loop so it can run again...

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Cancel
element14 Community

element14 is the first online community specifically for engineers. Connect with your peers and get expert answers to your questions.

  • Members
  • Learn
  • Technologies
  • Challenges & Projects
  • Products
  • Store
  • About Us
  • Feedback & Support
  • FAQs
  • Terms of Use
  • Privacy Policy
  • Legal and Copyright Notices
  • Sitemap
  • Cookies

An Avnet Company © 2025 Premier Farnell Limited. All Rights Reserved.

Premier Farnell Ltd, registered in England and Wales (no 00876412), registered office: Farnell House, Forge Lane, Leeds LS12 2NE.

ICP 备案号 10220084.

Follow element14

  • X
  • Facebook
  • linkedin
  • YouTube