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
DIY Test Instrumentation
  • Challenges & Projects
  • Project14
  • DIY Test Instrumentation
  • More
  • Cancel
DIY Test Instrumentation
Blog Project14 | DIY Test Instrumentation: Build Your Own Test Instrumentation!: Automated Cable Tester v
  • Blog
  • Forum
  • Documents
  • Members
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
Join DIY Test Instrumentation to participate - click to join for free!
  • Share
  • More
  • Cancel
Group Actions
  • Group RSS
  • More
  • Cancel
Engagement
  • Author Author: phoenixcomm
  • Date Created: 1 Jul 2021 9:51 PM Date Created
  • Views 1132 views
  • Likes 5 likes
  • Comments 2 comments
  • mcp23017
  • arduino mega 2560
  • diytestinstrumentationch
  • cable tester.
  • rs-485
  • full duplex
  • i2c communication
  • i2c expander
Related
Recommended

Project14 | DIY Test Instrumentation: Build Your Own Test Instrumentation!: Automated Cable Tester v

phoenixcomm
phoenixcomm
1 Jul 2021
image

U.S. Air Force Senior Master Sgt. Mike Chandler, 142nd Maintenance
Squadron out of the Portland Air National Guard, displays his avionics
Electronics Systems Test Station (ESTS) cable tester that he designed

Photo by: Airman First Class Andrew Kobialka

image

image

As my I2C parts count is growing out of control, I have decided to split my work between two Arduinos, one will control the six (6) note 1 MCP23017 while the other will control my dual 2X 0.96" I2C Serial 128X64 LED OLED  displays, as they are mounted in a nice stand. This Arduino will also have a rotary encoder to select from the menu and this will be under interrupt control. I will most likely use the SPI bus converted to RS-485 for intercommunications. I found the following code for rotary encoder interrupts from the web.  I will use this as a starting point only. The Arduino should be mounted in a plastic box on the rear or bottom of the unit.  Each of the 2 parts of the system will have 2 RS-285 modules shown below. One of the monitors will show the list of cables to select for the test.

The second monitor will show the status of the tests. The test consists of several phases.

/*
* Bas on Tech - Rotary Encoder and Interrupts
* This course is part of the courses on https://arduino-tutorials.net
* 
* (c) Copyright 2018-2019 - Bas van Dijk / Bas on Tech
* This code and course is copyrighted. It is not allowed to use these courses commercially
* without explicit written approval
*
* YouTube: https://www.youtube.com/c/BasOnTech
* Facebook: https://www.facebook.com/BasOnTechChannel
* Instagram: https://www.instagram.com/BasOnTech
* Twitter: https://twitter.com/BasOnTech
*
* ---------------------------------------------------------------------------
*
* More info about the Rotary Encoder:
* https://en.wikipedia.org/wiki/Rotary_encoder
*
* PIN CONNECTIONS
*
* GND --> GND black
* + --> 5V red
* SW --> 12 yellow
* DT --> 3 green (data)
* CLK --> 4 blue (clock)
*
*/
int switchPin = 12;  // button pin
int switchState = HIGH;  // button value
int pinA = 4;  // Rotary encoder Pin A
int pinB = 3;  // Rotary encoder Pin B
int pinAstateCurrent = LOW;  // Current state of Pin A
int pinAStateLast = pinAstateCurrent;  // Last read value of Pin A
void setup() {
  Serial.begin (9600);  // Initialise the serial monitor
  pinMode (switchPin, INPUT_PULLUP);  // Enable the switchPin as input with a PULLUP resistor
  pinMode (pinA, INPUT);  // Set PinA as input
  pinMode (pinB, INPUT);  // Set PinB as input
  // Attach a CHANGE interrupt to PinB and execute the update function when this change occurs.
  attachInterrupt(digitalPinToInterrupt(pinB), update, CHANGE);
}
void loop() {
  // BUTTON
  switchState = digitalRead(switchPin);  // Read the digital value of the switch (LOW/HIGH)
  // If the switch is pressed (LOW), print message
  if (switchState == LOW) {
  Serial.println("Switch pressed");
  }
}
void update() {
  /* WARNING: For this example I've used Serial.println within the interrupt callback. The Serial
  * library already uses interrupts which could cause errors. Therefore do not use functions
  * of the Serial libray in your interrupt callback.
  */
  // ROTATION DIRECTION
  pinAstateCurrent = digitalRead(pinA);  // Read the current state of Pin A
  // If there is a minimal movement of 1 step
  if ((pinAStateLast == LOW) && (pinAstateCurrent == HIGH)) {
  if (digitalRead(pinB) == HIGH) {  // If Pin B is HIGH
  Serial.println("Right");  // Print on screen
  } else {
  Serial.println("Left");  // Print on screen
  }
  }
  pinAStateLast = pinAstateCurrent;  // Store the latest read value in the currect state variable
}
  1. All pins test that is to say end to end.
  2. pins are tested for shorts drive one
    pin at a time and read all pins
  3. At this time the only way to test for
    opens is test 1.

notes and updates*

  1. six (6) was added  July 1, 2021
  • Sign in to reply

Top Comments

  • Jan Cumps
    Jan Cumps over 4 years ago +1
    I used Another Interrupt Library THAT REALLY WORKS (the Encoder interrupts the processor and debounces like there is no tomorrow) . Available halfway this page: https://playground.arduino.cc/Main/RotaryEncoders…
  • phoenixcomm
    phoenixcomm over 4 years ago in reply to Jan Cumps

    Jan Cumps Jan, I don't know if I would call this interrupt-driven. In fact what this library does calls a timer every 1ms.  the above call is as listed.

     

     

    pinMode (pinA, INPUT);  // Set PinA as input  

    pinMode (pinB, INPUT);  // Set PinB as input   //
    Attach a CHANGE interrupt to PinB and execute the update function when this change occurs.attachInterrupt(digitalPinToInterrupt(pinB), update, CHANGE);

     

    void update() {

    // ROTATION DIRECTION

    pinAstateCurrent = digitalRead( pinA );

    if (( pinAStateLast == LOW ) && ( pinAstateCurrent == HIGH )) {

         if ( digitalRead(pinB) == HIGH ) {

             Serial.println( "Right" );   }

          else {   Serial.println( "Left" );     }   }

    pinAStateLast = pinAstateCurrent; }  // Store the latest read value in the currect state variable

    ~~Cris

    does it in 11 lines and only when you move the Encoder! so now call backs work.

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

    I used Another Interrupt Library THAT REALLY WORKS (the Encoder interrupts the processor and debounces like there is no tomorrow).

    Available halfway this page: https://playground.arduino.cc/Main/RotaryEncoders/

    • 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