Setting (ADC) Analog Read Speed


#1

For the following example I’d like to adjust the speed of analog read or adc.read but the variable I’m trying to change doesn’t seem to impact the output.  Can someone suggest the appropriate mechanism to call the init function for the adc module to make this functional appropriately?  I need to know/control how fast data are acquired.  Also, any help related to capturing execution time in milliseconds would be appreciated–that feature doesn’t seem to be in the timer examples. 

################################################################################

Analog Read

Created by VIPER Team 2015 CC

Authors: G. Baldi, D. Mazzei

################################################################################

import streams # import the streams module
import adc # import the adc driver
import timers

create a stream linked to the default serial port

streams.serial()
#define the analog pin for reading the value
inputAnalog = A0
pinMode(inputAnalog,INPUT_ANALOG)
pinMode(LED0,OUTPUT)
#changing the latter variable doesn’t seem to influence anything
##HELP?
adc.init(inputAnalog, samples_per_second=50000)
###END HELP

t=timers.timer()

start the timer

t.start()

while True:

digitalWrite(LED0, HIGH)  # turn the LED ON by setting the voltage HIGH
sleep(500)               # wait for a 0.5 second
digitalWrite(LED0, LOW)   # turn the LED OFF by setting the voltage LOW
sleep(500)               # wait for a 0.5 second

Basic usage of ADC for acquiring the analog signal from a pin

value = adc.read(A0)
print("One sample:",value)

#acquire user defined samples with default sampling period
t0 = t.get()

t0 = timers.now()

value2 = adc.read(inputAnalog,5000)

print type(value2)#this will bork if values are too long

t1 = timers.now()

t1 = t.get()
#print("10 samples:\

",value2)
print(t1-t0)#would like to print the ellapsed time in milliseconds
print()
sleep(300)


```

#2

@LorenzoRizzello implemented this amazing SmartSensors lib that does exactly what you need 
https://rawgit.com/viper-dev/lib-smartsensors/r0.3.0/docs/html/index.html

let us know
D


#3

floyd,

This looks extremely promising, however, I’m running into an error for which I could use some help. This error appears for all of the examples I tried from the library examples.  I am using Win10 and an Arduino DUE.

Whenever I import the smartsensors library such as this:

from smartsensors import analogSensors

I get the following error:

[COMPILER]: Getting: C:\Users\viper\env\core\official\vhal\armcmx\atmelsam3x\vhal_tim.c from cache
[COMPILER]: Getting: C:\Users\viper\env\core\official\stdlib\csrc/hwtimers\hwtimers.c from cache
[COMPILER]: Getting: C:\Users\viper\env\core\official\vhal\armcmx\atmelsam3x\vhal_adc.c from cache
[COMPILER]: Getting: C:\Users\viper\env\core\official\stdlib\csrc/vbl/vbl_adc.c from cache
[COMPILER]: Linking C code…
[COMPILER]: Oooops, there are undefined symbols! {’_timReset’: ‘00000000’}
[COMPILER]: in  at line 0: C Native Error: undefined symbols!


Any suggestions?

#4

Have you updated to the last version of the VIPER suite?

Check for new updates using the package manager (puzzle icon on the left).


#5

I have updated to the IDE and package list and I am at r0.3.0 for the TOIShield and smartsensors package.  Any other ideas to deal with this issue?

  • r0.3.1 - board.viper.arduino_due
  • r0.3.1 - board.viper.particle_core
  • r0.3.1 - board.viper.particle_photon
  • r0.3.1 - board.viper.st_nucleof401re
  • r0.3.1 - board.viper.udoo
  • r0.3.1 - core.viper.boards_standard
  • r0.3.1 - core.viper.compiler
  • r0.3.1 - core.viper.core
  • r0.3.1 - core.viper.docs
  • r0.3.1 - core.viper.examples
  • r0.3.5 - core.viper.ide
  • r0.3.2 - core.viper.stdlib
  • r0.3.2 - core.viper.toolbelt
  • r0.3.1 - core.viper.uplinker
  • r0.3.2 - core.viper.vm
  • r0.3.2 - core.viper.vpm
  • r0.3.2 - lib.viper.bcm43362
  • r0.3.1 - lib.viper.cc3000
  • r0.3.0 - lib.viper.smartsensors
  • r0.3.0 - lib.viper.toishield
  • r1.0.0 - sys.viper.armgcc-windows64
  • r1.0.0 - sys.viper.bossac-windows64
  • r1.0.0 - sys.viper.browser-windows64
  • r1.0.0 - sys.viper.dfu-windows64
  • r0.3.0 - sys.viper.git-windows64
  • r0.3.0 - sys.viper.runtime-windows64
  • r0.3.1 - vhal.viper.armcmx_atmelsam3x
  • r0.3.1 - vhal.viper.armcmx_stm32f_common
  • r0.3.1 - vhal.viper.armcmx_stm32f1
  • r0.3.1 - vhal.viper.armcmx_stm32f2
  • r0.3.1 - vhal.viper.armcmx_stm32f4
  • r0.3.1 - vm.viper.arduino_due
  • r0.3.1 - vm.viper.particle_core
  • r0.3.1 - vm.viper.particle_photon
  • r0.3.1 - vm.viper.st_nucleof401re
  • r0.3.1 - vm.viper.udoo

#6

bug confirmed on Arduino Due compilation only.
We will fix it asap and notify here
Thanks for the feedback


#7

A temporary workaround is to “import icu” together with smartsensors…
A fix will be released soon.


#8

Thanks that seems to address the issue.