Pi Battery Identifier

 The purpose of this project is to generate unique identifiers of batteries based on their magnetic properties. Potentially being able to do non destructive testing of batteries.

The current overly detailed process I use for testing my many lithium ion batteries is to use a smart charger to do Internal Resistance and True Capacity tests on an individual battery. Then the results are logged into a database to be used for trending over time. 


Raspberry Pi project

Project Parts List
ComponentPurposeRecommended Model / Source
SBC HubProcesses raw digital inputs, applies offset corrections, and logs text logs.Raspberry Pi 4 Model B (4GB or 8GB)
3D MagnetometerDetects magnetic flux density concurrently across the X, Y, and Z axes.MLX90393 3D Magnetic Sensor Board (or TLV493D)
Mini DisplayProvides real-time readouts of \(B_x, B_y, B_z\) vectors and signature logging state.Adafruit 128x64 OLED Display (SSD1306/I2C)
PrototypingConnects all components without soldering.Solderless Breadboard & Premium M-to-F / F-to-F Jumper Wires
Power SupplyEnsures reliable current without dropping voltage during active processing.
🗺️ Connection Diagram
Both the MLX90393 sensor and the OLED display run via I2C communication. Because I2C uses unique hardware addresses for each chip, you can chain both devices to the exact same physical pins (SDA and SCL) on the Raspberry Pi 4's 40-pin header.
       Raspberry Pi 4 GPIO Header
       +-----------------------+

       | Pin 2  (5V Power)     |=======> [VCC] MLX90393 Sensor Module
       | Pin 1  (3.3V Power)   |=======> [VCC] SSD1306 OLED Display
       | Pin 3  (SDA / GPIO 2) |==+====> [SDA] MLX90393  &  [SDA] OLED
       | Pin 5  (SCL / GPIO 3) |==|====> [SCL] MLX90393  &  [SCL] OLED
       | Pin 6  (GND)          |==|==+=> [GND] MLX90393  &  [GND] OLED
       +-----------------------+  |  |

                                  |  |
    Shared Bus Routing:           |  |
    SDA (Data Chain) -------------+  |
    GND (Ground Return) -------------+
🐍 The Software Code Pipeline
To configure your Pi, first ensure I2C is activated via sudo raspi-config (under Interface Options). Next, install your Python dependencies:
bash
pip3 install adafruit-circuitpython-mlx90393 adafruit-circuitpython-ssd1306 pillow
Use code with caution.
Run this script to continuously read data, display real-time telemetry on your screen, and record a text signature file.

python
import time
import board
import busio
from adafruit_mlx90393 import MLX90393
import adafruit_ssd1306
from PIL import Image, ImageDraw, ImageFont

# 1. Initialize Shared I2C Bus & Connected Electronics
i2c = busio.I2C(board.SCL, board.SDA)
sensor = MLX90393(i2c, gain=MLX90393.GAIN_1X)
oled = adafruit_ssd1306.SSD1306_I2C(128, 64, i2c)

# 2. Establish Clean Blank Slate canvas for GUI Layout
image = Image.new("1", (oled.width, oled.height))
draw = ImageDraw.Draw(image)
font = ImageFont.load_default()

# Open file target to log the permanent 3D fingerprint data arrays
with open("battery_magnetic_signature.csv", "w") as log_file:
    log_file.write("Timestamp,B_x(uT),B_y(uT),B_z(uT)\n")
    
    print("System active. Bring a battery cell near the sensor grid to map profiles...")
    
    try:
        while True:
            # Parse localized vectors from the Triaxis registry
            MX, MY, MZ = sensor.magnetic
            timestamp = time.strftime("%Y-%m-%d %H:%M:%S")
            
            # Commit the signature telemetry arrays cleanly to disk 
            log_file.write(f"{timestamp},{MX:.2f},{MY:.2f},{MZ:.2f}\n")
            log_file.flush() # Forces immediate system writing
            
            # 3. Format telemetry arrays visually for the OLED mini display
            draw.rectangle((0, 0, oled.width, oled.height), fill=0) # Clear display buffer
            draw.text((0, 0),  "MAGNETIC SIGNATURE", font=font, fill=255)
            draw.text((0, 16), f"X-Axis: {MX:6.1f} uT", font=font, fill=255)
            draw.text((0, 28), f"Y-Axis: {MY:6.1f} uT", font=font, fill=255)
            draw.text((0, 40), f"Z-Axis: {MZ:6.1f} uT", font=font, fill=255)
            draw.text((0, 54), "STATUS: LOGGING...", font=font, fill=255)
            
            # Send updated canvas frame directly into screen memory
            oled.image(image)
            oled.show()
            
            time.sleep(0.2) # 5Hz sample rate is optimal for manual baseline scans
            
    except KeyboardInterrupt:
        print("\nLogging complete. File saved safely.")
Use code with caution.

Comments

Popular posts from this blog

Legs