Skip to content

Latest commit

 

History

History

Physical Computing

Physical computing

This section details the sensors employed by Mechamagnets, and code used to read the sensors.


Sensor List

Part Name Part Number Description Source
Linear Hall effect sensor A1324LUA-T Package: 3-SIP
Sensitivity : 5.0mV/G
Suitable for sensing 1/8in by 1/8in N48 neodymium magnets at a distance of ~ 5 to 10mm.
Digikey
Linear Hall effect sensor A1308KUA-1-T Package: 3-SIP
Sensitivity : 1.3mV/G
Suitable for sensing 1/4in by 1/16in N48 neodymium magnets at a distance of ~ 5 to 10mm.
Digikey


Custom PCBs

🚧 Under construction 🚧


Arduino / Processing code


mechamagnet_instrumentation folder

mechamagnet_instrumentation.ino Example Arduino sketch to read linear Hall effect sensors
in setup
Serial.begin(9600);
Initialize the serial communication which we will use in Processing to obtain the sensor readings
in loop
analogRead(analog_pin_number);
Read the sensor and return an integer based on the resolution of the ADC (10bit range = 0 - 1023).
Linear Hall effect sensors return the middle value (512 in the case of 10bit ADCs) when it does not pick up any magnetic field. The values deviate from the middle according to the strength and polarity of the magnetic field.
in loop
Serial.print(val);
Serial.print(" ");
Print a sensor reading to the serial port, and then a space character. The space is use to separate each sensor value.
in loop
Serial.println();
delay(25);
End the serial print with a line break. Processing will listen for this line break to determine when it has received a complete set of sensor readings. We inroduce a delay to avoid overloading Processing's buffer and to ensure minimal delay between sensor reading and visualization.



mechamagnet_instrumentation.pde Example Processing visualization sketch
Objects
MMButton
MMKnob
MMStick
Button: push buttons, switches etc.
Knob: knobs, dials, rotary encoders etc.
Stick: joystick, thumbsticks etc.

Creating an object First, declare object, e.g.
MMButton button

Then, in setup, define object, e.g.
button = new MMButton("BUTTON 1", 0, false, 0.5, 50, 50, 80, 200);

Updating and displaying object in draw loop

update object with serial data, e.g.
button.update(SERIAL_DATA);

then display object
button.display();

Object arguments: MMButton
MMButton(name, index, inverted, threshold, xpos, ypos, w, h)
name (String): object name, also used to name calibration CSV
index (int): index of value from SERIAL_DATA to read
inverted (boolean): TRUE—values decrease when button is pressed
threshold (float): from 0-1, actuation point of button
xpos, ypos, w, h (float): x position, y position, width and height of visualization.

Object arguments: MMKnob
MMKnob(name, index0, index1, inverted, xpos, ypos, d)
name (String): object name, also used to name calibration CSV
index0 (int): first index of value from SERIAL_DATA to read
index1 (int): second index of value from SERIAL_DATA to read
inverted (boolean): TRUE—flip first sensor reading
xpos, ypos, d (float): x position, y position and diameter of visualization.

if visualization rotates in the opposite direction, try switching index0 and index1.

Object arguments: MMStick
MMStick(name, index0, index1, inverted0, inverted1, xpos, ypos, size)
name (String): object name, also used to name calibration CSV
index0 (int): first index of value from SERIAL_DATA to read
index1 (int): second index of value from SERIAL_DATA to read
inverted0 (boolean): TRUE—flip first sensor reading
inverted1 (boolean): TRUE—flip second sensor reading
xpos, ypos, size (float): x position, y position and size of visualization.

if visualization axes are swapped, switch index0 and index1.

Calibration method Each object has its own calibration method(s). They can be accessed through the GUI button(s) under each individual visualizations. Calibrated values are stored in a CSV file located in the sketch's "data" folder, and named after the objects name field. When the sketch starts, it will attempt to find and load the object's calibration file; if the file cannot be found, a new file will be created.

MMButton fields val (float array): an array with the last x number of sensor readings.
val[0] (float): most recent sensor reading.
min (float): minimum sensor value.
max (float): maximum sensor value.
threshold (float): button actuation point (0-1).
threshold_val (float): button actuation point between min and max values.

MMKnob fields val (PVector): an array of 2D vectors with the last x number of sensor readings.
val[0] (PVector): Most recent sensor reading.
val[i].x (float): first sensor reading.
val[i].y (float): second sensor reading.
angle (float): knob's angle of orientation.
center_point (PVector): center of rotation.
angle_offset (float): knob's start of rotation.

MMStick fields val (PVector): an array of 2D vectors with the last x number of sensor readings.
val[0] (PVector): Most recent sensor reading.
val[i].x (float): first sensor reading.
val[i].y (float): second sensor reading.
start (PVector): minimum sensor readings.
end (PVector): maximum sensor readings
center_point (PVector): stick's center point.