Pages: [1]   Go Down
Author Topic: PHP gets stuck trying to connect to Arduino  (Read 486 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 4
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I have already gotten my Raspberry Pi to send and receive commands to an Arduino via PHP over serial, but I do all of my coding on my Mac so I would like to be able to connect to it via my laptop.

I know the location of the port on my Mac, I have changed the permissions on this file and my PHP file (sudo chmod 666 file), but when I run the file via the command line or browser it gets stuck. Can someone help me debug this?

PHP code (this same code connects correctly on my RPi):

$handle = fopen("/dev/tty.usbmodem1421", 'r+');
if(!$handle) {
   echo "Error connecting";
} else {
   echo "Connected";
}
Logged

Miramar Beach, Florida
Offline Offline
Faraday Member
**
Karma: 115
Posts: 5386
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I recommend using double quotes on the mode. Insure that is the correct filename for that device on your Mac.
Code:
$handle = fopen("/dev/tty.usbmodem1421", "r+");
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 4
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I tried that as well, nothing. Learning from my Raspberry Pi experience it might be a permission issue...

So I opened the permissions on /dev/tty.usbmodem1421, as well as adding the _www and httpd users to the tty group....still nothing.

I am able to open the port and send/receive messages with the screen command line utility so I have no clue what is going on. Any help would be much appreciated. Thanks
Logged

Miramar Beach, Florida
Offline Offline
Faraday Member
**
Karma: 115
Posts: 5386
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I use the command line in Linux (and Raspberry Pi) to get permissions on files and devices.
Code:
cd /dev
ls -l
What group does the Arduino display in your Mac? In the RPi, the Arduino Mega 2560 (/dev/ttyACM0) owner is root and the group is dialout. To access that device, the user must have dialout added to his/her user group. The user "pi" in the RPi has dialout group by default. (edit: I'm not sure about default because I installed an Arduino IDE in the RPi, so that may have added the group dialout to the user "pi" during that install.)

I don't have access to a Mac right now, but with Linux, open a command prompt and type "groups". It should display what groups your user belongs to.
« Last Edit: March 17, 2014, 07:58:42 pm by SurferTim » Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 4
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Thanks. I ran the ls -l command and found out that the serial port location belongs to the 'wheel' group, so I added both my user and the Apache _www user to the wheel group but still nothing...oh well I have it successfully working on my Raspberry Pi I just wanted to get it working on my Mac so I could test code on my laptop before uploading it to my RPi....
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 4
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I finally got it working after lots of research/time...apparently if you want to use the stty or PHP command from the terminal you can't use the /dev/tty.usbmodem1421 (even though that is what I use in the Arduino IDE) you have to use /dev/cu.usbmodem1421 instead. Odd but glad that I finally figured it out smiley
Logged

Pages: [1]   Go Up
Jump to: