Thursday, May 15, 2025

Material Master

 Material Measurement Device


Materials




Display will need 2(3)/5 of the pinouts. "SDA on pad 0 and SCL on pad 1." Since we are going for low power, I'll need a transistor to control the power. This drawing is wrong: 
    "Unique pad capabilities Digital #0 / A2  - this is connected to PA08 on the ATSAMD21. This pin can be used as a digital I/O with selectable pullup or pulldown, analog input (use 'A2'),  PWM output, and is also used for I2C data (SDA) Digital #1 / A0  - this is connected to PA02 on the ATSAMD21. This pin can be used as a digital I/O with selectable pullup or pulldown, capacitive touch, analog input (use 'A0'),  and true analog (10-bit DAC) output. It cannot be used as PWM output. Digital #2 / A1  - this is connected to PA09 on the ATSAMD21. This pin can be used as a digital I/O with selectable pullup or pulldown, analog input (use 'A1'),  PWM output, and is also used for I2C clock (SCL), and hardware SPI MISO Digital #3 / A3  - this is connected to PA07 on the ATSAMD21. This pin can be used as a digital I/O with selectable pullup or pulldown, analog input (use 'A3'),  capacitive touch, PWM output, and is also used for UART RX (Serial1 in Arduino), and hardware SPI SCK Digital #4 / A4  - this is connected to PA06 on the ATSAMD21. This pin can be used as a digital I/O with selectable pullup or pulldown, analog input (use 'A4'),  capacitive touch, PWM output, and is also used for UART TX (Serial1 in Arduino), and hardware SPI MOSI"

Battery display:
I'll need to create a voltage divider that scales down the battery's max 4.2V:
Battery + (4.2V max) ---- R1 (100k) ----+---- R2 (330k) ---- GND
                                        |
                                        +----> Trinket analog input pin (e.g., A1(Pad 2)
This will result in a max battery reading of 3.22V. It will use minimal current:
I=430k4.29.8μA
"All of the I/O pins can be used for 12-bit analog input" means I'll get values from 0 to 4095. The voltage divider reduced the reading to 76.7% of the actual voltage:
Vout=Vbat×R1+R2R2=Vbat×100k+330k330k=Vbat×0.767

Pseudocode, but insert real values of R1 & R2 from DMM:
const int analogPin = A1;  // ADC pin
const float R1 = 100000.0; // 100k nominal 
const float R2 = 330000.0; // 330k nominal
const float ADC_MAX = 4095.0;
const float V_REF = 3.3;

void setup() {
  Serial.begin(115200);
  analogReadResolution(12);  // 12-bit resolution for Trinket M0
}

void loop() {
  int adcValue = analogRead(analogPin);
  
  // Convert ADC to voltage at divider output
  float V_out = (adcValue / ADC_MAX) * V_REF;

  // Calculate battery voltage
  float V_bat = V_out * (R1 + R2) / R2;

  Serial.print("ADC: ");
  Serial.print(adcValue);
  Serial.print("  V_out: ");
  Serial.print(V_out, 3);
  Serial.print(" V  Battery Voltage: ");
  Serial.print(V_bat, 3);
  Serial.println(" V");

  delay(1000);
}

Hall Effect Sensor:
Testing with 5V, I got a sense distance of around 2.5mm. This might have to be embedded in the wall of a main body with magnets very near in the outer ring. Although it looks like I was testing it incorrectly. From the datasheet: "The UA package is south pole active: Applying a south magnetic pole greater than BOP facing the branded side of the package switches the output low."

No comments:

Post a Comment