Week 09 | Input Devices
This week's assignment is to add a sensor to a microcontroller board that we have designed and read it.
Things I did for this week:
- Design and make a 3-axis accelerometer module for measuring rotation and acceleration
- Tap into the design for a digital hourglass for output week based on this week's input device
- Remade my site using mkdocs
I have worked with off-the-shelf sensor module a lot before. So for this week I specifically want to learn how to design and make a sensor device from mere components.
Design a digital hourglass
I ran into this fun digital hourglass project years ago and still find it one of my favorite DIY project. So for these two weeks of input and output devices, I want to make one by myself with my own version of pcb.
After checking the documentation, I found the main components the project used are:
- Microcontroller
- Adafruit Analog Accelerometer: ADXL335
- Max7219 8*8 led matrix
I ordered the HiLetgo Max7219 8*8 led matrix module on Amazon, however I could not find any specs about its sizes and diameters other than W, L, H, anywhere online, so to know the distance between it's pins, I can only wait to measure by myself later. While waiting for the moduel to come, I decided to start with the design of an accelerometer breakout first for the input device week.
Design an accelerometer breakout board
I referred to Claire's blog from last year's input device week to understand how to make an accelerometer breakout board based on the ADXL 343 chip.
First I took a look at ADXL 343's datasheet.
Unfortunately I couldn't understand completely how to wire the pins of the chip to make it function, I need to figure that later with TAs, but for the time being, I just "copied" what claire did last year. I made the traces and size as tight as possible to explore how tiny the breakout board can be since the ADXL 343 chip itself is super tiny. So here are the schematic and pcb design from KiCAD:
With the traces down, I gave my pcb an outline and sent my files over to the miling machine in Quincy' studio.
Milling
This is worth a seperate section since I finally figured out how to mile on quincy's machine step by step thx to Lindong! The procedures are:
- Get Lindong's Png2ml.js file, creative a folder for it with two subfolders inside named "data" and "receipts"
- Place the exported png files into data folder
- Run Png2ml.js in terminal with Node: node png2rml.js data/input
- Specify x, y offsets by manual measure: node png2rml.js data/input "offset_x_in:8,clr_iters:4"
- Get generated results from data folder (3 files), upload results to http://10.1.10.179:8888 , the files will be sent and downloaded to studio’s laptop
- Open VPanel for MDX-50. Select "Cut" and firstly add toolX file for callibration
- Check if the test mile goes well, if not adjust the corresponding parameter (adjust by 0.001). Repeat several times if necessary.
And the milling result come out great! It is super cute and tiny.
Programming
#include <Wire.h>
#include <Adafruit_Sensor.h>
#include <Adafruit_ADXL343.h>
#define ADXL343_SCK 13
#define ADXL343_MISO 12
#define ADXL343_MOSI 11
#define ADXL343_CS 10
/* Assign a unique ID to this sensor at the same time */
/* Uncomment following line for default Wire bus */
Adafruit_ADXL343 accel = Adafruit_ADXL343(12345);
/* NeoTrellis M4, etc. */
/* Uncomment following line for Wire1 bus */
//Adafruit_ADXL343 accel = Adafruit_ADXL343(12345, &Wire1);
/* Uncomment for software SPI */
//Adafruit_ADXL343 accel = Adafruit_ADXL343(ADXL343_SCK, ADXL343_MISO, ADXL343_MOSI, ADXL343_CS, 12345);
/* Uncomment for hardware SPI */
//Adafruit_ADXL343 accel = Adafruit_ADXL343(ADXL343_CS, &SPI, 12345);
void displayDataRate(void)
{
Serial.print ("Data Rate: ");
switch(accel.getDataRate())
{
case ADXL343_DATARATE_3200_HZ:
Serial.print ("3200 ");
break;
case ADXL343_DATARATE_1600_HZ:
Serial.print ("1600 ");
break;
case ADXL343_DATARATE_800_HZ:
Serial.print ("800 ");
break;
case ADXL343_DATARATE_400_HZ:
Serial.print ("400 ");
break;
case ADXL343_DATARATE_200_HZ:
Serial.print ("200 ");
break;
case ADXL343_DATARATE_100_HZ:
Serial.print ("100 ");
break;
case ADXL343_DATARATE_50_HZ:
Serial.print ("50 ");
break;
case ADXL343_DATARATE_25_HZ:
Serial.print ("25 ");
break;
case ADXL343_DATARATE_12_5_HZ:
Serial.print ("12.5 ");
break;
case ADXL343_DATARATE_6_25HZ:
Serial.print ("6.25 ");
break;
case ADXL343_DATARATE_3_13_HZ:
Serial.print ("3.13 ");
break;
case ADXL343_DATARATE_1_56_HZ:
Serial.print ("1.56 ");
break;
case ADXL343_DATARATE_0_78_HZ:
Serial.print ("0.78 ");
break;
case ADXL343_DATARATE_0_39_HZ:
Serial.print ("0.39 ");
break;
case ADXL343_DATARATE_0_20_HZ:
Serial.print ("0.20 ");
break;
case ADXL343_DATARATE_0_10_HZ:
Serial.print ("0.10 ");
break;
default:
Serial.print ("???? ");
break;
}
Serial.println(" Hz");
}
void displayRange(void)
{
Serial.print ("Range: +/- ");
switch(accel.getRange())
{
case ADXL343_RANGE_16_G:
Serial.print ("16 ");
break;
case ADXL343_RANGE_8_G:
Serial.print ("8 ");
break;
case ADXL343_RANGE_4_G:
Serial.print ("4 ");
break;
case ADXL343_RANGE_2_G:
Serial.print ("2 ");
break;
default:
Serial.print ("?? ");
break;
}
Serial.println(" g");
}
void setup(void)
{
Serial.begin(115200);
while (!Serial);
Serial.println("Accelerometer Test"); Serial.println("");
/* Initialise the sensor */
if(!accel.begin())
{
/* There was a problem detecting the ADXL343 ... check your connections */
Serial.println("Ooops, no ADXL343 detected ... Check your wiring!");
while(1);
}
/* Set the range to whatever is appropriate for your project */
accel.setRange(ADXL343_RANGE_16_G);
// accel.setRange(ADXL343_RANGE_8_G);
// accel.setRange(ADXL343_RANGE_4_G);
// accel.setRange(ADXL343_RANGE_2_G);
/* Display some basic information on this sensor */
accel.printSensorDetails();
displayDataRate();
displayRange();
Serial.println("");
}
void loop(void)
{
/* Get a new sensor event */
sensors_event_t event;
accel.getEvent(&event);
/* Display the results (acceleration is measured in m/s^2) */
Serial.print("X: "); Serial.print(event.acceleration.x); Serial.print(" ");
Serial.print("Y: "); Serial.print(event.acceleration.y); Serial.print(" ");
Serial.print("Z: "); Serial.print(event.acceleration.z); Serial.print(" ");Serial.println("m/s^2 ");
delay(500);
}