Hi Ytai,

I'd like to have the pulse counting to be as accurrate as possible.

I'm not really sure about the difference of getVoltageSync() and 
getVoltage().

But when I use the *sync method, the method block until new sample arrive 
right?

I don't mind if i lost a few pH input.

So in order to achieve that goal, would it be better if I use getVoltage() 
rather than getVoltageSync()?
Or maybe I should try another method?

Many thanks


On Tuesday, August 29, 2017 at 1:17:37 PM UTC+7, Ytai wrote:
>
> I don't think there's a lot of value in using the *Sync version. Otherwise 
> it's fine, as long as you don't mind that the sample rate varies with the 
> flow rate. Otherwise, create a separate thread for one or the other.
>
> On Aug 28, 2017 18:21, "Maximillian" <[email protected] <javascript:>> 
> wrote:
>
>> Thanks a lot Ytai.
>>
>> One more thing.
>>
>> I plan to use pH sensor along with this flow sensor.
>>
>> more or less it will be like this:
>>
>> PulseInput flowMeter = ioio_.openPulseInput(FLOW_METER_PIN, PulseInput.
>> PulseMode.FREQ_SCALE_16); //using frequency measurement with 16x scaling
>> AnalogInput phMeter = ioio_.openAnalogInput(PH_METER_PIN);
>>
>>
>> float phVolt;
>>
>> int totalPulse = 0; //set initial value of totalPulse
>>
>> (this is inside the loop)
>>
>> {
>>
>>     duration = flowMeter.getDurationBuffered(); //the loop will wait here 
>> for 16 pulse then continue to next line
>>
>>     totalPulse += 16; //add total pulse by 16 because we use FREQ_SCALE_16
>>
>>     ....
>>     phVolt = phMeter.getVoltageSync();
>>     phValue = calculatePhFromVolt(phVolt);
>>
>>     ....
>>
>> }
>>
>>
>> I think the phMeter will always has a value to return and will not block 
>> the UI.
>>
>> Would it be an issue if combined with the 
>> PulseInput.getDurationBuffered()?
>>
>> Thanks.
>>
>> On Monday, August 28, 2017 at 9:03:16 PM UTC+7, Ytai wrote:
>>>
>>> Yup, that's what I meant. And you don't need the sleep.
>>>
>>> On Aug 28, 2017 1:21 AM, "Maximillian" <[email protected]> wrote:
>>>
>>>> Hi Ytai, thanks for the reply,
>>>>
>>>> Based from your suggestion,
>>>>
>>>> PulseInput flowMeter = ioio_.openPulseInput(FLOW_METER_PIN, 
>>>> PulseInput.PulseMode.FREQ_SCALE_16); //using frequency measurement with 
>>>> 16x scaling
>>>>
>>>>
>>>> int totalPulse = 0; //set initial value of totalPulse
>>>>
>>>> (this is inside the loop)
>>>>
>>>> {
>>>>
>>>>     duration = flowMeter.getDurationBuffered(); //the loop will wait here 
>>>> for 16 pulse then continue to next line
>>>>
>>>>     totalPulse += 16; //add total pulse by 16 because we use FREQ_SCALE_16
>>>>
>>>>     ....
>>>>
>>>>     ....
>>>>
>>>>     Thread.sleep(100);
>>>>
>>>> }
>>>>
>>>>
>>>> Do you mean like this?
>>>>
>>>> And also, do I still need the Thread.sleep(100)? As the 
>>>> getDurationBuffered() will do pause the loop while waiting for 16 
>>>> pulse to come.
>>>>
>>>> Thanks
>>>>
>>>>
>>>> do I still need to use Thread.sleep(100) when using this 
>>>> implementation? Since getDurationBuffered will do pausing the loop 
>>>> waiting for 16 pulse to come.
>>>>
>>>> On Monday, August 28, 2017 at 11:15:05 AM UTC+7, Ytai wrote:
>>>>>
>>>>> You can use getDurationBuffered() and apply scaling (to reduce the 
>>>>> pulse rate). This will ensure you don't miss any pulses. You can even 
>>>>> ignore the actual value returned, since you don't seem to care about the 
>>>>> rate, but rather about the count. Each time getDurationBuffered() 
>>>>> returns, 
>>>>> it would mean that 16 pulses (or whatever your scaling is) were observed. 
>>>>> So you'll end up with a somewhat cumbersome, yet accurate way to count 
>>>>> your 
>>>>> pulses.
>>>>>
>>>>> On Wed, Aug 23, 2017 at 7:39 PM, Maximillian <[email protected]> 
>>>>> wrote:
>>>>>
>>>>>> Fyi, I use this sensor.
>>>>>> https://www.seeedstudio.com/Water-Flow-Sensor-YF-B1-p-2878.html
>>>>>>
>>>>>>
>>>>>> On Thursday, August 24, 2017 at 9:38:08 AM UTC+7, Maximillian wrote:
>>>>>>>
>>>>>>> I think I could get around ~40 pulse per each call of flowMeter.
>>>>>>> getFrequencySync() in a Thread.sleep(100) loop.
>>>>>>>
>>>>>>> Is it still unsafe to just use the getFrequencySync() method for 
>>>>>>> that amount of pulse?
>>>>>>>
>>>>>>> Or maybe I can just lower the sleep time to maybe Thread.sleep(50) 
>>>>>>> for better accuracy?
>>>>>>>
>>>>>>> Thanks for the hint, I'll try to look into that.
>>>>>>>
>>>>>>>
>>>>>>> On Thursday, August 24, 2017 at 6:18:52 AM UTC+7, Ytai wrote:
>>>>>>>>
>>>>>>>> What's the maximum pulse rate for your application?
>>>>>>>>
>>>>>>>> On Wed, Aug 23, 2017 at 3:36 PM, Maximillian <[email protected]> 
>>>>>>>> wrote:
>>>>>>>>
>>>>>>>>> Can you give more hint about how to count?
>>>>>>>>>
>>>>>>>>> I'm not really sure how to do it.
>>>>>>>>>
>>>>>>>>> Big thanks
>>>>>>>>>
>>>>>>>>> On Wednesday, August 23, 2017 at 11:56:20 PM UTC+7, Ytai wrote:
>>>>>>>>>>
>>>>>>>>>> Sampling the frequency and integrating will give you an estimate 
>>>>>>>>>> of the total. If it's not accurate enough, you'll need to count.
>>>>>>>>>>
>>>>>>>>>> On Aug 22, 2017 2:51 PM, "Maximillian" <[email protected]> 
>>>>>>>>>> wrote:
>>>>>>>>>>
>>>>>>>>>>> Hi Ytai,
>>>>>>>>>>>
>>>>>>>>>>> This is my current code (trimmed for this post)
>>>>>>>>>>>
>>>>>>>>>>>
>>>>>>>>>>> int FLOW_METER_PIN = 14;
>>>>>>>>>>>
>>>>>>>>>>> volatile float pulseFreq, totalPulse;
>>>>>>>>>>>
>>>>>>>>>>> PulseInput flowMeter = ioio_.openPulseInput(FLOW_METER_PIN, 
>>>>>>>>>>> PulseInput.PulseMode.FREQ);
>>>>>>>>>>>
>>>>>>>>>>>
>>>>>>>>>>> totalPulse = 0;
>>>>>>>>>>>
>>>>>>>>>>> public void loop() throws ConnectionLostException, 
>>>>>>>>>>> InterruptedException
>>>>>>>>>>> {
>>>>>>>>>>>
>>>>>>>>>>>     pulseFreq = flowMeter.getFrequencySync();
>>>>>>>>>>>     totalPulse += pulseFreq;
>>>>>>>>>>>     //display totalPulse value to a textView;
>>>>>>>>>>>
>>>>>>>>>>>     Thread.sleep(100);
>>>>>>>>>>> }
>>>>>>>>>>>
>>>>>>>>>>>
>>>>>>>>>>> Current behavior is already as I expected, the totalPulse 
>>>>>>>>>>> textView will updated only when the hall sensor is spinning 
>>>>>>>>>>> (flow detected)
>>>>>>>>>>>
>>>>>>>>>>> If I use the getFrequencySync() method, I think the loop is 
>>>>>>>>>>> paused, waiting the flowMeter to receive input.
>>>>>>>>>>>
>>>>>>>>>>> If it received input, the totalPulse will increase by the 
>>>>>>>>>>> amount of pulseFreq from getFrequencySync().
>>>>>>>>>>>
>>>>>>>>>>> I haven't tested with real water yet (I just blow the flow 
>>>>>>>>>>> sensor to make the hall spin for early development test)
>>>>>>>>>>>
>>>>>>>>>>> My question, is it correct to use this approach with the 
>>>>>>>>>>> getFrequencySync() method?
>>>>>>>>>>> Or I still need to hack the DigitalInputImpl to count the pulses?
>>>>>>>>>>>
>>>>>>>>>>> Thanks
>>>>>>>>>>>
>>>>>>>>>>> On Wednesday, August 23, 2017 at 4:18:28 AM UTC+7, Ytai wrote:
>>>>>>>>>>>>
>>>>>>>>>>>> It is known, but there isn't currently a plan to add it. If 
>>>>>>>>>>>> anyone wants to contribute a patch, I will happily consider 
>>>>>>>>>>>> adopting it.
>>>>>>>>>>>>
>>>>>>>>>>>> On Aug 13, 2017 8:21 PM, "Maximillian" <[email protected]> 
>>>>>>>>>>>> wrote:
>>>>>>>>>>>>
>>>>>>>>>>>>> Is this still a known missing feature? As this post is from 
>>>>>>>>>>>>> 2013.. I need to use flow sensor as well..
>>>>>>>>>>>>>
>>>>>>>>>>>>> On Monday, September 9, 2013 at 10:31:46 AM UTC+7, Ytai wrote:
>>>>>>>>>>>>>>
>>>>>>>>>>>>>> This is known missing feature. You can work around this by 
>>>>>>>>>>>>>> hacking DigitalInputImpl to count the pulses: its setValue() 
>>>>>>>>>>>>>> method will 
>>>>>>>>>>>>>> get called on every edge.
>>>>>>>>>>>>>>
>>>>>>>>>>>>>>
>>>>>>>>>>>>>> On Fri, Sep 6, 2013 at 11:21 AM, jorge sb <[email protected]
>>>>>>>>>>>>>> > wrote:
>>>>>>>>>>>>>>
>>>>>>>>>>>>>>> Hi. I want to connect a hall sensor flow meter to ioio.
>>>>>>>>>>>>>>> Perhaps, I could use "PulseInput" but after reading 
>>>>>>>>>>>>>>> ioio-wiki, I see that I can't do it with it.
>>>>>>>>>>>>>>> Really, I need a simple pulse counter but without loosing 
>>>>>>>>>>>>>>> any pulse.
>>>>>>>>>>>>>>> With flow meter I will like to get:
>>>>>>>>>>>>>>> - Total liquid flow (accumulated countered pulses)
>>>>>>>>>>>>>>> - Instant flow (reading difference between two counts in a 
>>>>>>>>>>>>>>> measured time).
>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>> With this sensor I could get a pulse every 50 msec or less 
>>>>>>>>>>>>>>> at max rate.
>>>>>>>>>>>>>>> I think I could loose pulses doing periodic read of digital 
>>>>>>>>>>>>>>> input.
>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>> Some suggestion.
>>>>>>>>>>>>>>> Thanks.
>>>>>>>>>>>>>>>  
>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>> -- 
>>>>>>>>>>>>>>> You received this message because you are subscribed to the 
>>>>>>>>>>>>>>> Google Groups "ioio-users" group.
>>>>>>>>>>>>>>> To unsubscribe from this group and stop receiving emails 
>>>>>>>>>>>>>>> from it, send an email to [email protected].
>>>>>>>>>>>>>>> To post to this group, send email to 
>>>>>>>>>>>>>>> [email protected].
>>>>>>>>>>>>>>> Visit this group at 
>>>>>>>>>>>>>>> http://groups.google.com/group/ioio-users.
>>>>>>>>>>>>>>> For more options, visit 
>>>>>>>>>>>>>>> https://groups.google.com/groups/opt_out.
>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>
>>>>>>>>>>>>>> -- 
>>>>>>>>>>>>> You received this message because you are subscribed to the 
>>>>>>>>>>>>> Google Groups "ioio-users" group.
>>>>>>>>>>>>> To unsubscribe from this group and stop receiving emails from 
>>>>>>>>>>>>> it, send an email to [email protected].
>>>>>>>>>>>>> To post to this group, send email to [email protected]
>>>>>>>>>>>>> .
>>>>>>>>>>>>> Visit this group at https://groups.google.com/group/ioio-users
>>>>>>>>>>>>> .
>>>>>>>>>>>>> For more options, visit https://groups.google.com/d/optout.
>>>>>>>>>>>>>
>>>>>>>>>>>> -- 
>>>>>>>>>>> You received this message because you are subscribed to the 
>>>>>>>>>>> Google Groups "ioio-users" group.
>>>>>>>>>>> To unsubscribe from this group and stop receiving emails from 
>>>>>>>>>>> it, send an email to [email protected].
>>>>>>>>>>> To post to this group, send email to [email protected].
>>>>>>>>>>> Visit this group at https://groups.google.com/group/ioio-users.
>>>>>>>>>>> For more options, visit https://groups.google.com/d/optout.
>>>>>>>>>>>
>>>>>>>>>> -- 
>>>>>>>>> You received this message because you are subscribed to the Google 
>>>>>>>>> Groups "ioio-users" group.
>>>>>>>>> To unsubscribe from this group and stop receiving emails from it, 
>>>>>>>>> send an email to [email protected].
>>>>>>>>> To post to this group, send email to [email protected].
>>>>>>>>> Visit this group at https://groups.google.com/group/ioio-users.
>>>>>>>>> For more options, visit https://groups.google.com/d/optout.
>>>>>>>>>
>>>>>>>>
>>>>>>>> -- 
>>>>>> You received this message because you are subscribed to the Google 
>>>>>> Groups "ioio-users" group.
>>>>>> To unsubscribe from this group and stop receiving emails from it, 
>>>>>> send an email to [email protected].
>>>>>> To post to this group, send email to [email protected].
>>>>>> Visit this group at https://groups.google.com/group/ioio-users.
>>>>>> For more options, visit https://groups.google.com/d/optout.
>>>>>>
>>>>>
>>>>> -- 
>>>> You received this message because you are subscribed to the Google 
>>>> Groups "ioio-users" group.
>>>> To unsubscribe from this group and stop receiving emails from it, send 
>>>> an email to [email protected].
>>>> To post to this group, send email to [email protected].
>>>> Visit this group at https://groups.google.com/group/ioio-users.
>>>> For more options, visit https://groups.google.com/d/optout.
>>>>
>>> -- 
>> You received this message because you are subscribed to the Google Groups 
>> "ioio-users" group.
>> To unsubscribe from this group and stop receiving emails from it, send an 
>> email to [email protected] <javascript:>.
>> To post to this group, send email to [email protected] 
>> <javascript:>.
>> Visit this group at https://groups.google.com/group/ioio-users.
>> For more options, visit https://groups.google.com/d/optout.
>>
>

-- 
You received this message because you are subscribed to the Google Groups 
"ioio-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/ioio-users.
For more options, visit https://groups.google.com/d/optout.

Reply via email to