
MOLEGRAPH AUTO FIRMWARE (v4.6)
Windows USB Upload Guide
========================================

This package contains precompiled firmware for the MoleGraph school probeware
system. The firmware runs on an Arduino Nano with an ATmega328P microcontroller.

Because the Arduino Nano has limited program memory, this package provides four
precompiled firmware configurations. Each configuration is available as:

  - a standard .hex file for normal USB uploading;
  - a .with_bootloader.hex file for advanced ISP programming.

WHICH FIRMWARE SHOULD I CHOOSE?
========================================

NOT SURE? Start with a 30720 version and use the included Windows USB upload
script. It automatically tries the appropriate upload speeds, so you do not
need to know which bootloader is installed on your Arduino Nano.

1. STANDARD CONFIGURATION - 30720 bytes

File:
MoleGraphAuto-v4.6-30720-NO_LSM303DLHC.hex

TOF distance sensor: VL530X
Disabled: LSM303DLHC accelerometer and magnetometer.

A good starting point for USB uploading and broad compatibility.

2. VL53L1X CONFIGURATION - 30720 bytes

File:
MoleGraphAuto-v4.6-30720-VL53L1X-NO_LSM303DLHC-NO_MAX6675-NO_TURB-NO_AD8232-NO_DCA30-NO_LED.hex

TOF distance sensor: VL53L1X
Disabled:
  - LSM303DLHC accelerometer and magnetometer
  - MAX6675 temperature sensor with K-Type thermocouple
  - Turbidity sensor
  - AD8232 ECG
  - 0-30 A current sensor
  - Output LED module

Use this if your setup requires the VL53L1X and must fit within the smaller
memory limit.

3. FULL CONFIGURATION - 32256 bytes

File:
MoleGraphAuto-v4.6-32256.hex

TOF distance sensor: VL530X
Disabled: none - full sensor configuration.

This is the most complete precompiled build. Use it if your Arduino Nano has
the newer Optiboot bootloader and you want all available sensors enabled.

4. VL53L1X CONFIGURATION - 32256 bytes

File:
MoleGraphAuto-v4.6-32256-VL53L1X-NO_LSM303DLHC-NO_MAX6675.hex

TOF distance sensor: VL53L1X
Disabled:
  - LSM303DLHC accelerometer and magnetometer
  - MAX6675 temperature sensor with K-Type thermocouple

Use this if you have Optiboot, need the VL53L1X, and want to keep more sensors
enabled than in the 30720-byte VL53L1X build.

UNDERSTANDING THE MEMORY LIMITS
========================================

The numbers 30720 and 32256 refer to the firmware memory limit in bytes. They
are not the size of the downloaded HEX file. The NO_... parts of a filename
indicate which sensors or modules are disabled in that build.

The available program memory depends on the Arduino Nano bootloader:

  - 30720 bytes with the older bootloader;
  - 32256 bytes with the newer Optiboot bootloader.

If you are unsure which bootloader your board has, use a 30720 build with the
USB upload scripts. If you want to use a 32256 build, your Nano must have
Optiboot.

For instructions on installing Optiboot and configuring the fuses, see:
https://github.com/e-Mole/MoleGraph/blob/master/docs/troubleshooting/02_arduino-nano-bootloader-fix.md

WINDOWS: THE EASIEST WAY TO UPLOAD FIRMWARE VIA USB
========================================

The package includes AVRDUDE and ready-to-use .bat scripts for Windows. You do
not need to install AVRDUDE separately or type command-line instructions.
Keep the supplied folder structure intact when extracting the package.

1. Extract the complete package to a folder on your computer. Keep all files
   and subfolders together.
2. Connect the Arduino Nano to your computer using a USB data cable.
3. In the package's main folder, double-click the Upload_... .bat file matching
   the firmware configuration you want to install.
4. When prompted, enter ONLY the number of the Arduino's COM port. For example,
   if the device is shown as "USB-SERIAL CH340 (COM46)", enter 46.
5. Wait for the final success or failure message. Do not close the window or
   disconnect the board while uploading.

For the 30720 builds, the script first tries 115200 baud. If AVRDUDE reports a
communication or synchronization failure, it automatically retries at
57600 baud.

The 32256 builds require Optiboot and are uploaded at 115200 baud.

IMPORTANT: Run the Upload_... .bat file from the package's main folder.
The file tools\UploadFirmware.bat is an internal helper and should not be
started directly.

If uploading fails, check that you selected the correct COM port, that no
other application is using it, and that the USB cable supports data. For a
32256 build, also confirm that the board has Optiboot.

WHAT ARE THE .with_bootloader.hex FILES?
========================================

Files ending in .with_bootloader.hex contain the firmware together with a
bootloader. They are intended for ISP programming, not for normal USB uploading.
Do not select them for standard USB uploading.

Use these files only if you are deliberately programming the complete device
with an ISP programmer. The Arduino Nano Bootloader Fix guide explains the ISP
procedure and fuse configuration:
https://github.com/e-Mole/MoleGraph/blob/master/docs/troubleshooting/02_arduino-nano-bootloader-fix.md

CUSTOM FIRMWARE CONFIGURATION (ADVANCED)
========================================

For the best fit to your hardware, we recommend compiling MoleGraphAuto yourself
and enabling only the sensors you need in config.h. This lets you tailor the
firmware to your setup and manage the Nano's memory limit directly.

Follow the Memory Optimization & Sensor Configuration guide:
https://github.com/e-Mole/MoleGraph/blob/master/docs/troubleshooting/04_memory-optimization-config.md

SUPPORTED SENSORS
========================================

The following list describes the full MoleGraphAuto-v4.6-32256.hex configuration.
Other builds disable the sensors or modules indicated in their filenames.

KINEMATICS & DISTANCE
- I105 - TOF distance sensor (VL530X in the full build; VL53L1X in explicitly
  named variants)
- D021 - SRF04 motion sensor
- D035 - Digital caliper
- A039 - 810H photogate switch / slot

MECHANICS, MAGNETIC FIELD & SOUND
- D007 - Force gauge with HX711
- A006 - MPX5700DP pressure sensor
- I003 - LSM303DLHC accelerometer and magnetometer
- A023 - Magnetic field sensor (Hall sensor)
- A027 - Sound intensity sensor (microphone)

THERMODYNAMICS & CLIMATE
- W001 - DS18B20 thermometer
- I005 - MLX90614 non-contact thermometer
- D034 - MAX6675 temperature sensor with K-Type thermocouple
- I002 - BME280 barometer, thermometer and hygrometer

LIGHT & OPTICS
- A018 - Light intensity sensor (photoresistor)
- I032 - BH1750 light intensity sensor (luxmeter)
- I031 - VEML6070 UV radiation sensor
- I011 - TCS34725 color sensor (BASIC mode and extended MONITOR mode with
  online MoleGraph ColorLab support for measured data analysis, calibration
  testing, and LUT exploration)
- I011 - Chemistry colorimeter using TCS34725; RGB-channel and total C-channel
  transmittance, plus raw (RAW) RGB+C data

LIQUIDS & GASES
- A014 - pH sensor
- C015 - TDS conductivity and salinity sensor
- A037 - ORP electrode and module
- A038 - TS-300B turbidity sensor
- C019 - MH-Z16 carbon dioxide sensor
- A025 - MQ-3 alcohol gas sensor
- A036 - MQ-2 LPG / propane / methane / hydrogen gas sensor
- A020 - SGX-VOX oxygen (O2) gas sensor

HUMAN BODY & HEALTH
- A022 - Heart rate sensor
- A010 - AD8232 ECG

ELECTRICITY
- A028 - DC voltage sensor, 0-25 V
- A029 - DC current sensor, 0-5 A with ACS712
- A030 - DC current sensor, 0-30 A with ACS712

OUTPUT & DEMONSTRATION
- D200 - Output LED module for sampling-frequency visualization

ALWAYS ENABLED
- A101 - Analog sensor using the Arduino 10-bit ADC (SENSOR_AD)
- D103 - Special TIMER (SENSOR_TIMER)
