Working on the PHP Backend of the Arduino + LCD Project

I haven’t posted for a while, but that doesn’t mean I haven’t been working on the ongoing Arduino + LCD project, which is moving along towards connecting external data to be displayed on the LCD screen.

The last bit of time I’ve put into the project has been focused on printing text to the LCD screen from a text file. It’s an easy enough process using a PHP serial class that I mentioned in the last post, combined with PHP’s basic file manipulation functions.

Getting started again, loading the test PHP script to print out a message from the serial port.

Plugging in the Arduino, waiting for it to respond to a message over its serial port.

Remembering that, for a reason I’ve yet to fully understand, I need the Arduino IDE open with the serial monitor window open to get serial communications happening between Arduino and PHP.

But to kill the PHP script hanging while trying to talk over the serial port, I have to unplug the Arduino.

You can see that in Arduino, the Serial port isn’t being found if PHP tries to use it first. I’m still having issues with the Arduino+LCD wanting to listen over the serial port without the Arduino IDE and Serial Monitor open. How is this usually automated in an¬†installation? Or am I having some kind of specific difficulties??

Plugging Arduino back in.

All is clear on the LCD.

Sending a simple test over the Arduino serial monitor, it’s all working.

I ran the PHP file with a message in the script itself and it still worked — I’m always paranoid I’m going to forget some important part of this between the times that I’m working on it.

The print out from my PHP script in the browser.

Here’s the file from which I needed to copy the fopen command that I had worked on previously, again pulling from a tutorial somewhere online to get going.

Here’s the basics of the PHP code to open a file and read it line by line.

Here’s the test text file.

And then, integrating the file open functions from the other file into the larger PHP script.

It worked, well, one line anyways.

There were some issues with my code transfer.

A few changes, and it was working, appearing OK in the browser…

…but not so well ¬†on the LCD screen itself. Those strange characters were due to the newlines or carriage returns in the text file.

I tried some more basic troubleshooting text so I could better keep track of the lines.

Again, I wasn’t exactly sure how to correct the problem, but I knew it was connected to the newlines in the text file.

Some code changes to pull out the newline characters, now leaving spaces, but not maintaining the newlines, which is fine for this purpose.

And, the corresponding PHP output.

And on the LCD! It worked!!!!!

On another note, I was wondering if I needed to just use some kind of simple regex tool to pull out the title from a Twitter RSS feed. For the purposes of this project, I’m not really concerned about a whole lot of the information, and really, I’d just like to have the text from each tweet to be found in a text file. I could set up a database and all the rest, but it feels a bit like overkill. As well, since I’m generally feeling behind schedule, I don’t want to cloud this with certain details that are likely unnecessary.

Next steps are going to be parsing some RSS and displaying it on the LCD, and integrating a second Arduino and LCD through a wireless connection.

Annotated Bibliography (tutorial on writing files in PHP) (parsing RSS with PHP magpie library) (truncating a string, adding … )

I would like to thank the Canada Council for the Arts for their generous support.

9 Replies to “Working on the PHP Backend of the Arduino + LCD Project”

  1. Excellent – I want to do something similar to this, which is post a latest tweet to my arduino’s LCD. I’m not far off, but all the code snippets are in python, which I don’t know – I do know php to an extent – can you possibly post your code?

    1. Emma, I’ll definitely post the code soon … it would probably be most useful once I get the Magpie RSS parser integrated. Probably the next post I make, I’ll make sure to include the PHP code thus far.

    1. Sure! I think I want to keep going with PHP, just because I’m much more familiar with the language, but if you have something working, it’d be interesting to see if I’m missing anything obvious.


  2. hi there!
    OMG nice project u did!
    but im so curious, how do you pull the data from online database to the arduino? how u send the data from DB to the arduino? i meant, i dont get how u made the php directly to the arduino.


    1. Amy, right now, I’ve just been pulling in data from a text file, though to do the same from a database would use PHP code to request text from a MySQL database and then sending that through the serial port.

      As for the Twitter feed, I’m using the MagpieRSS library, which I’ll write about more in the next post.

  3. hi thanks for the reply.
    may i know how the php pull the message from the text file?
    i dont understand the php coding at line u said specify the device? how u specify it?

    and can u show me the php code that u used?

    thanks in advance for your time :)

    1. Check out the PHP Serial class page for more information on how to specify the device, etc. There’s also a number of tutorials on how to set it up, but basically those lines in code just open the connection to the serial device, which in this case, is this Arduino.

      I’ll be posting all the code at the end of the project, but for the time being, it’s a total mess, so I’d rather wait until I can clean it up so it’ll be more useful.

Comments are closed.