Go Down

Topic: PHP gets stuck trying to connect to Arduino (Read 723 times) previous topic - next topic

mkm29

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";
}

SurferTim

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

mkm29

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

SurferTim

#3
Mar 18, 2014, 01:47 am Last Edit: Mar 18, 2014, 01:58 am by SurferTim Reason: 1
I use the command line in Linux (and Raspberry Pi) to get permissions on files and devices.
Code: [Select]
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.

mkm29

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....

mkm29

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 :)

Go Up
 


Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

Arduino
via Egeo 16
Torino, 10131
Italy