A
A
Alexander Berezutsky2017-11-27 19:39:29
Arduino
Alexander Berezutsky, 2017-11-27 19:39:29

How to read analog pins of Arduino Uno in Wolfram Mathematica?

So, I need to connect my Arduino UNO to Mathematica and read 3 analog values ​​from pins A0, A1, A2, which are connected via a photodiode.
From what I understand, there are 2 ways I can communicate with the Arduino Uno via Mathematica:
First , I have a properly working Arduino IDE sketch that can be uploaded to the device via Mathematica. About the same as it is described here:
community.wolfram.com/groups/-/m/t/936358
However, I can't insert codestr in the correct format, Mathematica gives a compilation error all the time.
Here is my sketch, which compiles and works correctly:

int raw1 = 0, raw2 = 0, raw3 = 0;
    int x = 0, y1 = 0, y2 = 0, y3 = 0;

    void setup() 
    {
    Serial.begin(9600);
    pinMode( A0, INPUT );
    pinMode( A1, INPUT );
    pinMode( A2, INPUT );
    analogReference(INTERNAL);
    }

    void loop() 
    {
    while (x<=6000)
    { 
    raw1 = analogRead( A0 );
    y1=raw1;
    raw2 = analogRead( A1 );
    y2=raw2;
    raw3 = analogRead( A2 );
    y3=raw3;
    x++;               
    Serial.print( y1 );
    Serial.print("\t"); 
    Serial.print( y2 );
    Serial.print("\t");                
    Serial.print( y3 );
    Serial.println();
    delay(400);
    }
    }

Secondly, in Mathematica 11 (the version I use) there are a number of commands that allow you to communicate with the device without the help of the Arduino IDE language. As far as I understand, if I want to read 3 values ​​every 0.01 seconds for a second, my code should look like this:
Uno = DeviceOpen["Arduino", "COM3"];

    DeviceConfigure[Uno, <|"A0" -> "AnalogInput", "A1" -> "AnalogInput", "A2" -> "AnalogInput"|>];

    DeviceReadTimeSeries[Uno, {1, 0.01}, {"A0", "ReadMode" -> "Analog"}]
    DeviceReadTimeSeries[Uno, {1, 0.01}, {"A1", "ReadMode" -> "Analog"}]
    DeviceReadTimeSeries[Uno, {1, 0.01}, {"A2", "ReadMode" -> "Analog"}]

    DeviceClose[Uno]

But Mathematica refuses to compile and writes the following error:
CCompilerDriver`CreateObjectFile::cmperr: Compile error: avr-g++: error:C:\Users\Username\AppData\Local\Temp\arduinocompile1420c72c8f614b19b9df9d5891fcf275\SketchTemplate.cpp.c: No such file or directory

Anyone could help with this issue?
I will be grateful for any response.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
vanyamba-electronics, 2017-11-28
@vanyamba-electronics

The SketchTemplate.cpp file is not found.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question