Page 1 of 1

force sensor -help needed in code

Posted: Wed Sep 22, 2021 10:07 pm
by rzeszurzeszu
Hello,
I would like to measure weight gain (difference between previous and actual mass in every 15 seconds. Than send it via UART as mass change divided by 15 sec.

could someone give me hint or put some flow ? Should I use some timer component ?

Thank you in advance

Re: force sensor -help needed in code

Posted: Thu Sep 23, 2021 7:35 am
by mnfisher
There would be several ways to do this.

In pseudocode:

The 'simplest' might just be a delay(15s) between readings
Then mass = ReadMass()
Diff = oldMass - mass
Print(diff)
OldMass = mass

However depending on the hardware you are using - delay busy waits so for battery powered devices you might want to sleep the MCU and wake on an interrupt (internal or external from a RTC for example). You might also want to keep multiple 'previous ' masses (in an array)

So - give us some more details on what you want (what MCU for example)

Martin

Re: force sensor -help needed in code

Posted: Thu Sep 23, 2021 12:58 pm
by rzeszurzeszu
Hello Martin,
I would like to use arduino UNO.
The aim is to count the water drops in time ( every 15 seconds) and measuring the weight ( every 15 sec.)
I must use 2 force sensors in my project and observe both.

Could you please propose something in FC9 ?

Thank you in advance

Re: force sensor -help needed in code

Posted: Thu Sep 23, 2021 9:43 pm
by mnfisher
Okay - so a simple example using a timer interrupt.

Here I use a 244.141Hz interrupt - so each 'second' measured is actually 0.9994s (so 15s is 14.99s). You can make it more accurate by using a faster interrupt (change the interrupt prescaler and the factor in the macro 'timer')

Note that I suspect it's difficult to get complete accuracy without using an external RTC to provide an accurate 'pulse' - due to inaccuracies in the crystal used on the Arduino board.

I don't have a load cell to test - so I've just used random numbers so the mass fluctuates up and down.

Note that it also simulates okay in FC.
timed_mass.fcfx
(12.95 KiB) Downloaded 142 times
Martin