noxibus to create a capacitive interface and I want to capture the data from one or two pins instead of all 29 at once.
That's an interesting task. The Trill
library does not expose this feature, so after setup()
, where you can use the usual Trill
methods to initialise the sensor, you will have to use the Wire
library directly to perform the readings. Look at section 5.2 of the datasheet (https://github.com/BelaPlatform/Trill/blob/master/trill_datasheet.pdf). Relevant quotes:
At each transaction between the host and the Trill device, the host can directly write or read portions of the Cypress IC’s RAM.
When writing to the device, the first byte written in a transaction is the memory offset at which the following bytes in the same transaction are written, or the memory offset at which future read transactions will start from.
...
Memory offsets between COMM_DATA_OFFSET_BYTES and (COMM_BUFFER_SIZE_BYTES - COMM_DATA_OFFSET_BYTES - 1) (inclusive) constitute the data region of the memory.
Each pair of bytes represents a 16-bit unsigned integer word in Big-endian format.
Each pad reading is described by 2 bytes (1 word), representing the amount of capacitive activation on the corresponding pad.
First of all you need to figure out what offsets you are interested in reading. Data is stored starting at COMM_DATA_OFFSET_BYTES
(the value of the constant can be found at https://github.com/BelaPlatform/Trill/blob/master/firmware/common/trill-main.h.
). Each pad reading is 2 bytes long, so to access pad n
you would want to read starting from:
unsigned int offset = COMM_DATA_OFFSET_BYTES + 2 * n
The number of bytes to read depends on the number of consecutive pads you want to read starting from pad n
. To read m
pads, given how each reading is 2 bytes long, read:
unsigned int bytes = m * 2;
With the above info at hand and the i2c_address
of the device (which you can find here, you should be able to do, in loop()
:
Wire.beginTransmission(i2c_address);
Wire.write(offset); // write the offset at which you want to start reading data from
Wire.endTransmission();
Wire.requestFrom(i2c_address, bytes); // request the bytes you want to read
while(Wire.available() < bytes) // wait for bytes to be available
;
while(bytes)
{
// now read two bytes and parse them as big endian to reconstruct the reading
int reading = ((uint8_t)Wire.read()) << 8;
reading += (int)Wire.read();
bytes -= 2;
// HERE: do something with the reading
}
Note:
if for a given device you are always reading from the same offset (i.e.: you are reading only one pad or several consecutive ones), then you can move the first three lines to setup()
, thus making loop()
faster.
noxibus PS: I also heard there was a Processing library for Trill, does anyone know where to find it?
https://github.com/BelaPlatform/trill-processing-library
PS:please use triple backticks (```) to enclose your code. I amended your post accordingly