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
Data Conversion
  • Challenges & Projects
  • Project14
  • Data Conversion
  • More
  • Cancel
Data Conversion
Blog Micro Servo Tester #2 : Now With OLED Display and Button
  • Blog
  • Forum
  • Documents
  • Events
  • Polls
  • Files
  • Members
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
Join Data Conversion to participate - click to join for free!
  • Share
  • More
  • Cancel
Group Actions
  • Group RSS
  • More
  • Cancel
Engagement
  • Author Author: dubbie
  • Date Created: 6 Mar 2021 2:23 PM Date Created
  • Views 1382 views
  • Likes 8 likes
  • Comments 2 comments
  • push button
  • micro servo tester
  • oled display
  • dataconverch
Related
Recommended

Micro Servo Tester #2 : Now With OLED Display and Button

dubbie
dubbie
6 Mar 2021

I have made some progress with my combined servo tester and pulse generator project. I am happy with the servo tester part so I have decided to add an OLED display (128 x 64) and a button to select different modes. The Servo Tester will be the first mode and the second mode I want to add will be a pulse generator. At present I have not written the code for the Pulse Generator but I now have the display working and the button to change between modes.

 

The revised circuit diagram is show below. I have just added a push-to-make button on D3 for mode selection and a 128x64 OLED display (SDA on A4 and SCL on A5). An updated circuit diagram is shown below.

 

image

 

The display is Adafruit compatible so I just used their libraries. I have not used button inputs on my projects for a very long time so it was a challenge to get that working. Identifying how the debounce would work and then how to use it to select the mode. I now have an infinite while statement inside the main loop, which will just cycle sequentially through the modes available. At present there are only have two modes: Servo Tester and Pulse Generator, but it would be easy to add further modes, perhaps such as a DVM. The main loop part of the programme is listed below.

 

void loop(void)

{

 

int width;

int freq;

int modeselect;

int newmode;

 

width = 0;

freq = 0;

modeselect = 1; // Servo tester

newmode = 1;    // Used to read button

 

Serial.println("Servo Motor Tester " );

Serial.println("Dubbie Dubbie : Just for Fun " );

Serial.println(" 5th Feb'21 ");

Serial.println();

 

  display.clearDisplay();  // Clear the display so we can refresh

  display.setCursor(0,10);  // Bottom left

  display.println("Dubbie Dubbie ");

  display.println("Combined ");

  display.println("Servo Tester and ");

  display.println("Pulse Generator ");

  display.display();  // This outputs to the screen

 

  delay(1500);

  digitalWrite(ledblue, HIGH);   // Shows it's working

  delay(500);

  digitalWrite(ledblue, LOW);  

 

while(1)

  {

    servotestermode();

    pulsegeneratormode();

  } /* while */

} /* loop */

 

void mydisplaywidth(void)

 

{

int pulsevalue;

pulsevalue = 0;

  display.setCursor(80, 50); // Output the pulse width - bottom right

  display.fillRect(80, 50, 45, 8, 0); // Clear previous value

  pulsevalue = analogRead(adcwidth);

  display.setCursor(80, 50); // Output the pulse width - bottom right   

  display.print(pulsevalue);

  display.print(" us");

  display.display();

} /* mydisplaywidth */

 

bool buttonpress(int buttonselect)

 

{

int buttonvalue;

buttonvalue = 0;

 

  buttonvalue = digitalRead(buttonselect);

  if (buttonvalue > 0)

    {

      return(false);

    }

  else

    {

      do

        {

          delay(20); // 20 ms debounce delay  // press debounce

        } while (digitalRead(buttonselect) < 1);

      do

        {

          delay(20); //20 ms debounce delay  // release debounce

        } while (digitalRead(buttonselect) < 1);

      return(true);

    } /* if */

} /* buttonpress */

 

void servotestermode(void)

 

{

int pwidth;

pwidth = 0;

 

  display.clearDisplay();  // Clear the display so we can refresh

  display.setCursor(0,50);  // Bottom left

  display.println("Servo Tester ");

  while (!buttonpress(button))

    {

      digitalWrite(testservo, HIGH);

      delayMicroseconds(200);       // Start of the 1 ms pulse

      delayMicroseconds(pwidth);     // Makes up the rest of the pulse

      digitalWrite(testservo, LOW);

      Serial.println(pwidth);

      pwidth = analogRead(adcwidth); //Assumes 100 us conversion time

      pwidth = pwidth * 2;

      mydisplaywidth();

      delay(18); // The rest of the pulse   

    } /* while */

} /* servotestermode */

 

void pulsegeneratormode(void)

 

{

  while (!buttonpress(button))

    {

      display.clearDisplay();  // Clear the display so we can refresh

      display.setCursor(0,25);  // Middle left

      display.println("Pulse Generator ");

      display.display();  // This outputs to the screen          

    } /* while */ 

}

 

After spending a couple of days trying to get the push button and debounce to work I was pleased when it all came together this morning, as illustrated in the following video.

 

You don't have permission to edit metadata of this video.
Edit media
x
image
Upload Preview
image

 

All I have to do now is write the code for the pulse generator and if time permits, create some sort of 3D printed box, or possibly buy a case.

 

Dubbie

  • Sign in to reply

Top Comments

  • DAB
    DAB over 4 years ago +3
    Nice update. DAB
  • three-phase
    three-phase over 4 years ago

    Good to see the project coming along Dubbie.

     

    Kind regards

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • DAB
    DAB over 4 years ago

    Nice update.

     

    DAB

    • Cancel
    • Vote Up +3 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