Project log: More about the Arduino Uno + “reprap d1scount display” and “rrd smart adapter”. Rotary encoder button debouncing.

Continuing from the previous entry, I have completed the mapping of pins to the so-called rrd smart adapter. This board is meant for 3D printers of some kind but I am not using it for that purpose. I got it simply because it is a useful board for my purposes and my local shop had it in stock. Anyhow, here is the complete pinout. The indicated Arduino pins are not indicative of much, just what I am using for my application at the moment.

rrd adapter 2.png
The colors don’t mean anything in particular.

There are no pull-ups on the rotary pins, so you must declare them in AVR.

pinMode(PIN_ROTBTN, INPUT_PULLUP);
pinMode(PIN_ROTIN1, INPUT_PULLUP);
pinMode(PIN_ROTIN2, INPUT_PULLUP);

Unfortunately when trying to use the rotary encoder I get back a lot of signal bounce. This issue could have been avoided in hardware using some simple passives but they are missing on the board. On to finding a mitigation solution short of soldering some caps on there.

The solution is to add some debouncing to each pin, and to then go through a state transition table to filter out invalid moves. This works because the rotary encoder moves through a gray-code type phase system, with a new step is indicating by a transition back to phase 0 after going through the four phases. I used the library Bounce2 by Thomas Ouellet Fredericks to simplify a little bit, I would recommend the library for general button debouncing use.

#include <Bounce2.h>

Bounce bounce2 = Bounce();
Bounce bounce3 = Bounce();

int position = 0;
enum
{
  INVALID,
  CW,
  CCW,
};

uint8_t table[] = {0,1,2,0,2,0,0,1,1,0,0,2,0,2,1,0};

void setup() {
  bounce2.attach(3, INPUT_PULLUP);
  bounce3.attach(2, INPUT_PULLUP);
  bounce2.interval(10);
  bounce3.interval(10);
  
  Serial.begin(9600); // start the serial monitor link
  Serial.print("hello\n");
}

void loop(){
  static int previous = 0;

  bounce2.update();
  bounce3.update();

  // get current state.
  bool A = bounce2.read();
  bool B = bounce3.read();

  int current = (A << 1) | B;

  if (current != previous) {
    // state transition
    uint8_t direction = table[ (previous << 2) | current ];

    if (direction != INVALID) {

      if (direction == CW && current == 0) position++;
      if (direction ==CCW && current == 0) position--;

      previous = current;
  
      Serial.println(position);
    }
  }

out:
  return;
  
}
Posted in Uncategorized | Leave a comment

Project log: Arduino Uno + “reprap d1scount display”

The code is running on an Arduino Uno, wired up to the controller. This is a generic control board called the “RepRapDiscount Smart Controller” which can come in many different configurations, so ensure you know yours before doing anything.

To document how I have wired this up, here is a diagram. Obviously your mileage may vary. The display is a 4 lines x 20 chars running a generic HD44780 type controller, only available in 4-bit mode.


#include <Arduino.h>
#include <LiquidCrystal.h>


const int PIN_BUZZER = 9;

const int PIN_LCDDATA4 = 5;
const int PIN_LCDDATA5 = 4;
const int PIN_LCDDATA6 = 3;
const int PIN_LCDDATA7 = 2;
const int PIN_LCDE = 11;
const int PIN_LCDRS = 12;

// declare the LCD in parallel mode.
LiquidCrystal lcd(PIN_LCDRS, PIN_LCDE, PIN_LCDDATA4, PIN_LCDDATA5, PIN_LCDDATA6, PIN_LCDDATA7);

// the setup function runs once when you press reset or power the board
void setup()
{
  // initialize digital pin LED_BUILTIN as an output.
  pinMode(LED_BUILTIN, OUTPUT);
  
  // initialize buzzer as output.
  pinMode(PIN_BUZZER, OUTPUT);

  // initialize the LCD, number of columns and rows.
  lcd.begin(20, 4);
  lcd.print("hey whats up");
}

// the loop function runs over and over again forever
void loop()
{
  lcd.setCursor(1, 1);
  lcd.print(millis());
}
Posted in Uncategorized | 1 Comment

3D Print: Wooden Tower

Printed in Wood PLA filament.
Posted in Uncategorized | Leave a comment

Project Build #2

previous entry

Mounting the Motors

Now to have a mount for the NEMA-17 motors. I’m not quite sure yet how the axle should be positioned, so I have it going over the center of the frame contour.

Sketching a way to mount NEMA-17 to my frame.

A Fork in the Road

During assembly I have found that I really should have a sturdier frame. So I put everything on hold to redesign the frame and print in the ASA filament I acquired, my favorite material. There is a possibility of some warping. I really hope that doesn’t happen.

Posted in build-log | 1 Comment

Project Build #1

The Frame

Since I am printing the frame, I decided to split it in two logical parts: the top and the bottom that screw in together using standard M3 screws.

The lower half.

A while later, I had the top part.

The upper half.

During initial testing I found that the 10×10 dimension for the tubes is too weak, I will have to redesign this to use 20×20 tubes. I also found that the printing material should not be PETG, because of the nature of that material. PETG has a tendency to flex, and I want the frame to be really stiff in order not to interfere with accuracy of the head. So I will be reworking the frame in ASA filament, which I have had good luck printing in the past.

next entry

Posted in Uncategorized | 1 Comment