8. Electronics Design

Assignment

Group Assignment

Link to this week's group assignment

Capacitive Sensing with ATmega328p

As part of my final project, I think my synth will need an input device to be able to control the pitch of the final generated sound, so I decided to make a capacitive sensing boa rd that can use touching as input.

We have some ATmega328p in stock and since I have cut one board working with the DIP packaging, I decided to make one with the MLF package this time.

For the schematic I have 10 copper pads connecting to the digital pins 3 to 12 and all of them are connected to pin 2 through a 1MOhm resister. This will be the capacitive sensors that will be used. I also exposed the UART pins on pin 0 and pin 1, A4 and A5 for I2C communication and the SPI interface on pin 11 to 13 and reset for burning the bootloader wit h the external programmer. I also put a reset button and a LED on pin 13.

After adjusting some design rules, I finished the wiring and layout of all the components, the gaps between the pins of the chip is at the limit of the size of our end mill.

Then I cut the board and soldered the components, the small package is a bit challenging but I managed soldering anyway.

After soldering, the I uploaded some test code through the programmer, for some reason the bootloader was not working so I cannot use the UART to upload the program, the auto reset circuit on the reset pin seems fine and I couldn't find out what was the problem.

The program utilizes an Arduino library called capacitive sensor, it allows to use any two pins on the board to form a capacitive sensor between them. With the test programs I found that some of my capacitive input pins was not working. After measuring some connections on the board, and the resistance between some input pins and pin2, I found that the pins that were working have a lower resistance on the two ends of the 1Mohm resistor they were connected to, possibly due to they were connected in parallel with the internal resister inside the chip. As for the pins that were not working properly, they were measured to have 1Mohm resistor across the two sides of the resistor, indicating they were not connected to the chip.

(TODO: more images)

The pins were tested with the connection test with the multimeter, but they were still unconnected, the pins of the chips were too small to be tested directly on them with the pro be. After reflowing some of the pins with the soldering iron, the board was working properly.

test code (TODO: explain)

#include <CapacitiveSensor.h>

CapacitiveSensor pads[] = {
  {2, 3}, {2, 4}, {2, 5},
  {2, 6}, {2, 7}, {2, 8},
  {2, 9}, {2, 10}, {2, 11},
  {2, 12},
};
#define array_len(a) (sizeof(a)/sizeof*(a))

void setup() {
  Serial.begin(9600);
  pinMode(13, OUTPUT);
}

void loop() {
  unsigned long start = millis();
  bool touched = false;
  for (int i = 0; i < array_len(pads); ++i) {
    long val = pads[i].capacitiveSensor(30);
    Serial.print(i);
    Serial.print(": ");
    Serial.print(val);
    Serial.print("\t");
    if (val > 200) {
      touched = true;
      break;
    }
  }
  Serial.println();
  Serial.println(millis() - start);
  digitalWrite(13, touched);
}

Source files