Hi, I would like to use the analog input from the Arduino on the UDOO Neo. Analog inputs are useless if you cannot read at a certain frequency. So my question is how to use a timer to read analog input on the Arduino? I tried the TimerOne library but I get an error at compile time : Code: WARNING: library TimerOne claims to run on [avr] architecture(s) and may be incompatible with your current board which runs on [solox] architecture(s). ~/Documents/src/arduino/sketch_sep15b/sketch_sep15b.ino: In function 'void setup()': sketch_sep15b:44: error: 'Timer9' was not declared in this scope Timer9.initialize(150000); ^ I also tried other libraries such as Metro, TimerDue, MsTimer, ... without success. Thanks
You could try to modify the library so that is usable on the Neo. Or you could use the following method to read an analog pin in an interval. https://www.arduino.cc/en/Tutorial/BlinkWithoutDelay
You should be able to use this library, it is based on millis() so No usage of hardware timers in the library. http://playground.arduino.cc/Code/SimpleTimer
Hi, Thanks for your reply I need to be able to read at a certain frequency (mesure the time beetween each reads) as precise as possible. Adding a lag with millis() is not a solution as reading analog input takes a few microseconds. Usually, the frequency of reading is about 100-200 us, 1ms is far too long :/
Then you have to look into the Arduino board manager sources https://github.com/UDOOboard/arduino-board-package yourself. Find out how the timers are working and adapt one of the libraries. And please share this with us.
Well, I edited the source code of SimpleTimer and I uncommented the line to use micros() instead of millis(). I'll try for my needs.
I was not able to use micros() but I found the HWtimer library in the board package (udooneo-arduino-solox-1.6.7/variants/udooneo/mqx/release/bsp/hwtimer.h). Here is the documentation on how to use the timer on Freescale MQX. An example with a 200us period timer: Code: #include <imx6sx_sdb_m4.h> #include <hwtimer_epit.h> #define PERIOD 200 #define NB_MESURES 600 float values[NB_MESURES]; HWTIMER timer; void readValue(void *param) { values[n] = analogRead(PIN); n = (n + 1) % NB_MESURES; } void setup() { analogReadResolution(12); Serial.begin(115200); hwtimer_init(&timer, &BSP_HWTIMER1_DEV, BSP_HWTIMER1_ID, 1); hwtimer_set_period(&timer, BSP_HWTIMER1_SOURCE_CLK, PERIOD); hwtimer_callback_reg(&timer, readValue, 0); hwtimer_start(&timer); } void loop() { }