Pages: [1]   Go Down
Author Topic: Serial communication from browser  (Read 1451 times)
0 Members and 1 Guest are viewing this topic.
Belgium
Offline Offline
Newbie
*
Karma: 0
Posts: 5
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi everybody,

I'm trying to do the following:
I'm using a live chat application. The problem is that I'm not always looking at my monitor. To make sure I don't miss any chats I wanted to activate a flashing lamp when a chat opens.

What I've got now:
Program that talkes with Arduino through serial USB (prossessing on windows Vista), lamp connected to the Arduino through a relay. Chat window in which I can change the code (or implement an iframe if necessary).

What I still need:
A way to send serial commands (ethernet shield isn't an option) from the browser to the Arduino. It's only for 1 PC, so if I have to install software locally, that's possible.
Anybody that can point me in the right direction ?
« Last Edit: June 29, 2011, 08:21:48 am by notexa » Logged

Belgium
Offline Offline
Newbie
*
Karma: 0
Posts: 5
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Attached is the schema of what I'm trying to do.


* arduino_brower_lamp.jpg (19.61 KB, 512x398 - viewed 28 times.)
Logged

London
Offline Offline
Full Member
***
Karma: 0
Posts: 168
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

You'll probably need something like a webserver running on your PC, so you can go to http://localhost/popupmessage.php (or whatever language you want).  Then your popupmessage.script can talk to the serial port.  You might get all sorts of issues with cross-site scripting blocks and stuff, but I've never tried.  There are some PHP classes that can talk to serial ports, I think.  Perhaps google it.
Logged

Current Projects: Rodentometer - Hamster Endurance Moni

Belgium
Offline Offline
Newbie
*
Karma: 0
Posts: 5
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Thanks for the tip !
Googling for serial and php gave tons of pages, but finally found something that works smiley
I used serialcomm.zip from http://missionduke.com/arduino-projects/

Leds flickering with a status update on the LCD: check, next step: connecting it to my relay.
Logged

Chester, UK
Offline Offline
Sr. Member
****
Karma: 2
Posts: 489
Trying to return the love to none logic level MOSFETS
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

First thought - why handle the stop button on the PC side.  Having a physical button attached to the Arduino to handle this seems far simpler and also has the additional benefit of allowing for an amusing button:
Logged

If your system involves lethal voltages/life critical/flamable elements - you probably shouldn't need to ask.
The Arduino != PC.

Belgium
Offline Offline
Newbie
*
Karma: 0
Posts: 5
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

That's actually a nice idea smiley
And true, the coolness factor increases 10-fold.

I currently have the following code:
Code:
#include <LiquidCrystal.h>
LiquidCrystal lcd(7, 8, 9, 10, 11, 12);
int ledPin13 = 13;                 // LED connected to digital pin 13
int incomingByte;      // a variable to read incoming serial data into
char* LCDStrings[]={"Incoming chat","Click stop flash","Alarm stopped","Have a good chat"};

void setup() {
  lcd.begin(16, 2);
  lcd.clear();
  pinMode(ledPin13, OUTPUT);      // sets the digital pin as output
  Serial.begin(9600); // initialize serial communication
}

void loop() {
 if (Serial.available() > 0) {
  incomingByte = Serial.read(); // read the oldest byte in the serial buffer

  while (incomingByte == 48) {
    PrintLCD(0);
    digitalWrite(ledPin13, HIGH);   // sets the LED on
    delay(250);
    digitalWrite(ledPin13, LOW);   // sets the LED on
    if (Serial.available() > 0) {
      incomingByte = Serial.read(); // read the oldest byte in the serial buffer
    }
    delay(250);
  }
  if (incomingByte == 177) {
    digitalWrite(ledPin13, LOW);    // sets the LED off
    PrintLCD(2);
    delay(3000);
    lcd.clear();
  }
 }
}

int PrintLCD(byte messageid) {
  lcd.clear();
  lcd.setCursor(0, 0);
  lcd.print(LCDStrings[messageid]);
  lcd.setCursor(0, 1);
  lcd.print(LCDStrings[messageid+1]); 
}

Is this ok ? Are there optimalizations possible ?
Logged

Pages: [1]   Go Up
Jump to: