Message Boards Message Boards

Where are the output values from DeviceRead for Arduino pins?

Posted 8 years ago

I am reading pins 2-13 from a connected Arduino using DeviceRead from a script file (*.wl)..

However, nothing is output with regard to the values that are read from the Arduino. Where is the output? How can that output be used in the script?

I am runnning Wolfram v10.3 on a Raspberry Pi3, connected to an Arduino UNO via /dev/ttyACM0.

The script file contains

arduino=DeviceOpen["Arduino", "/dev/ttyACM0"];                          
DeviceRead[arduino,{2,3,4,5,6,7,8,9,10,11,12,13}];

Is output produced by the DeviceRead? If so, where does that output go?

The above commands work fine when run via the on-line (interactive) Wolfram Language program.

POSTED BY: ken Kashmarek
3 Replies
Posted 8 years ago

I suggest you to use ToString to convert allpins output. Looks like wolfram kernel when used as script misses to print Association output on stdout

sqatesla01lx:/Test/Mathematica/M-LINUX-L/11.0.1.0/5585670/Executables> cat readpin.wl
arduino = DeviceOpen["Arduino","/dev/ttyACM0"];
Print[ToString[DeviceRead[arduino]]]

sqatesla01lx:/Test/Mathematica/M-LINUX-L/11.0.1.0/5585670/Executables> wolfram -script readpin.wl
<|2 -> 0, 3 -> 0, 4 -> 0, 5 -> 0, 6 -> 0, 7 -> 0, 8 -> 0, 9 -> 0, 10 -> 1, 11 -> 0, 12 -> 0, 13 -> 0, A0 -> 1.36364 volts, A1 -> 1.35875 volts, A2 -> 1.26100 volts, A3 -> 1.15836 volts, A4 -> 1.06061 volts, A5 -> 1.05083 volts|>

POSTED BY: Updating Name
Posted 8 years ago

Under a topic call WolframScripting, the following parameters are supposed to be pertinent:

-print all            prints all messages generated
-verbose            prints everything

Yet, these don't work for my simple script. Further, execution of the same script repeatedly, runs WITHOUT message or the DeviceRead fails with a timeout (even when changed to read only pin 2, not all pins).

I did come across this:

Raspberry Pi3 attached UNO devices

pi@rPi3:~ $ ls -l /dev/ttyA*

crw-rw---- 1 root dialout 166, 0 Aug 29 14:07 /dev/ttyACM0

crw-rw---- 1 root dialout 204, 64 Aug 29 13:50 /dev/ttyAMA0

*** they are listed as dialout!!!

Since the emulated USB ports are serial devices by nature, I suspect this may be applicable, but it may also reflect that the device is not be handled correctly by Wolfran Language when running in a script. When executed interactively, it works correctly.

The /dev/ttyACM0 device has been confirmed as the device connected to the UNO board from the Arduino IDE (it was used to upload a sketch that ran successfully after uploading).

Does anyone have any insight into this issue? Please?

POSTED BY: ken Kashmarek
Posted 8 years ago

Update to the original question with more input...

  • from the on-line execution of wolfram

Wolfram Language (Raspberry Pi Pilot Release) Copyright 1988-2016 Wolfram Research Information & help: wolfram.com/raspi

In[1]:= arduino=DeviceOpen["Arduino","/dev/ttyACM0"];

In[2]:= arduino
Out[2]= DeviceObject[{Arduino, 1}]

In[3]:= allpins=DeviceRead[arduino,{2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19}];

In[4]:= allpins
Out[4]= ArduinoLinkPrivateArduinoReadDriver[{e30e0b83-13f8-4f26-85d2-1eff85d6\

 8587, SerialLink`SerialPort[/dev/ttyACM0, {115200, 8, None, None, None}]}
, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19]
  • content of readpin2.wl script file

arduino=DeviceOpen["Arduino","/dev/ttyACM0"]; arduino allpins=DeviceRead[arduino,{2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19}]; allpins

  • execution of the script file

pi@rPi3:/Shared/wolfram $ wolfram -script readpin2.wl pi@rPi3:/Shared/wolfram $ wolfram -script readpin2.wl > xxx.txt pi@rPi3:/Shared/wolfram $ ls -l

-rw-r--r-- 1 pi pi 139 Aug 25 17:33 readpin2.wl

-rw-r--r-- 1 pi pi 0 Aug 25 18:32 xxx.txt

So, how can I get output from the executing script file?

POSTED BY: ken Kashmarek
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