Read Serial Port with PHP, HELP

HI

I have Downloed PHP "Class to support serial port access" Google Code Archive - Long-term storage for Google Code Project Hosting., i run a Zentyal Server with LAMP, and i dont know i to read a single "Serial.println(" GB large.");" From arduino, to dysplay on HTML page.
Help Please i have to give this Work until Friday.

run a Zentyal Server with LAMP

What is this?

i dont know i to read a single "Serial.println(" GB large.");"

What does this mean? Serial.println() will send a string across the serial port. Are you trying to read that string with your PHP script? Or are you trying to send a string to the Arduino?

Help Please i have to give this Work until Friday.

This statement will not have any impact on when you receive answers. (It does however, make me wonder if this is a homework assignment.)

Zentyal is a Network Gateway, Unified Threat Manager, Office Server, Infrastructure Manager, Unified Communications Server or a combination of them. All services based on the same technology and fully integrated. For the first time you can make your network act as one single unit.

The Linux small business server.

I have this PHP code;

<?php include "php_serial.class.php"; // Let's start the class $serial = new phpSerial; // First we must specify the device. This works on both linux and windows (if // your linux serial device is /dev/ttyS0 for COM1, etc) $serial->deviceSet("/dev/ttyUSB0"); // Then we need to open it $serial->deviceOpen(); $read = $serial->readPort(); // If you want to change the configuration, the device must be closed $serial->deviceClose(); // We can change the baud rate $serial->confBaudRate(9600); echo $read; ?>

on Arduino i Have;

void setup() {
  Serial.begin(9600);
  
}

void loop() {
 
  Serial.println(12);
}

when i put url from php page i don´t showm nothing!!!!!

The serial rate is 9600 in the Arduino code, but some default serial rate and then 2400 in the PHP code. Shouldn't the rate be the value be the same between the two (9600)?

I put a same Baud, on arduino and php, i wrong when post the last part of code.

ntmg:
I put a same Baud, on arduino and php, i wrong when post the last part of code.

I don't know anything about this class, and documentation seems sparse - but based on the class comments, and this thread:

http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1218903707

The following is probably closer to what you want (???):

<?php 
include "php_serial.class.php"; 

// Let's start the class 
$serial = new phpSerial(); 

// First we must specify the device. This works on both linux and windows (if 
// your linux serial device is /dev/ttyS0 for COM1, etc) 
$serial->deviceSet("/dev/ttyUSB0"); 

// Set for 9600-8-N-1 (no flow control)
$serial->confBaudRate(9600); //Baud rate: 9600
$serial->confParity("none");  //Parity (this is the "N" in "8-N-1")
$serial->confCharacterLength(8); //Character length     (this is the "8" in "8-N-1")
$serial->confStopBits(1);  //Stop bits (this is the "1" in "8-N-1")
$serial->confFlowControl("none");

// Then we need to open it 
$serial->deviceOpen(); 

// Read data
$read = $serial->readPort(); 

// Print out the data
echo $read; 

// If you want to change the configuration, the device must be closed 
$serial->deviceClose(); 
?>

This is all untested; maybe that other thread can shed some light - good luck!

:slight_smile:

$serial->deviceOpen();

Unless you have modified your Arduino to not reset when the serial port is opened, this resets the Arduino.

$read = $serial->readPort();

This reads whatever the Arduino has written to the serial port in the last few nano-seconds. It's still resetting, so that would be nothing.

// If you want to change the configuration, the device must be closed
$serial->deviceClose();

You want to set the configuration properly, first, not after attempting to read from the port. This also resets the Arduino.

void loop()
{
  Serial.println(12);
}

If this is all the Arduino does, is there really a point to it?

I am Working on VB to read Serial, i look to import MSCOM in PHP, but doesn´t work very weel.

A Question. This push Buttom will work like This:

#include <glcd.h>

#include "fonts/allFonts.h"         // system and arial14 fonts are used
#include "bitmaps/allBitmaps.h"       // all images in the bitmap dir 

Image_t icon;

 int choise;
gText textArea;              // a text area to be defined later in the sketch
gText textAreaArray[3];      // an array of text areas  
gText countdownArea =  gText(GLCD.CenterX, GLCD.CenterY,1,1,Arial_14); // text area for countdown digits

const int buttonPin[] = {38,39,40,41,42,43};     // the number of the pushbutton pin
int pinCount =6;
int val[6];

int buttonState = 0;
unsigned long startMillis;
unsigned int  loops = 0;
unsigned int  iter = 0;
         int  theDelay = 20; 
         

void setup()
{
  int thisPin;
    for (int thisPin = 0; thisPin < pinCount; thisPin++)  {
    pinMode(buttonPin[thisPin], INPUT);      
  }    

  GLCD.Init();   // initialise the library, non inverted writes pixels onto a clear screen
  if(GLCD.Height >= 64)   
    icon = ArduinoIcon64x64;  // the 64 pixel high icon
  else
    icon = ArduinoIcon64x32;  // the 32 pixel high icon
  GLCD.ClearScreen(); 
introScreen();
  GLCD.SelectFont(System5x7, BLACK); // font for the default text area
}
void  loop()
{ 
//  int thisPin;
  
  GLCD.DrawRect(0, 0, GLCD.CenterX, GLCD.Bottom); // rectangle in left side of screen
    GLCD.DrawRoundRect(GLCD.CenterX + 2, 0, GLCD.CenterX - 3, GLCD.Bottom, 5);  // rounded rectangle around text area   
    for(int i=0; i < GLCD.Bottom; i += 4)
    GLCD.CursorToXY(GLCD.CenterX/2, GLCD.Bottom -15);          
    GLCD.CursorTo(0,0);
    GLCD.print("Pastelaria\n\n");
    GLCD.CursorTo(0,3);
    GLCD.print("Cafetaria\n\n");
    GLCD.CursorTo(0,6);
    GLCD.print("Cozinha\n\n");
    GLCD.CursorToXY(GLCD.CenterX + 16, 9);
    GLCD.print("Clique"); 
    GLCD.SelectFont(System5x7, BLACK);
    GLCD.CursorToXY(GLCD.CenterX + 4, 24);
    GLCD.print("no Botao");
   
   
   for (int thisPin = 0; thisPin < pinCount; thisPin++)  {
    val[thisPin] = digitalRead(buttonPin[thisPin]);      

if (buttonPin[0]== HIGH){
    Serial.println("Pastelaria");
    choise=0;
    scrollingDemo();
    
}else if(buttonPin[1]== HIGH){
    Serial.println("Cafetaria");
    choise=1;
    scrollingDemo();
    
}else if(buttonPin[3]== HIGH){
    Serial.println("Restaurante");
    choise=2;
    scrollingDemo();
}
   
   
}
}

void introScreen(){  
  GLCD.DrawBitmap(icon, 32,0); //draw the bitmap at the given x,y position
  countdown(3);
  GLCD.ClearScreen();
  GLCD.SelectFont(System5x7, BLACK); // you can also make your own fonts, see playground for details   
  GLCD.CursorToXY(GLCD.Width/2 - 44, 3);
  GLCD.print("Ementa Electronica");
  countdown(3);  
  GLCD.ClearScreen(); 
  
}
void countdown(int count){
  while(count--){  // do countdown  
    countdownArea.ClearArea(); 
    countdownArea.print(count);
    delay(1000);  
  

}  
}
void scrollingDemo(){
 
  GLCD.ClearScreen();  
//  int choise=-1;
   
  
   
  switch (choise) {
  case 0:   
    GLCD.CursorTo(0,0);
   GLCD.print("Bolo de Arroz\n");
   GLCD.CursorTo(0,3);
   GLCD.print("Nata\n");
   GLCD.CursorTo(0,6);
   GLCD.print("Bispo\n");
     break;
  case 1:   
   GLCD.CursorTo(0,1);
   GLCD.print("1=Cafe\n");
   GLCD.CursorTo(0,2);
   GLCD.print("2=Galao\n");
   GLCD.CursorTo(0,4);
   GLCD.print("3=Descafenado\n");  
    break;
  case 2:    
    GLCD.ClearScreen(); 
   GLCD.CursorTo(2,1);
   GLCD.print("1=Frango\n");
   GLCD.CursorTo(3,2);
   GLCD.print("2=Natas\n");
   GLCD.CursorTo(4,3);
   GLCD.print("3=Salada\n");
    break; 
  }
}

for(int i=0; i < GLCD.Bottom; i += 4)
GLCD.CursorToXY(GLCD.CenterX/2, GLCD.Bottom -15);

Why are you doing something in a loop that does not depend on the loop index?

if (buttonPin[0]== HIGH){

Let's see.

const int buttonPin[] = {38,39,40,41,42,43};     // the number of the pushbutton pin

So, buttonPin[0] is 38. No, 38 is not HIGH, so this block won't get executed.

}else if(buttonPin[1]== HIGH){

buttonPin[1] is 39. 39 is not HIGH, so this block won't get executed.

I think you want to compare val[thisPin] in these if tests, but, it doesn't make sense to store all the pin states in an array, when you never use the array again.

There is no reason to read the pin states in a for loop, when only one action per iteration of the loop can be invoked.