element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • 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 & Tria Boards Community
    • Dev Tools
    • Manufacturers
    • Multicomp Pro
    • Product Groups
    • Raspberry Pi
    • RoadTests & Reviews
  • About Us
  • 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
      • Japan
      •  Korea (Korean)
      •  Malaysia
      •  New Zealand
      •  Philippines
      •  Singapore
      •  Taiwan
      •  Thailand (Thai)
      • Vietnam
      • 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
Sustain The World - Design Challenge
  • Challenges & Projects
  • Design Challenges
  • Sustain The World - Design Challenge
  • More
  • Cancel
Sustain The World - Design Challenge
Blog Waste Food Management  Blog #4  Program for Servo and User Interface
  • Blog
  • Forum
  • Documents
  • Polls
  • Files
  • Events
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
  • Share
  • More
  • Cancel
Group Actions
  • Group RSS
  • More
  • Cancel
Engagement
  • Author Author: wtos03
  • Date Created: 19 Aug 2020 11:02 AM Date Created
  • Views 447 views
  • Likes 3 likes
  • Comments 3 comments
  • 3d sensor
  • servo
  • waste food management
Related
Recommended

Waste Food Management  Blog #4  Program for Servo and User Interface

wtos03
wtos03
19 Aug 2020

This week I spend most of my time in programming for 3D sensor and Servo control. My development environment is Arduino.  You can go to https://github.com/Infineon/XMC-for-Arduino/wiki/Implementation-in-Arduino-IDE  for instruction on how to add XMC support for Arduino. After installing Arduino, you need to install 3D sensor library by going to Sketch—> Include Library —> Manage Libraries..  Search for TLV and you should found TLV493D-A1B6 by Infineon. If you cannot find the library. You need to install the Library by download at https://www.arduinolibraries.info/libraries/tlv493-d-a1-b6. Currently, I am using Arduino 1.8.10.

For Hardware prototype, I had been connected 5 LEDS and one Servo (MG996) to these ports

                 Pin Port                In Arduino Program

LED1          P2.15                  0

LED2          P2.14                  1

LED3          P1.0                    2

LED4          P1.1                    3

LED5          P1.8                    4

MG996       P2.12                  5

 

Note for MG996 servo. We can use 3.3 v for the signal line of the servo. However, if you change servo, you need to check the spec whether they can drive by 3.3 v signal or not.

I had been looking around on the internet for idea on how to program 3D sensor for knob control and I found one which is useful for me to quick start.

It is Multi-Functional Magnetic Knob for Consumer Electronics by Md.  Chair Alam at  https://www.hackster.io/taifur/multi-functional-magnetic-knob-for-consumer-electronics-006870 The project looks similar I need. So I take his concept and adapt the program to my own.

Concept to check 3D sensor used in the program.

1)  Check the Azimuth angle by using getAzimuth() library.

2) We need to multiply by 100  because the value is too small.

3) Get the magnetic field amount by using getAmount() library.

4) When you move knob, compare previous angle with current angle.

  o If it’s more than 20 mean move Forward.

  o If it’s less than  -20  mean move Backward.

5) At the same time compare magnetic field between previous measure and current measure.

  o  If it’s more than 60 mean Click happen.

We do need to adjust value when we really do the real control panel installation.  Now it’s just trial and error for these values.

 

Currently, Arduino Servo library is not supported for  XMC4700. So  I need to build simple  Servo control by myself by just sending PWM signal with 20 ms period ( Frequency 50 Hz).  The duty cycle will control the degree of Servo.

To calculate the duty cycle

1) We need to make sure that the Angle for servo within range  0- 180 degrees by using constrain function.

2) Map the angle to pulse width by Minimum pulse width = 540  and Maximum pulse width = 2000 (trial and error) Because I don’t have information on how duty cycle relates

to servo’s angle at this moments.

3) Send HIGH signal equal to pulse width and LOW signal equal to (20000 (20ms ) - HIGH period ) and loop until the servo reach position.

This is quick and dirty to control Servo.  The best way is to use PWM but I don’t know how to set PWM frequency in Arduino with XMC4700 yet. So this is interim solutions until I find better solutions.

 

The source code is on GitHub at  https://github.com/wtos03/WasteFoodMgmt

And this Video is my result of running the code

https://www.youtube.com/watch?v=--gjYTqpD3c&feature=youtu.be

 

In this video,  you will see when moving knob the LED will move from left to right and right to left depend on the position of the knob.  If the LED reaches the Last LED it will

go to the first LED again. However,  If you at the first LED you cannot move back anymore only forward is allowed. When you pull up and down the knob. The working LED will on and Servo will move. The knob is toggle state that means pull up/down once to on and again to off.

 

Next step to program for control DC Motor and create valve using Servo for  EM substance control.

  • Sign in to reply

Top Comments

  • rati89
    rati89 over 5 years ago +1
    Hey Wichai, great work so far! I also like that you are using lego! Btw, I want to mention, that there is a servo lib: https://github.com/Infineon/ServoC Check it out! BR Brew
  • dubbie
    dubbie over 5 years ago

    A nice switch concept.

     

    Dubbie

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • wtos03
    wtos03 over 5 years ago in reply to rati89

    Hi Brew,

    Thanks for the point out. I will look into it.

    Wichai

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • rati89
    rati89 over 5 years ago

    Hey Wichai,

     

    great work so far! I also like that you are using lego!

    Btw, I want to mention, that there is a servo lib: https://github.com/Infineon/ServoC

    Check it out! image

     

    BR

    Brew

    • Cancel
    • Vote Up +1 Vote Down
    • Sign in to reply
    • More
    • 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