02 Data Acquisition Unit - sghctoma/sst GitHub Wiki

Intro

The DAQ unit collects data from the sensors, and stores them on a MicroSD card. The card is also used to store a configuration file in the root directory called CONFIG. If the file does not exist, the following default values wil be used:

SSID=sst
PSK=changemeplease
NTP_SERVER=pool.ntp.org
SST_SERVER=sst.sghctoma.com
SST_SERVER_PORT=557
COUNTRY=HU
TIMEZONE=UTC0

The first time the device is turned on, sensor(s) need to be calibrated, so that the device knows their initial angle that corresponds to the maximum travel as well as the rotation direction.

  1. When the unit displays CAL_EXP, extend both the shock and fork (e.g. lift the bike up) and press the left button.
  2. The unit will now display CAL_COMP. Compress both suspensions (e.g. sit on the bike), and press the left button again.

This concludes the sensor calibration. If you need to recalibrate the device, hold the left button while turning it on. This will restart the calibration sequence described above.

After calibration (and on subsequent starts), the display will show a status page with

  • the current time,
  • battery status,
  • sensor indicators.

daq unit

A long press of the right button will initiate server mode, which is used by the Sufni.Bridge application to access session files. A short right press in this mode will close the server.

Starting the server will also initiate time synchronization with the time server specified as NTP_SERVER. This is done via a WiFi connection for which the network name, password and 2-digit country code are specified in the config file as well (SSID, PSK and COUNTRY). Session timestamps are stored in UTC, but the time displayed is in the time zone specified as the TIMEZONE setting. This value should either be a valid POSIX time zone string, or a canonical tz database time zone name. For canonical names to work, the SD card root directory must contain a file called zones.csv with name - POSIX zone string mapping. Such a file can be downloaded here: nayarsystems/posix_tz_db. It is important that the CSV file adheres to the proper format (comma as separator, double-quote mark as delimiter).

A short left press will start a session, during which the display will show which of the two sensors are available (e.g. "REC:F|S" for both, "REC:F|." for fork only). A second short left press will end the session.

A long left press will synchronize time first, then try to upload all not yet uploaded sessions to the server specified by SST_SERVER and SST_SERVER_PORT (default values are my own server). During this, the display will show the total number of files to upload, which of them is currently being processed, and how many sessions failed to import. This status page remains for 3 seconds after upload is finished.

A short right press will send the unit to a low-energy sleep mode, from which another short right press wakes it up.

If the unit is connected to a computer via USB, it will act as a mass storage device, and gives read-write access to the content of the MicroSD card. During this, the display will show "MSC MODE".

Building the hardware

Main box

To build the DAQ unit, you will need the following components:

  • Raspberry Pi Pico W
  • SSD1306 OLED display (I2C by default, can be configured for SPI)
  • MicroSD card reader (SDIO by default, can be configured for SPI)
  • DS3231 RTC unit (I2C)
  • A battery charger unit (based on e.g. TP4056)
  • Battery (I'm using a 18350 lithium-ion battery)
  • A P-channel MOSFET (DMG2305UX recommended by Raspberry)
  • Two push buttons
  • One switch (to cut main power)
  • Two connectors (e.g. JWPF) for the sensors (4-pin for AS5600, 3-pin for potentiometer sensors)
  • (only for potentiometer sensors) MCP6002 operation amplifier

The schematic below shows the default PIN arrangement - if you solder everything together according to it, you won't have to modify the firmware source code in the next chapter.

schematic

The hardware is supposed to to be buildable from off-the-shelf components, so there's no PCB design included. Maybe there will be such an option in the future, but for now, you have to figure out the physical wiring for the components, breakout boards you got.

Sensors

The project was built with the rotational sensors in mind, but both the firmware and the backend components can handle the more traditional linear potentiometer-based sensors as well. It is even possible to mix them, e.g. linear sensor on the fork and AS5600 on the shock.

Option 1 - AS5600

For the sensors, you will need 2 AS5600 magnetic rotary encoders, and you need to connect their I2C pins to the 4-pin connectors. As of yet, there is no design for universal mounts, so you will need to get creative.

For the fork, you will need 2 equal-length rods connected to

  • each other,
  • one of them to the uppers,
  • the other to the lowers

via pivot points. This will form an isosceles triangle, and the AS5600 chip has to be attached so that it measures one of the equal angles (preferably the one at the uppers, so the wiring won't bend when the fork moves). You will need the lenght of the rods and the maximum distance between the upper and lower pivot point for calibration.

On the shock, there's no need to construct a triangle, we already have one: the one defined by the two eyelets and a pivot point on the frame. The AS5600 has to be put at the frame pivot, and you will need all three sides of the triangle at maximum expansion for calibration.

calibration

Option 2 - Linear potentiometer

These just need to be connected to the Pico's AGND, 3V3 output, and the opamp's pins indicated on the schematic. If you want to change the default design, the ADC to use can be configured in ~/firmware/src/fw/hardware_config.h.

📝 NOTE:: with linear potentiometers, the sensor indicators on the status screen will always indicate the presence of sensors, even when they are not connected.

Building the firmware

Linux

To build the firmware, first you need to set up version 2.0 of the Pico C SDK (Chapter 2.). Make sure your don't leave the pico-extras repository out, since it is needed for the PIO I2C implementation. After setting up the SDK, download and unpack the sources:

$ wget https://github.com/sghctoma/sst/releases/download/v0.4.0-alpha/firmware-src.zip -O ~/firmware-src.zip
$ cd ~/
$ unzip firmware-src.zip

📝 NOTE: If you have made changes to the default schematic, you need to adjust GPIOs in ~/firmware/src/fw/hardware_config.h accordingly.

📝 NOTE: The default baud rate for SPI MicroSD cards is 25 MHz, which might be too high for some cards/readers/wirings. In case you experience problems with the card (e.g. CARD ERR message, occasional freezes, or CRC erro messages in the serial console), trying a lower BAUD_RATE value in ~/firmware/src/fw/hardware_config.h might solve them.

The next step is building the firmware:

$ cd ~/firmware
$ cmake --preset default
$ cmake --build --preset default

The firmware is built for I2C displays, SDIO MicroSD card readers and AS5600 sensors for both fork and shock with the default preset. There are presets for all possible combinations of these components named using the following pattern: {card_type}-{display_type}-{fork_sensor_type}-{shock_sensor_type}. Debug presets have an additional -debug suffix. The possible values for those placeholders are:

  • card type: spi_card and sdio_card
  • display type: spi_disp and i2c_disp
  • fork sensor type: as5600_fork and linear_fork
  • shock sensor type: as5600_shock and linear_shock

You can get a full list of presets with the cmake --list-presets command.

When the build is done, you need to plug the Pico in to a USB port while keeping the BOOTSEL button pushed. You can then mount the Pico as a mass storage device, and copy the sufni-suspension-telemetry.uf2 file from the output directory to it - this will install the firmware, which will start on the next boot.

Alternatively, you can use the picotool command when the Pico is attached in BOOTSEL mode:

$ sudo picotool load ~/firmware/build/release/default/sufni-suspension-telemetry.uf2

Windows

You will need to set up the Pico development environment, which is easily done using the installer found in the pico-setup-windows repository. Download and install the latest release. Make sure you leave the clone and build the pico-examples repository from GitHub option checked - this will also donwload the pico-extras repository (we need it for the PIO I2C implementation)

Download and extract the firmware sources, then open the firmware folder in Visual Studio Code. Make sure to start VSCode via the Pico - Visual Studio Code Start Menu shortcut - this will set all the necessary environment variables.

📝 NOTE: If you have made changes to the default schematic, you need to adjust GPIOs in ~/firmware/src/fw/hardware_config.h accordingly.

📝 NOTE: The default baud rate for SPI MicroSD cards is 25 MHz, which might be too high for some cards/readers/wirings. In case you experience problems with the card (e.g. CARD ERR message, occasional freezes, or CRC erro messages in the serial console), trying a lower BAUD_RATE value in ~/firmware/src/fw/hardware_config.h might solve them.

You will need to select one of the configuration presets depending on what kind of display (I2C or SPI), MicroSD reader (SDIO or SPI) and sensors (AS5600 or linear potentiometer) you use.

CMake presets

After that, you can build the firmware by opening the CMake tools from sidebar, and clicking on the build icon in the project tree.

When the build is done, you need to plug the Pico in to a USB port while keeping the BOOTSEL button pushed. The Pico will attach itself as a mass storage device, so you can copy the sufni-suspension-telemetry.uf2 file from the output directory to it - this will install the firmware, which will start on the next boot.