Answer the question
In order to leave comments, you need to log in
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);
}
}
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]
CCompilerDriver`CreateObjectFile::cmperr: Compile error: avr-g++: error:C:\Users\Username\AppData\Local\Temp\arduinocompile1420c72c8f614b19b9df9d5891fcf275\SketchTemplate.cpp.c: No such file or directory
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question