Reputation: 213
I am able to send data to my arduino, the leds in the middle of the board flash when I send a message. The exact same happens when I don't send a message, but just open and close the serial port. This either means the PhpSerial class is not sendig the message or the arduino is set up incorrectly.
My arduino code:
#include "USBSerial_main.h"
int incomingByte = 0;
int pin = 2;
void setup() {
Serial.begin(9600);
pinMode(2, OUTPUT);
digitalWrite(2, false);
}
void loop() {
if(Serial.available() > 0){
Serial.read();
digitalWrite(2, true);
delay(100);
digitalWrite(2, false);
}
}
My php code:
<?php
ini_set('display_errors', '1');
error_reporting(E_ALL);
include "PhpSerial.php";
$msg = '';
$comPort = "/dev/ttyACM0";
if(isset($_POST["hi"])){
$serial = new phpSerial;
$serial->deviceSet($comPort);
$serial->confBaudRate(9600);
$serial->confParity("none");
$serial->confCharacterLength(8);
$serial->confStopBits(1);
$serial->deviceOpen();
$serial->sendMessage("Well hello!");
$serial->serialflush();
$serial->deviceClose();
$msg = "Your message has been sent!";
}
?>
<html>
<head>
<title>hi</title>
</head>
<body>
<form method="POST">
<input type="submit" name="hi" value="Send">
</form><br>
<?=$msg?>
</body>
</head>
I have already modified the PhpSerial.php file, because it was not detecting the stty command, which is in fact available, the coreutils package is fully up to date.
I just took out the check like this:
//if ($this->_exec("stty") === 0) {
register_shutdown_function(array($this, "deviceClose"));
//} else {
// trigger_error(
// "No stty availible, unable to run.",
// E_USER_ERROR
// );
//}
What is going wrong and what do I do to fix this? Does it have to do with the version of PhpSerial (which I just pulled straight from github a few hours ago) or something else?
One more notice: it's doing exactly this using fopen.
System: Running Ubuntu 14.02 LTS in VBox.
Upvotes: 1
Views: 794
Reputation: 2672
As rslite has said, this is the delay time the bootloader uses to check for reprogram requests. For projects in "production" stage, it can be frustrating to find the program has reset every time you connect via serial to see what's going on. Especially for web based applications, where it will add to the page loading time.
You can disable auto reset on serial connection (link). There is the destructive and non destructive methods. I've duplicated the simple non destructive method here for quick reference. There are more details if you follow the link.
The simple way that doesn't require any permanent modifying of your hardware or software configuration changes:
Stick a 120 ohm resistor in the headers between 5v and reset (you can find these on the isp connector too). 120 is hard to find so just combine resistors. Don't go below 110 ohms or above 124 ohms, and don't do this with an isp programmer attached. You can just pull out the resistor when you want auto-reset back.
Perhaps add a switch or jumper if this is a more permanent arrangement? Or you may be able to remove a resistor from your arduino PCB - details of that are found in the link.
Even without the auto reset feature it's still quite easy to get code uploaded.
After that, the normal upload procedure should start with the RX/TX leds flashing madly. In case the IDE (or avrdude) throws an error, just work on your timing a bit. I'm doing this on a regular basis and it works well with the current bootloader.
Upvotes: 0
Reputation: 84813
One thing you might need to check is that the Arduino will reset when you open the serial connection, the bootloader runs and it takes a certain amount to start running your own code. You might try to add a delay of 1-2 seconds after deviceOpen
before sending the message.
Upvotes: 2