Hi guys,
I'm having trouble with my project that requires me not to use any shield.
So, I'm only using USB cable as the only connection to my laptop. I basically start a simple project by creating my own web server in my laptop and a simple PHP script to control an LED in the Arduino (the basic led in pin 13).
Here is my Arduino code:
I'm not that familiar with PHP, but you probably could do what you want to do using the apache web server and a batch file (the auto reset feature of the arduino would need to be defeated).
PHP is an interpreted language optimized for web servers (like Apache).
Back to the serial question, there are PHP libraries/classes for interfacing with the serial port, but I think all of them require the Direct IO extension to work.
If you're not comfortable building PECL extensions like Direct IO you'd probably be best to have your PHP script shell out to an external program to do the actual communication. The Interfacing with Software page provides many examples.
It looks as if your PHP page will open and close the serial port for each request. Normally, when you open the serial port this causes the Arduino to reset. You could confirm whether that's happening by writing a sketch which does something obvious when it resets.
Also, it looks to me as if your page is writing ASCII characters 0 (NUL) and 1 (SOH) but your sketch is looking for 48 ('0') and 49 ('1').
PHP is an interpreted language optimized for web servers (like Apache).
If the serving machine is a windows machine, PHP mat be no more functional than a simple batch file. It seems PHP on a windows writes to the serial port using the windows command processor, just like a simple batch file.
Hi guys, I actually did some revision to my project and it works...
Just want to share it with you guys, Correct me if it's just somehow works, but foremost I'm glad that it worked as what I wanted it to be.
I didn't change anything in my php script,
I think the magic works in 'chr(1)' and Arduino will still read it as '1'. The ASCII converter works in PHP. Correct me if I'm wrong
Should be (Bytein == 49) instead of (Bytein = 49). The latter always evaluates to true. You appear to have fixed that bug in your latest revision however.
I was actually testing this project, therefore I was more concerned on these 2 values. Well I guess to make this project more reliable I'd put 'else' so that it won't turn on/off the light if in any case, other values (such as byte 32) becomes the input. Correct me if I'm wrong
Well I guess to make this project more reliable I'd put 'else' so that it won't turn on/off the light if in any case, other values (such as byte 32) becomes the input. Correct me if I'm wrong
You should not turn the light on if the value isn't 1 and you shouldn't turn it off if the value isn't 0, if your goal is only to respond to those two values. Most importantly, the first call to turn the light on needs to go.