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
force sensor -help needed in code
-
- Posts: 22
- http://meble-kuchenne.info.pl
- Joined: Fri Aug 27, 2021 1:34 pm
- Been thanked: 2 times
-
- Valued Contributor
- Posts: 1460
- Joined: Wed Dec 09, 2020 9:37 pm
- Has thanked: 135 times
- Been thanked: 709 times
Re: force sensor -help needed in code
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
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
-
- Posts: 22
- Joined: Fri Aug 27, 2021 1:34 pm
- Been thanked: 2 times
Re: force sensor -help needed in code
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
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
-
- Valued Contributor
- Posts: 1460
- Joined: Wed Dec 09, 2020 9:37 pm
- Has thanked: 135 times
- Been thanked: 709 times
Re: force sensor -help needed in code
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.
Martin
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.
Martin