-
Notifications
You must be signed in to change notification settings - Fork 9
Description
Summary
Runtime settings on Trill devices (Trill Square in this case) persist while powered and are not reset between sketches unless explicitly changed or the board is power-cycled. This can cause unexpected behavior when changing sketches (e.g., from RAW-tuned settings to CENTROID without restoring defaults).
Example
The following sketch can be used to reproduce the issue. It continuously prints results of rawDataRead() for the Trill Square to Serial:
#include <Wire.h>
#include "Trill.h"
Trill trillSquare;
// tunables
static const uint8_t PRESCALER = 1;
static const uint8_t SCAN_SPEED = 0;
static const uint8_t SCAN_RES = 15;
void printRawData(Trill & trill) {
while(trillSquare.rawDataAvailable() > 0) {
int data = trillSquare.rawDataRead();
if(data < 1000)
Serial.print(0);
if(data < 100)
Serial.print(0);
if(data < 10)
Serial.print(0);
Serial.print(data);
Serial.print(" ");
}
Serial.println("");
}
void setup() {
Serial.begin(115200);
if(trillSquare.setup(Trill::TRILL_SQUARE) != 0)
Serial.println("failed to initialise trill square");
// POINT OF INTEREST-->
// ***RAW mode runtime settings***
// delay(10); trillSquare.setPrescaler(PRESCALER);
// delay(10); trillSquare.setScanSettings(SCAN_SPEED, SCAN_RES);
// delay(10); trillSquare.setMode(Trill::RAW);
// ***DIFF mode***
trillSquare.setMode(Trill::DIFF);
}
void loop() {
delay(100);
Serial.println("");
trillSquare.requestRawData();
if(trillSquare.rawDataAvailable() > 0) {
printRawData(trillSquare);
}
}
I am interfacing with the Trill Square using an Arduino Pro Micro, as outlined in the Bela Trill documentation:
Steps to Reproduce
- begin with a cold power cycle of the Trill Square and Arduino Micro.
- Run the sketch with the RAW mode runtime settings commented and DIFF mode uncommented.
- Take note of Serial output (expected DIFF mode behavior without contact):
0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000
0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000
...
- With the Arduino still powered, run the sketch with the RAW mode runtime settings uncommented and DIFF mode commented.
- Take note of Serial output (expected RAW mode behavior without contact at
PRESCALER = 1andScanSettingsparams):
24012 24326 24735 24310 24036 24872 26996 24588 24752 25759 25349 24472 24884 26012 25089 24842 25256 24223 23753 23540 23524 23996 23903 24196 23877 22798 23282 24111 24618 24270
24003 24319 24746 24313 24038 24875 26997 24674 24749 25761 25352 24480 24894 26001 25065 24843 25238 24228 23756 23534 23528 23995 23914 24211 23884 22800 23281 24132 24607 24273
...
- With the Arduino still powered, run the sketch again with the RAW mode runtime settings commented and DIFF mode uncommented.
- Take note of Serial output (unexpected behavior):
21024 21282 21668 21282 21035 21763 23620 21544 21640 22557 22135 21429 21793 22758 21919 21746 22171 21198 20770 20606 20588 21004 20906 21186 20921 19966 20371 21103 21540 21239
21013 21285 21663 21287 21048 21756 23617 21561 21652 22540 22167 21430 21784 22756 21972 21760 22140 21204 20784 20604 20581 20992 20915 21182 20907 19939 20373 21105 21540 21240
...
- Without modifying the sketch, power cycle the Arduino and rerun the sketch.
- Take note of Serial output (back to expected DIFF mode behavior):
0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000
0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000
...
Requested Documentation Updates
State persistence callout:
Add a prominent note such as "Trill devices retain mode/prescaler/scan/baseline settings while powered. Power-cycle the board or explicitly set all parameters in setup() when switching sketches."
