php code to read a digital pin output in arduino

hi. i dont have an ethernet shield (they're expensive in our country), so im relying on PHP to read the output of my pin 12 and if it is one or on, it will connect to twitter to post a message. here's my problemS: 1. i do not know any PHP (as in none, even creating a file or starting up with it) 2. how can a PHP read the output in pin 12 3. how can PHP post a message in twitter

please help me..

PHP can't read Arduino pins. You could send the Arduino a message, on the serial port, asking it to tell you the value of a pin, and have the Arduino interpret that command, read the pin, and reply with the value that it read.

Which OS are you using?

  1. i do not know any PHP (as in none, even creating a file or starting up with it)

Then, you need to start here: http://www.php.net/docs.php or pick a different PC side language.

  1. how can a PHP read the output in pin 12

It can't.

  1. how can PHP post a message in twitter

The same as it posts to any other web server. See #1.

You could send the Arduino a message, on the serial port, asking it to tell you the value of a pin, and have the Arduino interpret that command, read the pin, and reply with the value that it read.

yes, that's what i was hoping to do

yes, that's what i was hoping to do

Whether you are actually able to do this depends on your ability to write code, and which OS you are running on. You didn't answer that part.

im sorry...im running windows 7 and i dont have any experience on PHP

im sorry...im running windows 7

Well, you will be, then. There is a flaw in the Windows OS that prevents PHP from reading serial data. It can write to the serial port, but not read from it.

So, while you might eventually figure out how to tell the Arduino that you want to know something that it knows, you will not be able to read its response. Not using PHP, anyway.

You could get a copy of Visual C# from Microsoft (they actually give it away), and write an application that communicates with the serial port. You can also create HTTP GET, PUT, and POST requests and send them off to be acted upon. Of course, you can then read any reply that is returned.

The help that comes with Visual C# is abysmally difficult to navigate, but, it does include a search field and does include examples. You could possibly copy an entire example and be talking to the Arduino and twitting in less than an hour. After you download and install the software, that is.

i actually have C# in here from microsoft... so am i still going to use PHP? can i make C# do the fuunction of PHP instead?

i actually have C# in here from microsoft...

Saves time having to download it, then.

so am i still going to use PHP?

I don't know. Are you? Why are you stuck on the idea of using a tool you know nothing about?

can i make C# do the fuunction of PHP instead?

I don't know. C# has the ability to do the job. Whether or not you can make it happen is the unknown.

I don't know. Are you? Why are you stuck on the idea of using a tool you know nothing about?

because that's the first suggestion from this forum...w/o an ethernet shield they said i should use PHP.

they said i should use PHP.

Now you know there are alternatives. Use an alternative if you understand the alternative better, or if the original suggestion is not appropriate for you.

PHP is not appropriate for you because of the flaw in the Windows OS. So, you don't really have that as an option.

Were you on a Linux system, the situation would have been different. There, PHP is able to read from the serial port, and to post HTTP GET, PUT, and POST requests, and Visual C# is not an option.

There is a flaw in the Windows OS that prevents PHP from reading serial data.

That's total BS! It is a PHP issue. If it was a windows issue, the serial monitor would not work. PHP was made for file handling and not I/O work. PHP can only write to the serial port as if the serial port is a file (just like batch files and VBscript can). If the poster is wanting to get data from the arduino using apache as an interface, then he needs to write a simple CGI application that can be the go between to open the serial port, do the I/O with the arduino, then pass the results to apache. In years past I actually used qbasic to do the job. More recently I made an application using freebasic to do the job. PHP was not designed to do serial I/O operations.

That's total BS! It is a PHP issue.

No, it isn't. I've looked at how PHP writes to the serial port. The connection between PHP and the hardware is platform dependent. The necessary API to read from the serial port on Windows is private, and can not be called from non-Microsoft code.

Spend some time with Google if you like. No one has been able to find a workaround to the problem for any version of Windows.

No, it isn't. I've looked at how PHP writes to the serial port. The connection between PHP and the hardware is platform dependent. The necessary API to read from the serial port on Windows is private, and can not be called from non-Microsoft code.

Do you expect an application written and complied for the linux OS to also magically run under the windows OS? Generally speaking, applications need to be written to be compliant for the OS for which they are written. At one time one could bit bang the parallel port pins in windows. User level access to the hardware is generally not available in the current windows OS.

Spend some time with Google if you like. No one has been able to find a workaround to the problem for any version of Windows.

Well, using PHP on windows for serial port I/O is somewhat like trying to find a workaround to make a Ford piston fit into a chevy engine. Obviously sometime in the past the PHP pied piper swept thru this forum and convenced many that PHP should/could be used for serial port I/O on windows. From my limited reading in the past about PHP, it was designed for file operations to support dynamic web pages and not hardware I/O. The fact that it can be used on linux for serial port operations is probably a quirk of linux where hardware I/O is similar to DOS in the old days. For web based serial I/O on current windows, one can make a simple exe using free basic to do the job.

Just as a followup, some time back I posted some code in the below discussion that I tested for use with apache to control an ssc-32 servo controller. The issue of the arduino resetting when a com port is opened would still have to be addressed. If the resetting can be fixed, then arduino web based control via apache would be fairly easy.

http://www.lynxmotion.net/viewtopic.php?f=28&t=1874