Group Abstract Group Abstract

Message Boards Message Boards

Can't connect to Serial Device using Mathematica 10 under Windows 7

GROUPS:

Following instructions as listed in the documentation Serial (RS-232 / RS-422 serial protocol I'm unable to successfully connect to the device (Arduino Uno) using

DeviceOpen["Serial",{"COM10","BaudRate"->9600}]
(*SerialLink`SerialPortOpen::nopen: Could not open the port COM10.*)

Port COM10 is alive, well and tested in the computer, using another program to link the device, send byte codes and receive values back. enter image description here

POSTED BY: Diego Zviovich
Answer
4 months ago

What is the set up in your Arduino? Can you show the sketch? Have you see the serial monitor ? I had similar problems. It looks like the Matematica kernel gets hang. Close the notepad or quick and restart kernel.

Also, you are using he putty client to capture the Port 10, therefore, Mathematica will not be able to capture it the same time.

POSTED BY: Jose Calderon
Answer
4 months ago

Hola Jose,

Indeed I closed the Serial Monitor and Putty. Only one program can communicate with the arduino at a time. The reason Im showing it on the screen is that indeed the COM10 port works with all tools except mathematica.

Here is the sketch

#include <dht11.h>
dht11 DHT11;
#define DHT11PIN 2
int inByte = 0; // incoming serial byte
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);

}

void loop() {
// put your main code here, to run repeatedly:
if (Serial.available() > 0) {
// get incoming byte:
inByte = Serial.read();
if (inByte == 84){
int chk = DHT11.read(DHT11PIN);
Serial.println((float)DHT11.temperature, DEC);
}
if (inByte == 72){
int chk = DHT11.read(DHT11PIN);
Serial.println((float)DHT11.humidity, DEC);
}

}


}
POSTED BY: Diego Zviovich
Answer
4 months ago

Diego,

I am seeing the same issue: DeviceRead[serial] blocks and DeviceReadBuffer[serial] returns always {}

I'm using the following arduino sketch:

void setup() { Serial.begin(9600); }

void loop() { Serial.write(42); delay(1000); }

In a serial monitor this prints out asterisks (*) which is character code 42.

We looking into it and will update you when we have a solution.

POSTED BY: Arnoud Buzing
Answer
4 months ago

@Diego Try "\\.\COM10" instead of "COM10" as a workaround.

DeviceOpen["Serial", {"\\.\COM10", "BaudRate" -> 9600}]
POSTED BY: Fahim Chandurwala
Answer
4 months ago

@Fahim Chandurwala, thank you very much. It worked!!

I hope our friends from Wolfram update the documentation. There was no way that I would have figured that out without your help.

Now this works. Using the Arduino Sketch mentioned above.

DeviceOpen["Serial", {"\\.\COM10", "BaudRate" -> 9600}]
readSensor[connection_, type_] :=
Module[{}, DeviceWrite[connection, type]; Pause[.1];
FromCharacterCode[DeviceReadBuffer[conn]]]
(*Read Temperature*)
readSensor[conn,"T"]
(*31.00000*)
(*Read Humidity*)
readSensor[conn,"H")
(*42.00000*)
POSTED BY: Diego Zviovich
Answer
4 months ago

Diego, there will be a fix in Mathematica 10.0.1 to make "COMn" work for n>9. Thank you for reporting this.

POSTED BY: Arnoud Buzing
Answer
4 months ago

@Fahim Chandurwala This is ver interesting.. I just puzzled.. How did you figure this out?

Another thing,, I an confuse as to when to use Serial.println[] and when to use Serial.write[]? Can anyone comment here?

POSTED BY: Jose Calderon
Answer
4 months ago

Hola Jose, Serial.println and Serial.write are Arduino functions and not from mathematica.

For Serial.println > http://arduino.cc/en/Serial/Println

For Serial.write > http://arduino.cc/en/Serial/Write

POSTED BY: Diego Zviovich
Answer
4 months ago

Diego... My apologies for bringing an out of subject issue. I have been going back and forth between Arduino and Mathematica Devices forums. At some point the line got blurred. Thank you for the links.

POSTED BY: Jose Calderon
Answer
4 months ago