le festoche de la bd à amiens

Context : Participating to the local Comics festival

Each year, Our city hosts a very famous Comics Festival

This year, we have the opportunity to participate to the construction of an exhibit on a comic from Steve Baker, named Bots.

Steve baker

We proposed to take one device from the Bots universe and make it work : a badge automatic disposer

Machine : The badge disposer

Bots Badge disposer

What it should do

  • Ability to enter a four digit numeric code,
  • Automatic “take” on one badge in a box,
  • Deposit on an accessible area for the user.

dispatch of tasks

on this assignment, we are two students (and one intructor)

  • Adrien will do the “taking” part and choosed to make a Delta robot,
  • Benjamin will do the Frame, Head and & mechanical “fun additions”,
  • Instructor Jean-Baptiste HEREN will do the Keypad & general help on programming.

Keypad

We could have bought the keypad but the subject and our aim to make almost anything drived us in a custom “keypad.44”.

The keypad uses a typical “multiplexing” on input, based on a simple principle :

  • rows are inputs
  • columns are outputs
  • each switch connects is column to row

switch matrix

keypad.44.board

And here is the soldered board (I initially forgot the pull-down resistors for the inputs but it was easy to add because of the GND connected plan.)

keypad.44.board.soldered

The program loops and actvate each column to check if one input is active. Its goes fast enought to detect if one key is active.

/*
2019 - Jean-Baptiste HEREN
LA MACHINERIE
created for For keypad.44 board
*/

#include <Arduino.h>
#include <SoftwareSerial.h>

//LED -> PA5
#define LED_PIN 5
//OUTA -> PA4
#define OUTA_PIN 6
//OUTB -> PA3
#define OUTB_PIN 7
//OUTC -> PA2
#define OUTC_PIN 8

//IN1 -> PB2
#define IN1_PIN 2
//IN2 -> PB1
#define IN2_PIN 1
//IN3 -> PB0
#define IN3_PIN 0
//IN4 -> PA7
#define IN4_PIN 3

//RX -> PA0
#define RX_PIN 10
//TX -> PA1
#define TX_PIN 9


SoftwareSerial mySerial(TX_PIN, RX_PIN); // RX, TX
const byte ROWS = 4; //four rows
const byte COLS = 3; //three columns
char keys[ROWS][COLS] = {
  {'7','8','9'},
  {'4','5','6'},
  {'1','2','3'},
  {'#','0','*'}
};
byte rowPins[ROWS] = {2, 1, 0, 3}; //connect to the row pinouts of the keypad
byte colPins[COLS] = {6, 7, 8}; //connect to the column pinouts of the keypad
char key = '0';
char code[3] = "0000";
// char solution[3] = "6666";
char position = 0;
boolean keyChanged = false;
boolean keyCleared = false;

// serial Input
char val;
int intval = 0;
char rx_buf[16];
int i_rx=0;


// Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );

// 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_PIN, OUTPUT);
  pinMode(OUTA_PIN, OUTPUT);
  pinMode(OUTB_PIN, OUTPUT);
  pinMode(OUTC_PIN, OUTPUT);
  pinMode(IN1_PIN, INPUT);
  pinMode(IN2_PIN, INPUT);
  pinMode(IN3_PIN, INPUT);
  pinMode(IN4_PIN, INPUT);
  // setup columns
  digitalWrite(colPins[0], LOW);
  digitalWrite(colPins[1], LOW);
  digitalWrite(colPins[2], LOW);



  digitalWrite(LED_PIN, HIGH);   // turn the LED on (HIGH is the voltage level)
  // mySerial.println("pouet");
  delay(1000);                       // wait for a second
  digitalWrite(LED_PIN, LOW);    // turn the LED off by making the voltage LOW
  delay(1000);

  // Open serial communications and wait for port to open:
  mySerial.begin(9600);
  // mySerial.println("Hello, world?");
}

// the loop function runs over and over again forever
void loop() {

  char column = 0;
  char row = 0;

  // keyChanged = false;
  keyCleared = true;

  if (mySerial.available() > 0) {
    intval = mySerial.read();
    val = (char) intval;
    rx_buf[i_rx++] = val;
    if (val == '\n' || val == '\r') {
       mySerial.write(rx_buf, i_rx);
       i_rx = 0;
     }
  }

  for(column=0 ; column < COLS ; column++){
    digitalWrite(colPins[column], HIGH);
    for(row=0; row < ROWS; row++){
      if( digitalRead(rowPins[row]) == HIGH){
        digitalWrite(LED_PIN, HIGH);
        key = keys[row][column];
        keyChanged = true;
        keyCleared = false;
        while (digitalRead(rowPins[row]) == HIGH) {
           delay(100);
        }
         digitalWrite(LED_PIN, LOW);
        break;
      }
      if(keyChanged) break;
    }
    digitalWrite(colPins[column], LOW);
  }

  if (keyChanged && keyCleared) {
     code[position] = key;
     mySerial.println(key);
     keyChanged = false;
     if (position >= 3) {
       if (strncmp(code,  "6666", 4) == 0 ) {
         mySerial.println("start");
       } else {
         mySerial.println("fail");
         mySerial.println(code);
       }
       position = 0;
    } else {
      position++;
    }
  }
}