Fastest way to read Analog signal from AIO and store on Revpi

Moderator: RevPiModIO

Post Reply
User avatar
palmerpi
Posts: 21
Joined: 04 Feb 2019, 17:17
Location: Northern Ireland
Contact:

Fastest way to read Analog signal from AIO and store on Revpi

Post by palmerpi »

Hello, I have one Analog signal that I need to read and store as fast as possible. I am using Core 3+ and AIO. I also need to store the reading locally on revpi for a short period ideally in database. I have the Analog signal reading ok using Revpi node in node-red but it doesn't appear to be capturing the signal quickly enough. If for example I put on a 4-20ma source incrementing by 1ma every 0.1sec I only appear to capture every 3rd or 4th reading. Ideally I would like to capture every 20ms. Is there anything in node that I can do to improve this or should I try find a solution in Python or some other way. Thank you.
User avatar
nicolaiB
KUNBUS
Posts: 931
Joined: 21 Jun 2018, 10:33
Location: Berlin
Contact:

Re: Fastest way to read Analog signal from AIO and store on Revpi

Post by nicolaiB »

Hi palmerpi,

I would recommend a simple Python application using the revpimodio2 library. For storage you can use a in memory database or nearly any other database which runs on Linux.

A simple application with gathers information from two analog inputs every 20 milliseconds and prints the timestamp in milliseconds with the two value could look like this:

Code: Select all

#!/usr/bin/env python
# -*- coding: utf-8 -*-
# vim: ts=4:sw=4:et

import time
import revpimodio2

def loop(cycletools):
    timestamp_milliseconds = int(round(time.time() * 1000))

    analog_value1 = rpi.io.InputValue_1.value
    analog_value2 = rpi.io.InputValue_2.value

    print(timestamp_milliseconds, analog_value1, analog_value2)

# create new instance of revpimodio2 in readonly (monitoring) mode
rpi = revpimodio2.RevPiModIO(autorefresh=True, monitoring=True)

# catch SIGINT and handle proper release of all IOs
rpi.handlesignalend()

# start cycle loop, cycle time in milliseconds
rpi.cycleloop(loop, cycletime=20)

User avatar
palmerpi
Posts: 21
Joined: 04 Feb 2019, 17:17
Location: Northern Ireland
Contact:

Re: Fastest way to read Analog signal from AIO and store on Revpi

Post by palmerpi »

Brilliant. Thank you, thats just what I needed. I was making my python too complicated. This will work great.

Alan



quote=nicolaiB post_id=11251 time=1635946702 user_id=724]
Hi palmerpi,

I would recommend a simple Python application using the revpimodio2 library. For storage you can use a in memory database or nearly any other database which runs on Linux.

A simple application with gathers information from two analog inputs every 20 milliseconds and prints the timestamp in milliseconds with the two value could look like this:

Code: Select all

#!/usr/bin/env python
# -*- coding: utf-8 -*-
# vim: ts=4:sw=4:et

import time
import revpimodio2

def loop(cycletools):
    timestamp_milliseconds = int(round(time.time() * 1000))

    analog_value1 = rpi.io.InputValue_1.value
    analog_value2 = rpi.io.InputValue_2.value

    print(timestamp_milliseconds, analog_value1, analog_value2)

# create new instance of revpimodio2 in readonly (monitoring) mode
rpi = revpimodio2.RevPiModIO(autorefresh=True, monitoring=True)

# catch SIGINT and handle proper release of all IOs
rpi.handlesignalend()

# start cycle loop, cycle time in milliseconds
rpi.cycleloop(loop, cycletime=20)

[/quote]
User avatar
palmerpi
Posts: 21
Joined: 04 Feb 2019, 17:17
Location: Northern Ireland
Contact:

Re: Fastest way to read Analog signal from AIO and store on Revpi

Post by palmerpi »

Do you know if I can speed the time the actual analog refreshes? I'm not capturing the constantly changing reading on input 1.

Im using your script above with one input as an example and while the loop reads at 20ms the reading from the analog doesn't update at this rate.

e.g Time Milliamps
1636109023743 15934
1636109023764 15934
1636109023783 15934
1636109023803 15934
1636109023822 13795
1636109023843 13795
1636109023862 13795
1636109023882 13795
1636109023901 13795
1636109023922 13795
1636109023941 13795
1636109023961 13795
1636109023980 13795
1636109024001 13795
1636109024020 13795
1636109024040 13795
1636109024059 13795
1636109024080 13795
1636109024099 13795
1636109024119 13795
1636109024139 13795
1636109024159 13795
1636109024178 13795
1636109024198 13795
1636109024218 13795
1636109024238 13795
1636109024257 13795
1636109024278 13795
1636109024297 13795
1636109024317 13795
1636109024336 13795
1636109024357 13795
1636109024376 13795
1636109024396 13795
1636109024416 13795
1636109024436 13795
1636109024455 13795
1636109024476 13795
1636109024495 13795
1636109024515 13795
1636109024535 13795
1636109024555 13795
1636109024574 13795
1636109024595 13795
1636109024614 13795
1636109024634 11659
1636109024654 11659
1636109024674 11659
1636109024693 11659
1636109024713 11659




nicolaiB wrote: 03 Nov 2021, 14:38 Hi palmerpi,

I would recommend a simple Python application using the revpimodio2 library. For storage you can use a in memory database or nearly any other database which runs on Linux.

A simple application with gathers information from two analog inputs every 20 milliseconds and prints the timestamp in milliseconds with the two value could look like this:

Code: Select all

#!/usr/bin/env python
# -*- coding: utf-8 -*-
# vim: ts=4:sw=4:et

import time
import revpimodio2

def loop(cycletools):
    timestamp_milliseconds = int(round(time.time() * 1000))

    analog_value1 = rpi.io.InputValue_1.value
    analog_value2 = rpi.io.InputValue_2.value

    print(timestamp_milliseconds, analog_value1, analog_value2)

# create new instance of revpimodio2 in readonly (monitoring) mode
rpi = revpimodio2.RevPiModIO(autorefresh=True, monitoring=True)

# catch SIGINT and handle proper release of all IOs
rpi.handlesignalend()

# start cycle loop, cycle time in milliseconds
rpi.cycleloop(loop, cycletime=20)

User avatar
palmerpi
Posts: 21
Joined: 04 Feb 2019, 17:17
Location: Northern Ireland
Contact:

Re: Fastest way to read Analog signal from AIO and store on Revpi

Post by palmerpi »

Answered my own question. In PICTORY there is a setting for ADC_DATARATE. Changed to 160 Hz and that did the trick.
1636110598822 18614
1636110598843 18615
1636110598862 18615
1636110598883 13492
1636110598902 18545
1636110598922 18786
1636110598941 18786
1636110598962 15671
1636110598981 18599
1636110599001 18761
1636110599021 18761
1636110599041 17825



palmerpi wrote: 05 Nov 2021, 11:49 Do you know if I can speed the time the actual analog refreshes? I'm not capturing the constantly changing reading on input 1.

Im using your script above with one input as an example and while the loop reads at 20ms the reading from the analog doesn't update at this rate.

e.g Time Milliamps
1636109023743 15934
1636109023764 15934
1636109023783 15934
1636109023803 15934
1636109023822 13795
1636109023843 13795
1636109023862 13795
1636109023882 13795
1636109023901 13795
1636109023922 13795
1636109023941 13795
1636109023961 13795
1636109023980 13795
1636109024001 13795
1636109024020 13795
1636109024040 13795
1636109024059 13795
1636109024080 13795
1636109024099 13795
1636109024119 13795
1636109024139 13795
1636109024159 13795
1636109024178 13795
1636109024198 13795
1636109024218 13795
1636109024238 13795
1636109024257 13795
1636109024278 13795
1636109024297 13795
1636109024317 13795
1636109024336 13795
1636109024357 13795
1636109024376 13795
1636109024396 13795
1636109024416 13795
1636109024436 13795
1636109024455 13795
1636109024476 13795
1636109024495 13795
1636109024515 13795
1636109024535 13795
1636109024555 13795
1636109024574 13795
1636109024595 13795
1636109024614 13795
1636109024634 11659
1636109024654 11659
1636109024674 11659
1636109024693 11659
1636109024713 11659




nicolaiB wrote: 03 Nov 2021, 14:38 Hi palmerpi,

I would recommend a simple Python application using the revpimodio2 library. For storage you can use a in memory database or nearly any other database which runs on Linux.

A simple application with gathers information from two analog inputs every 20 milliseconds and prints the timestamp in milliseconds with the two value could look like this:

Code: Select all

#!/usr/bin/env python
# -*- coding: utf-8 -*-
# vim: ts=4:sw=4:et

import time
import revpimodio2

def loop(cycletools):
    timestamp_milliseconds = int(round(time.time() * 1000))

    analog_value1 = rpi.io.InputValue_1.value
    analog_value2 = rpi.io.InputValue_2.value

    print(timestamp_milliseconds, analog_value1, analog_value2)

# create new instance of revpimodio2 in readonly (monitoring) mode
rpi = revpimodio2.RevPiModIO(autorefresh=True, monitoring=True)

# catch SIGINT and handle proper release of all IOs
rpi.handlesignalend()

# start cycle loop, cycle time in milliseconds
rpi.cycleloop(loop, cycletime=20)

Post Reply