Skip to content

Hardware_Electronics Box (v3)

Elias Issa edited this page Sep 19, 2018 · 19 revisions

Background

v1 - The first electronics box was built around the arduino nano and received commands from the audio port of the tablet

v2 - The second electronics box was built around the redbearlabs nano and received commands via bluetooth low energy

v3 - This iteration of the electronics box returns to an arduino controller, this time the Leonardo, and communicates with the tablet using serial over usb

The latest electronics box is slightly larger than the previous versions but is also meant to have more flexibility by using the Arduino Leonardo. A PCB shield interfaces with the arduino and breaks out a couple analog lines (for interfacing sensors such as photodiodes) as well as a serial line (for rfid). The headers allow flexible testing on the remaining arduino pins. The pump circuit is the same as the original electronics including a prime toggle switch.

Parts

Arduino Leonardo with Headers (Sparkfun,Part# DEV-11286)

Arduino Stackable Header Kit (Sparkfun, PRT-11417)

Break Away Headers - Straight (Sparkfun, PRT-00116)

USB Female Type A SMD Connector (Sparkfun, PRT-09011) 3x

LED 5mm assorted 20-pack (Sparkfun, Part# 12062)

Diode 1N4001 1A 50V [(Allied Electronics, Part# 70015967)] (http://www.alliedelec.com/hvca-1n4001/70015967/) 2x

NTE128 Transistor [(Allied Electronics, Part# 70214874)] (http://www.alliedelec.com/nte-electronics-inc-nte128/70214874/)

180 ohm resistors (Amazon, Part# B0185FHGBM)

DC female jack Breadboard male 10-pack (Amazon, Part# B00R5C9AQQ)

Toggle Switch (DigiKey, Part# 432-1170-ND)

DC Power Cable Male, 5.5/2.1mm (Amazon, Part# B0054D80LE)

Female-to-Female Jumper Wires 4-inch & 8-inch (Amazon, Part# B01L5ULRUA)

Male-to-Male Jumper Wires 4-inch (Amazon, Part# B077N6HFCX)

PCB

The PCB was made in Eagle (free for academics) and produced by oshpark. Sparkfun has a number of useful tutorials for basic PCB design. Particularly relevant:

Once you have made the board, you can simply upload the .brd file to manufacture at oshpark in runs of 3,6,9,etc. Oshpark has fairly quick turnaround so that you should receive your boards in a week.

Here is the simple arduino leonardo shield that is the current design. A lot of the components were pulled from the sparkfun or adafruit libraries for eagle. This design uses a full copper ground plane on the top side of the board.

EAGLE SCHEMATIC

EAGLE BOARD

OSHPARK TOP

PCB ASSEMBLY

The best way to start is to attach the arduino headers first. Place the board upside down resting on the headers and solder on the bottom side of the board. As long as you pay attention to make sure the 4 headers are aligned before soldering, you should get a good fit of the shield to the Arduino. The same trick can be used to solder the 3 pin jumpers for 5V, 3V, and ground. You can insert them into the board and turn upside down, align, then solder.

Adding stackable headers

Add the USB connectors next, that way you have full access to soldering their small terminals before adding other components.

Adding USB connectors

Once the USB connectors are done, you can add the remaining components in any order you choose holding the DC jack to the penultimate step and the tall toggle switch to be the last component added.

Adding remaining components except DC jack and toggle switch

Completed boards

Once you have completed the board, program the arduino, and add it to your mkturk system. Here is what that looks like:

Complete system

Arduino Code

Before writing any code, you will need to create a Webusb-compatible version of the arduino sdk's serial library. The instructions for adding this library in arduino and configuring the Arduino Leonardo can be found at webusb arduino.

Below is working example code for the Arduino Leonardo. The arduino receives characters via serial over usb (character string encodes the pump on duration from the browser), and then triggers a digital line that turns on the pump for a specified amount of time.

#include <WebUSB.h>

WebUSB WebUSBSerial(1, "webusb.github.io/arduino/demos");

#define Serial WebUSBSerial

// Example 3 - Receive with start- and end-markers

const byte numChars = 32;
char receivedChars[numChars];
boolean newData = false;
const int pumpPIN=2;
const int pumpLEDPIN=7;
int pumpdur;

void setup() {
  pinMode(pumpPIN, OUTPUT);
  pinMode(pumpLEDPIN, OUTPUT);
  while (!Serial) {
    ;
  }
  Serial.begin(9600);
  Serial.println("<Arduino is ready> Sketch begins \r\n>");
  Serial.flush();
}

void loop() {
    recvWithStartEndMarkers();
    showNewData();
    turnOnPump();
}

void recvWithStartEndMarkers() {
    static boolean recvInProgress = false;
    static byte ndx = 0;
    char startMarker = '{';
    char endMarker = '}';
    char rc;
 
    while (Serial && Serial.available() > 0 && newData == false) {
        rc = Serial.read();

        if (recvInProgress == true) {
            if (rc != endMarker) {
                receivedChars[ndx] = rc;
                ndx++;
                if (ndx >= numChars) {
                    ndx = numChars - 1;
                }
            }
            else {
                receivedChars[ndx] = '\0'; // terminate the string
                recvInProgress = false;
                ndx = 0;
                newData = true;
            }
        }

        else if (rc == startMarker) {
            recvInProgress = true;
        }
    }
}

void showNewData() {
    if (newData == true) {
        Serial.print("This just in ... ");
        Serial.println(receivedChars);
        Serial.flush();
    }
}

void turnOnPump() {
  if (newData == true) {
    pumpdur = atoi(receivedChars);
    digitalWrite(pumpPIN,HIGH);
    digitalWrite(pumpLEDPIN,HIGH);
    delay(pumpdur);
    digitalWrite(pumpPIN,LOW);
    digitalWrite(pumpLEDPIN,LOW);
    newData = false;
    
    Serial.print("Pump triggered, dur=");
    Serial.print(pumpdur);
    Serial.flush();
  }
}

3D Printed Enclosure

We 3D printed a simple, custom-fitting enclosure with front panel cut-outs for cable connections. The stl surfaces for the box and lid can be used for 3d printing or you can use them as references for dimensioning your own enclosure.

CAD model

Assembled enclosure

https://playground.arduino.cc/Code/ID12

http://bildr.org/2011/02/rfid-arduino/

http://www.instructables.com/id/Reading-RFID-Tags-with-an-Arduino/

https://learn.sparkfun.com/tutorials/sparkfun-rfid-starter-kit-hookup-guide

https://www.arduino.cc/en/Tutorial/SoftwareSerialExample