This repository is the second version of the Pocket Spectrometer. The main improvement is the use of an AMS sensor from Adafruit that features a built-in grove-compatible port (known as Stemma QT) for I2C communication. While the previous version used a DFRobot AMS sensor that required manual soldering of I2C connections, this version simplifies assembly by using Adafruit's sensor with the Stemma port. The M5StickC and AMS sensor are connected using a Grove to Stemma connector, readily available from Adafruit. This cable offers improved stability with additional grip at the Grove port, making it more reliable than the original Grove cable used in the first version, which had a looser connection. This plug-and-play approach eliminates the need for soldering, reducing build steps and complexity. The 3D-printed main body has been modified to accommodate the Adafruit AMS sensor's different form factor. This version is improvement on the build side, but functionality of the spectrometer remains the same.
- 1x M5StickC (https://docs.m5stack.com/en/core/m5stickc_plus)
- 1x AS7341 spectral sensor from Adafruit (https://www.adafruit.com/product/4698)
- 1x 100mm Grove to stemma connector cable (https://www.adafruit.com/product/4528)
- 4x M2 screws (https://eu.mouser.com/ProductDetail/Harwin/M80-2260000B?qs=DXv0QSHKF4wN5XPxPv8mDw%3D%3D&utm_source=octopart&utm_medium=aggregator&utm_campaign=855-M80-2260000B&utm_content=Harwin)
- 4x M2 heat-set inserts (https://www.mouser.com/ProductDetail/SI/IUTFB-M2?qs=DPoM0jnrROVcA4QFWOCRzw%3D%3D&srsltid=AfmBOopUU4Yk4SA0-Q8_GQOYWdSUdiCuBDWbHyQfNmQKO6hRtp1Q_SV6)
- Black PLA filament for 3D printing of the enclosure and the cap
- White PLA for 3D printing of the reflector
-
- Black electrical tape
- Main body
- Cap
- White reflector
- 3D printer
- Soldering iron (for heat-set inserts only)
- M2 screwdriver
- OpenSCAD for 3D printed parts (Optional, only required if you wany to modify the designs)
- 3D printer slicer software (e.g., Ultimaker CURA)
- Thonny IDE for programming the M5StickC
The AS7341 sensor is crucial for this project:
- 11 readable individual sensor elements (10 light channels plus flicker detection)
- Coverage from 350-1000 nm for comprehensive analysis
- Built-in LED control for consistent illumination
- Low power consumption for extended battery life
- Affordable price point (~$16)
- Stemma QT connector for easy, solder-free connection
The M5StickC is the perfect platform for this project because it packs incredible functionality into a tiny package:
- Built-in rechargeable battery for true portability and field applications
- USB-C connector for easy charging and programming
- Seeed Grove port for simple sensor connections
- Two user-programmable buttons for interface control
- TFT display screen for displaying spectra in real-time
- Beautifully labeled breakout header for expansion
- Extra built-in sensors (6-axis IMU, Microphone, IR transmitter)
- Compact size (48.2 x 25.5 x 13.7mm) ideal for portable spectrometer
- MicroPython support for easy programming
- Affordable price point (~$20)
- Power on the M5StickC
- Quickly press the M5 button after restart (using reset/PWR button) until you see the settings screen
- Download and install Thonny IDE
- Connect the M5stickC to computer and Open Thonny
- Navigate to Tools > Options > Interpreter
- Configure settings:
- Set interpreter to "MicroPython (ESP32)"
- Select the correct COM port for your M5StickC
- Click OK and reconnect
- Once connected, you can write and test code directly in the IDE
- Download the software from this repository and save into a folder (For example to Downloads folder).
- Unzip the folder. Navigate to this folder's sub folder named Software inside Thorny. The files of the Software should should up at the top-left side as shown in the below figure.
-
First test the components:
- Connect the Grove to stemma cable between M5StickC and AMS sensor

- Upload the firmware using Thonny IDE as described above
- Verify the spectral sensor functions correctly. If M5 button is pressed, white light of the AMS sensor should be on and a spectrum should be displayed on the screen as shown in the picture.
- Disconnect the Grove connector cable from the M5StickC after the above testing

- Connect the Grove to stemma cable between M5StickC and AMS sensor
-
Prepare the 3D printed parts:
-
Final assembly:
-
Route the Grove to stemma cable from the AMS sensor through the hole at the bottom into the slot for M5stickC as shown in the image here.

-
See this image for more clarity.
-
Press-fit the M5StickC into the body from the top
-
Apply black electrical tape to cover the AMS sensor and wires for light isolation and protection
-
Press fit the white reflector at the narrow slot.
The code is written in MicroPython for simplicity and accessibility, making it easy to modify for various applications. Most AI tools nowadays work well with Python code, making MicroPython an ideal choice for future modifications and improvements.
- Upgrade to AS7343 for expanded capabilities (14 spectral channels vs AS7341's 10 channels)
- Optimize battery life for extended field use
- Conduct comprehensive testing (Work in progress)

- Document detailed measurement protocols and generate standard curve plots
- Add data logging functionality with time-stamped spectra files
- Create a calibration procedure for improved accuracy
- If code doesn't execute properly, use the stop/rerun button in Thonny IDE until you see three forward-looking arrows in the console
- Restart the device if experiencing connection issues
- Ensure proper USB mode selection on the M5StickC before programming
- Ensure correct serial port is selected at the Thonny IDE M
- Verify the Grove to stemma cable is fully seated at both ends
- Ensure the M2 screws aren't overtightened on the sensor











