Hi Bohdan,
You can in fact use the Mathematica Arduino driver for this : http://reference.wolfram.com/language/ref/device/Arduino.html
You will need a way to connect to the device and read from it. For your specific MAX 6675 device, there is an Adafruit library you can use to interface with the device. The basic gist of this is that you download the library somewhere on your computer, then you can deploy a customized sketch to the Arduino that then acts like a wrapper to the Adafruit library. I use this library as an example because it is a simple one, but you can certainly forgo this library and directly do the SPI interaction using the Arduino SPI library, but that code is more complicated. I am basically copying the example code that Adafruit provides and turning it into Mathematica code.
First, we declare the initialization or global code that we need access to:
libInit = "
int thermoDO = 4;
int thermoCS = 5;
int thermoCLK = 6;
int vccPin = 3;
int gndPin = 2;
MAX6675 thermocouple(thermoCLK, thermoCS, thermoDO);
";
Next we declare the "BootFunction"
, which is akin to the setup
function normally found in Arduino sketches to setup our pins for us:
bootFunc = "void bootFunc(){
pinMode(vccPin, OUTPUT);
digitalWrite(vccPin, HIGH);
pinMode(gndPin, OUTPUT);
digitalWrite(gndPin, LOW);
delay(500);}
";
Finally, we make a simple wrapper function to return back the temperature in celsius as a Real
:
readFunc = "
double readTempCel(){
return thermocouple.readCelsius();
}";
Putting this all together in a call to DeviceConfigure we have :
DeviceConfigure["Arduino", "Upload"->{
"Libraries" -> {"SPI", "/path/to/MAX6675_library"},
Initialization -> libInit,
"BootFunction" -> <|"Code" ->bootFunc |>,
"Functions" -> <|"readCelsius"-><|"Code"->readFunc ,"ReturnType"->Real|>|>
}]
You can then execute the "readCelsius"
function with DeviceExecute as follows:
DeviceExecute["Arduino","readCelsius"]
Hope this helps.
Thanks,
Ian