You will now need to edit files /etc/inittab and /boot/cmdline.txt as described at RPi_Serial_Connection#Preventing_Linux_using_the_serial_port. When you have done this - remember to reboot after editing - the terminal emulator set up in Step 1 will no longer show any output from Linux - it is now free for use by programs.
Syntax of mode (display a list of mode commands & options) C: > mode/? Sakyubasu no tatakai hacked save. Open COM4 in write mode (for Microsoft Windows only) $fp =fopen('com4', 'w'); or your can use $fp =fopen('com4', 'r+'); for read & write Open USB serial port for read and write (for Linux) $fp =fopen('/dev/ttyUSB0',r+'); Open first serial port in read & write (for Linux) $fp = fopen('/dev/ttyS0','r+'); To terminate string with Carriage Return fwrite($fp, 'string to send r'); To terminate string with New Line & Carriage Return fwrite($fp, 'string to send n r'); Close the serial port fclose($fp).
I have attempted serial comm via PHP to Arduono using a WAMP install on a PC. Serial comms seemed to work only one way. And I was told that this was a PC issue, but on MAC/Linux, PHP serial comm works two ways without issue. I have previously set up a RPi with Apache, MySQL and PHP.
(for some added support/features in an MQTT set-up/project) I have never attempted to use PHP serial communication when things were on a Pi. I will have an Arduino connected to the RPi. The RPi will have a webpage served up that I write.
What I would like to happen is upon clicking a link/hotspot in the hosted webpage it to send some serial data upon $_POST[] to the connected Arduino via PHP. Have the webpage sit in an 'idle' state. And when the Arduino is done doing its task(s). Send out a serial message back to the RPi/PHP script. And then change the display state/view of the hosted webpage.
(waiting for another 'user interaction' so to speak) Re-cap: Is 2-way serial communication possible with PHP when running on an RPi3? @DougieLawson Thank you for the reply. That seemed to work (no more port not open errors). I have moved away from testing on my Windows PC/WAMP.
And have moved over to the RPI. Everything as far as set-up and installing apps/packages is working as expected. I have a DB with populated table(s). And my web app is loading and displaying all dynamically generated content correctly as well. My current testing phase is actual serial communication (2-way) from RPi/PHP >> Arduino. Arduino >> RPi/PHP Since I can not do this in a Windows environment, I have my Arduino connected via USB to my RPI. I load up the Chromium browser.
And my web page (drink menu) is displayed to me. I click on the 'order' button. (which saves the button data to a hidden field, upon $_POST. That data is sent via PHP to the connected Arduino.) And here is where I am currently. * Since the Arduino is now connected via USB to the RPi. I can not use the serial monitor to know when/what serial data is being sent BACK to the RPi. * I believe that the Arduino is receiving the (some) serial data.
Because when I click on the 'order' button and submit the webpage. I see the RX/TX lights on the Arduino start to blink. Question: I'm having trouble thinking of a way I can DEBUG this. (without serial monitor or a way to see what is being sent BACK to the RPi).
I was also not clear on how to go about reading (listening) to the serial port. Since the webpage will already be parsed after submission (to display a please wait type message). So I figured possibly an AJAX type of approach. So the page can send initial serial data to connected Arduino. Display a 'please wait' message. (All done server side via PHP after submit) and then have a little AJAX snippet call an external PHP script that does the serial read?
(also not sure where the best places to open/close the port is. If using an external script to READ the serial port?) Can 1 php script open the port. And another still access it? Here is my current approach to attempt to read the SERIAL data back form the Arduino after it is finished (no telling when this data will come back from the Arduino). Linux follows the 'everything is a file' motto of Unix. As soon you plug an Arduino into the Raspberry, a file should magically appear in /dev. This file represents a serial port and can be read and written to.