Message Boards Message Boards

2
|
16266 Views
|
9 Replies
|
12 Total Likes
View groups...
Share
Share this post:

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

Posted 10 years ago

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
9 Replies

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
Posted 10 years 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

@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
Posted 10 years 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

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

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

DeviceOpen["Serial", {"\\.\COM10", "BaudRate" -> 9600}]

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
Posted 10 years 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

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
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract