Recording data from two adxl345 sensors

F_Dos's icon

if not complicated - the only thing I would like to add is the addition is the current state of the ESP at the beginning if the recording log. so once recording is starting it will write the state of the ESP rather OK or disconnected

I did it my self but I'm sure I manage to overcomplex it

Source Audio's icon

please wait with that, it is onky entry in the log, nothing to do with path.

do you want day month year europe kind time stamp ?

F_Dos's icon

do you want day month year europe kind time stamp ?


Yes that is fine

please wait with that, it is onky entry in the log, nothing to do with path.


OK

Source Audio's icon

I have it ready with the path, one needs to modify record button

to start after folder/path has been created.

Max Patch
Copy patch and select New From Clipboard in Max.

you need to add js writers and connect them

F_Dos's icon

I should connect join object of each sensor to coll as well or only to js files?

F_Dos's icon

the output of regexp is empty:

I forgot to change the name....

that fixed. file created but without data and time in the file name

it needed _ and not -

F_Dos's icon

ok it write the file correct now.

I think the two unsolved things are
To integrate it to work with scheduled recording as well, not only manual
To write to the ESP logger

Source Audio's icon

Sorry I posted too fast, there are couple of mistakes in there.

andare more things to consider , also when gates for sensors should open,

inserting of ESP status on recording start is tricky before one needs last seen

values befor record timer jumps in, dio you just need 3 states or also recording start time ?

F_Dos's icon

inserting of ESP status on recording start is tricky before one needs last seen


ok in that case this can be avoided

values befor record timer jumps in, dio you just meed 3 states or also recording start time ?

ust 3 states is enough — I don't need the recording start time in there too, since it already appears in the filename itself. But if there are actual state changes (a sensor connecting/disconnecting), then yes, those specific events should have their own timestamp.

Source Audio's icon

yes ok, I forgot that ESP log is also connected to recording elapsed time, not to real time.

here is new patch with js files too.

Max Patch
Copy patch and select New From Clipboard in Max.

F_Dos's icon

Thanks!! how complicate it is to insert this system of manual or schedule recording?

Max Patch
Copy patch and select New From Clipboard in Max.

F_Dos's icon

Logger file won't create. The other work perfect

Source Audio's icon

you mean ESP file ? it gets ok here, do you have js file in same folder ?

F_Dos's icon

you mean ESP file ? it gets ok here, do you have js file in same folder ?


Yes. ESP file

it is not recorded into the folder or at all.

all js write "ready"

it is the only one that is not

Source Audio's icon

did you double click js object to check if code is inside

F_Dos's icon

You are right. no code!

F_Dos's icon

does it make sense no mm ss rather only 00 00

code I'm using:

outlets = 1; var f = null;
function openFile(filename) {if (f) f.close();
if (filename.slice(-4).toLowerCase() !== ".txt") {filename = (filename.indexOf(".") !== -1 ? filename.substring(0, filename.lastIndexOf(".")) : filename) + ".txt";}
f = new File(filename, "write");
if (f.isopen) {f.eof = 0; outlet(0, "Opened OK");} else {error("Failed to create file: " + filename + "\n");}}
function anything() {if (!f || !f.isopen) {outlet(0, "Error: No file opened!"); return;}
var cleanArgs = arrayfromargs(messagename, arguments);
if (cleanArgs === "list") cleanArgs.shift();
var line = cleanArgs.join(" ");
f.writestring(line); f.writebytes(13);}
function close() {if (f) {f.close(); f = null; outlet(0, "Closed");}}
function notifydeleted() {close();}
Source Audio's icon

paste this inside lines-text.js

it uses same eady and Failed messages

outlets = 1; var f = null;

function openFile(filename) {if (f) f.close();

if (filename.slice(-4).toLowerCase() !== ".txt")

{filename = (filename.indexOf(".") !== -1 ? filename.substring(0, filename.lastIndexOf(".")) : filename) + ".txt";}

f = new File(filename, "write");

if (f.isopen) {f.eof = 0; outlet(0, "Ready");} else {outlet(0, "Failed");}}

function anything() {if (!f || !f.isopen) {outlet(0, "Error: No file opened!"); return;}

var cleanArgs = arrayfromargs(messagename, arguments);

if (cleanArgs === "list") cleanArgs.shift();

var line = cleanArgs.join(" ");

f.writestring(line); f.writebytes(13);}

function close() {if (f) {f.close(); f = null; outlet(0, "Closed");}}

function notifydeleted() {close();}

sorry that with mm ss is a mistake.

one should convert that

F_Dos's icon

I still have 00 00 :

ESPlogger:

Source Audio's icon

change counter to this, input is different than in old test file, here we get ms from clocker

and connect zl.reg it was missing

F_Dos's icon

in order to read file into dump I'm using this system:

F_Dos's icon

and connect zl.reg it was missing


Great!

edit: still something wrong:

F_Dos's icon
Max Patch
Copy patch and select New From Clipboard in Max.

Is this system for dumping into active window is valid?

F_Dos's icon

change counter to this, input is different than in old test file, here we get ms from clocker


ok I understand now. it is printing recording time and not timestamp

Source Audio's icon

I am using this

in case you want to read recording folder in one go ...

F_Dos's icon

Amazing!

something change in my dumper system? for some reason it won't show any active windows although I do have

I also need to extract time from file to show actual time in active windows

Source Audio's icon

here is the patch with time extract

Max Patch
Copy patch and select New From Clipboard in Max.

F_Dos's icon

Could you please help me integrate the dumping system as well the scheduled/manual recording system whenever you have time?

I'm having a hard time making it all work together with the new additions.

for some reason I'm not sure it is not working for me

Source Audio's icon

it is printing recording time because you want ti be able to compare disconnected time with recording pauses

to dump into detectors, jut connect grab objects to their coll objects, and pass recording start time from file name

which variant did you choose at the end ?

F_Dos's icon

I went with Variant 2 (buffered pauses) in the end.

F_Dos's icon

Will you be able to integrate that as well?I bang my head around it without success for this time speaking

Max Patch
Copy patch and select New From Clipboard in Max.

F_Dos's icon

tell me which dump1 or dump2, is it ok to popem all files in the folder ?

Dump2. Yes it is ok

you would want to read / write auto-record fies too, right ?

True

I will try my bets to do that, but you please don't ask for non important changes

Ok sure

Source Audio's icon

here is full patch, only serial object is missing.

quite few functions have been packed into sub patchers, some send/receive things added.

I hope it runs ok for you.

As this is my last day at home, post if something needs a fix.

but it will take a while for me to answer.

Max Patch
Copy patch and select New From Clipboard in Max.

F_Dos's icon

This looks amazing.

the thing I noticed that the active colls are empty but I do have a windows to display based on data:

folder of data:

Rec-20260804_180242.zip
zip 6.11 KB

it is working!

That is so elegant beautiful patch! thank you very very much for all your help

Records works great, as well dumping folder. did not test auto record yet.

F_Dos's icon

ok sorry to bother but the auto rec system is not working

i think it should be: translate ms hh:mm:ss

F_Dos's icon

the above change fixed it.

just to make sure ESP logger should look like this without timer or timestamp?

Source Audio's icon

ESP logger is text based, not coll based.

it has no index and semicolon.

If you want it coll based, well one would need to remake it then

What fixed auto record ? and what was not working ?

Source Audio's icon

ah ok, I see : translate in auto-rec was leftover from original one where we needed 2000 ms in advance.

good you spotted that. I changed it also in my patch.

F_Dos's icon

in order to see changes immediately - if changing green number I should bang "full scan" and if changing pink number I should bang buffered scan right?

edit: it seems the answer is yes according to my observation

F_Dos's icon

Quick wondering on my side — shouldn't the join 3 in the ESP logger have all hot inlets? If only S2 or Receiver changes but S1 doesn't, it won't trigger it — is that right?

This is obviously not an urgent question at all, since you mentioned you're already heading out.



I would assume increasing tolerance gap would at best add more active windows or make smaller windows into one longer one

but it seems in that below case it reduced active windows:

gap is 1000ms -->

uncreasing gap to 2000ms -->

Source Audio's icon

yes, as they feed zl.reg you can add @triggers -1 to join 3.

I was in a time pressure when trying to complete the patch, maybe you will detect

one or the other thing that needs a fix ...

F_Dos's icon

one or the other thing that needs a fix ...

I think I just did -- see my edited last message

I think I understand what's happening — when the gap is 1000ms, there's one pause between the two windows. When I raise it to 2000ms, that pause is now too short to count, so there are no pauses left in the list at all — and with zero pauses, the system has nothing to derive an activity window from, so it shows nothing instead of merging everything into one long window. is that correct?

Source Audio's icon

my patch had only ms as time value for pauses and activity,

I can not see and tell what you did in the patch that shows minutes and ms

for activity threshold.

rule is as described:

when detector starts it adds zero to the beginning.

that together with 1st input tells if from zero(record start)

till that point it was longer then pause threshold.

then all indexes continue to count till very last recording timestamp.

all pauses ends are start of activity periods, pause start is end of it.

if between that 2 start times is more then activity threshold it counts it.

in other words - no pauses - no result at all.

F_Dos's icon

That is the changes I made:


Thanks for the clarification — I actually ran the numbers on the file and now I understand: I was wrong in my earlier confusion. The zero-start gap isn't automatically counted as a pause — it's evaluated against the same threshold as any other gap. In this file, that gap is 1433ms, so with a 1000ms threshold it does count (matching the first row in the table), but with a 2000ms threshold it doesn't pass either — so an empty result with 2000ms is actually correct, not a bug. Sorry for the confusion earlier!

Source Audio's icon

that would be also ok, you don't need 1 ms precision , right ?

F_Dos's icon

that would be also ok, you don't need 1 ms precision , right ?


Yes that is ok I don't actually need 1ms precision

F_Dos's icon

You mentioned "no pauses - no result at all," but in this file there ARE real pauses that pass the 1000ms threshold (1480ms, 4559ms, 4519ms, 2729ms). That should produce a window from the recording start (or the zero-insertion point) up to the first real pause at 5616ms — but that window is completely missing from the table. Only 00:00:07-08 and 00:00:18-20 show up.

One more piece of the puzzle: when I lower the tolerance to 500ms, that early window DOES appear (as 00:00:00-03 and 00:00:04-05). So it's not that the data isn't there — it just doesn't show up at tolerance=1000ms specifically. Could this be a bug specific to how the very first window is handled, separate from the "no pauses at all" case?

I'm attaching the raw file (A_05082026_135827.txt) along with two patch screenshots (tolerance=1000ms and tolerance=500ms) so you can see both the data and the actual results.

A_05082026_135827.txt
txt 9.06 KB


Source Audio's icon

zero to first entry can not count as activity, only as pause if it is long enough.

Opene text object in dump2 patcher after running full scan to see what is stored there.

close it before running next scan, because text and coll

do not get any input when their editor window is opened.

F_Dos's icon

I opened the text object in dump2 after running full scan, in both tolerance settings, and found a very consistent pattern that might point to the actual bug:

At tolerance=1000ms, the stored list is:
7096, 8969, 13528, 14385, 18904, 20456, 23185, 20456

At tolerance=500ms, the stored list is:
832, 3984, 4552, 5616, 7096, 8969, 13528, 14385, 18904, 19216, 19920, 20456, 23185, 20456

Does that match anything in how the list gets built in dump2?

Source Audio's icon

yes there is a problem in dump2, for the time being it woud be better to replace it with dump1

till I get time to fix it.

Max Patch
Copy patch and select New From Clipboard in Max.

Source Audio's icon

here are both variants, dump3 is fixed dump2.

I hope at least it is fixed.

I remnamed colls, so you can test independently from main patch

Max Patch
Copy patch and select New From Clipboard in Max.

I actually thought a bit about this and maybe also worth for you is to display how much data you received within a period of time, for example 15 minutes, or 30 minutes slices since recording start.

F_Dos's icon

Thank you very much! I already changed to dump1 but I will go back to dump3 now!

F_Dos's icon

I'm using dump3:

with the following result that not make sense:

I would assume the with activity window of 3000ms 00:00:13 - 00:00:14 would not be desplayed

dump1 works perfectly I will just use that instead. I'm not sure if the bug with dump3 is on my side, but in any case dump1 is perfect

Source Audio's icon

honestly I am not sure.

Am on my way to flight, will try to check it when possible.

in meantime stick with version that works ...

P.S.

this is test coll I used

test-coll.txt
txt 1.16 KB


F_Dos's icon

Sure! have a safe flight and thanks for your time and effort?

F_Dos's icon

for getting the high and low value of an incoming string is this a valid way?

I would like to know the highest and lowest value within a stream of data

Roman Thilenius's icon

[peak]

[change +]

...among others

Source Audio's icon

you have a list with 3 floats, maybe this is better for you :

Max Patch
Copy patch and select New From Clipboard in Max.

F_Dos's icon

Thanks for the above.

I discovered that my min and max value are between -0.027 and 0.268

I'm try to use that values with this system:

Max Patch
Copy patch and select New From Clipboard in Max.

any idea why this part is not changing in values?

any different approach to creates random bangs from that range if values? right now I'm using > 0.35 (after scaled to 0. 1.)

Source Audio's icon

look at the scale output first. single float uses no ramp at all, why do you use line there ?

I do not understand what random bangs are, if value is > 0.35

F_Dos's icon

look at the scale output first. single float uses no ramp at all, why do you use line there ?

that is not needed. I added it because I did not get any change down the roud and I thought it might be related.

Any reason why no data is presented after the smoothing area ( where the pack f 200. and line 0. 10. is?)

I do not understand what random bangs are, if value is > 0.35

I'm looking for ways to have random bangs that are related to the input coming from the sensor. that is very primitive way of doing so

F_Dos's icon

you have a list with 3 floats, maybe this is better for you :

I try this for the sensor with only one value (the moister sensor):

Why it is not writing 0.73 as the minimum value?

if the input is:

0.734

0.741

0.73

I would expect or at least would like to show 0.73 as the minimum value and 0.741 as the maximum value

Source Audio's icon

i is not f

And stii Idin't understand what random bangs are

If you want to bang when input gets above 0.35 then insert > 0.35 , change, sel 1

That scale, pipe and all the rest is hard to understand because it is all wrong, one can not detect what the purpose of it is

F_Dos's icon

My stupid mistake. thanks for pointing it out

ok but this did not solved what I was describing

Source Audio's icon

Describing what exactly ?

F_Dos's icon

I'm sorry not being clear.

I wanted to get the min and max value of the single value sensor.

In a example case if input data of 0.726, 0.731 and 0.741 I would expect to see 0.726 as min value and 0.741 has max value. What I'm actually getting is 0. as min val and 0.741 as max val


regarding this system:

What I'm trying to achive is two things:

1 - to create 'random' bangs from the input signal to change the note value

2 - to smooth the incoming signal to make it more musical to be able to control the filter cutoff

Source Audio's icon

To smooth input read a number of values and average them

Iwould use bucket or zl. stream and zl. median to average the list

But that random bangs tells nothing

Do you mean to bang random object ?

If yes then use what I suggested in my last post

About min and max - I can't say

I posted working patch which did exactly that

F_Dos's icon

About min and max - I can't say

I posted working patch which did exactly that

It is indeed working perfect but for input list. I also wanted a single value input, this is why I modify it with no success apparently

Iwould use bucket or zl. stream and zl. median to average the list

OK I will look into that

But that random bangs tells nothing

Do you mean to bang random object ?

yes.

F_Dos's icon

when I manual move the number box as in this video I can see the output changes:

Recording at 2026-08-10 17.16.10.mp4

when it comes from the playback of the sensor - output is not moving at all:

Recording at 2026-08-10 17.19.00.mp4



Source Audio's icon

vexpr works just the same as expr for single input

remove v and @scalarmode 1

and you get expr version.

patch that you keep posting is bad

I don't mean only "smoothing", but you multiply rannge 0 - 1 * 500 and then insert scale 0 1 400 800 at the end

What result do you expect ?

Source Audio's icon

I have no option to play videos

F_Dos's icon

What result do you expect ?

imagine result is musically changing the filter cutoff that between 400 and 800

I'm excepting to smooth the incoming data

F_Dos's icon

and you get expr version.

when inputing 0.5 to 0.74 and min value is still 0 and not 0.5.. I'm no sure what am I missing

Source Audio's icon

How should scale output that range if input is 500 times higher then expected input

And why don't you use vexpr version instead?

Init it with single zero

Ihave no max at hand to post that simple patches

F_Dos's icon

And why don't you use vexpr version instead?

Init it with single zero

I will try that

Source Audio's icon

I now realised what you posted

If min is initialised with zero then 0.5 can not become new lowest value

Example I posted was telling how much move you had in negative range because you asked for exactly that, to measure maximum movement in negative direction

you need to init max with lowest expected value and min with highest expected value

If you want to get absolute min max

for example min -0.9 max -0.1

or min 0.2 max 0.6

F_Dos's icon

you need to init max with lowest expected value and min with highest expected value

This is done by assuming lowest and highest expected value or this can be extract from actual data somehow?

Source Audio's icon

You must know that values in advance

because you use them to evaluate min max from them

What are this values ?

You need no precise numbers, just higher or lower from expected values

In your case with bipolar sensors you need to decide what to use in first place.

We discussed allready 3 esp32 code variants,

you picked centered bipolar one

F_Dos's icon

You must know that values in advance

because you use them to evaluate min max from them

What are this values ?

Thanks. those are values from the recorded session I made with the sensors..

now I try to transform the recorded data into something musically

F_Dos's icon

I first of all detect min max of a short recording part using the patch you shared (the vexpr)

I then scaled it from -0.027 0.278 to 0. 1. and try use that value with the system I screenshot earlier

Source Audio's icon

why don't you first scale input range to control range to see how it works ?

Later you can smooth, adjust and whatever else is needed to make it sound right

But that patch you posted is not good

And think about what that measured min max means

Sensor moved to positive direction max 0.278

Which is not much

In negative direction it hardly moved 0.027

Is really small value of possible 4.9

In realtime you will not be able to measure min max and adjust scaling because you don't know

in advance what wiil really happen with the tree

F_Dos's icon

Thanks that was, of course, a good advice (scaling it right away to the desired output data).

what would be a good slew limiting to that output data? This try I made with line is working ok

Source Audio's icon

I can not give you advice about smoothing data because frequency and intensity of change is unknown

same as if you would average 10 readings ,

it makes sense for fast input, but if your tree shakes a bit once in 10 minutes it would not work at all

So maybe a slight smoother to avoid jumps and too fast oscilations and then rampsmooth or similar on dsp side, like for filter freq

F_Dos's icon

I can not give you advice about smoothing data because frequency and intensity of change is unknown

how can I get this info? This is the file I'm currently using for its data to make musical changes

A_07082026_130000.txt
txt 82.58 KB


Source Audio's icon

You want me to analyse that text file to find out what to do with sensor data for unknown effect ?

It is your job to do that, I would maybe prefer

Sensor to move pan using absolute values with 50 ms ramp time, nothing else

Source Audio's icon

To make this serious, you would understand that only 2 of 3 axes can move enough to give you any significant change. Tree branch can bend up or down, left or right, but will never rotate own axis. Means you have only 2 values to look at.

Then , shake that branch, blow at it with strong ventilator to see what are it's mechanical limits and measure min max values of that 2 axes.

From that point you can try to set range for effects, amplify and clip input to get more effect in less stormy weather etc

Source Audio's icon

P.S. I downloaded and looked at that capture you posted.

this are sensor inputs per hour

1, 872;

2, 823;

3, 598;

4, 462;

5, 82;

X-axis min max: -0.141 to +0.493 (Total span: 0.634)

Y-axis min max: -0.177 to +0.055 (Total span: 0.232)

Z-axis min max: -0.314 to +0.163 (Total span: 0.477)

That is not possible if you mounted that sensor on a tree branch.

even if ADXL345 datasheet specifies a Cross-Axis Sensitivity of up to 2% to 5%

Y axis shows least movement, but far too much compared to other 2 axis

if it should be the "quiet" one by the way it was mounted on the branch

F_Dos's icon

Understood, thanks for the explanation about the branch mechanics.

Quick question — do you think these ranges (X: 0.634, Y: 0.232, Z: 0.477) are generally too low overall, meaning I should lower RANGE to get more sensitivity across all axes? Or is your concern specifically about Y being disproportionately high compared to X and Z, separate from the overall magnitude?

Source Audio's icon

I would like to know how that capture was made, and how do you explain the results ?

or how is that sensor positioned, on what kind of branch, to try to understand

how could it bend.

I think I explained well enough why one of the axis

(which - depends how sensor is mounted on the branch)

can not travel as much as the other 2.

I only suspect that Y - which shows smallest travel is in question.

if that was a recording , where is Record-End ?

Did you do what I suggested - to shake that branch and blow at it etc ?

If it can not gain much like that, I would remove RANGE anyway, and also ALPHA

letting sensor send each peak.

P.S that input per hour I posted was done with what I once suggested,

to set time slice length and count how many inputs were received during that period.

F_Dos's icon

I would like to know how that capture was made, and how do you explain the results ?

or how is that sensor positioned, on what kind of branch, to try to understand


if that was a recording , where is Record-End ?

OK something is strange. At that day I schedualed 4 recording:

and that is the folders of the recorded files:

I just noticed that in that recording I shared there was no indeed record-end. I looked at all the other recording files of that sensor and all of them have a record-end:

A_06082026_173000.txt
txt 1.75 KB
A_06082026_230000.txt
txt 0.23 KB
A_07082026_060000.txt
txt 89.77 KB
A_07082026_173000.txt
txt 5.67 KB

I'm not sure what went wrong with that.

Did you do what I suggested - to shake that branch and blow at it etc ?

Yes I did it before the recorded session


F_Dos's icon

I think I found it. for some reason the last recording split into two. the file I fist shared with no record-end; :

A_07082026_130000.txt
txt 82.58 KB


is continue in that file with record-end; :

A_07082026_173000.txt
txt 5.67 KB


Source Audio's icon

I see very simple explanation

You had record start at 13:00 5 hours long

That should end at 18:00

Why do you set next recrding at 17:30 ???

You say you did shake the tree but why don't you post the readings ?

I want to help you but have to beg for infos ?