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
I would like to thank the Canada Council for the Arts for their generous support.


![Eric Boucher Micro-Residency Iteration 6/6 This past Saturday I did my portion of the BCL collab/micro-residency with the lovely and talented wunderkind, Mr.Eric Boucher. For the collab I had Eric interview my sister’s good friend, Sam. Aside from her notable charm, I think Sam was a good candidate for the project because she is a student who came from Sarnia [...]](http://d1ugx41kvdwavn.cloudfront.net/wp-content/uploads/2009/12/eric_sam_dec1209-150x150.jpg)
![Save the City: Listen to the City The details: Sunday, January 24, 2010 (8pm) at Phog Lounge (157 University Ave W, Windsor) As part of the Broken City Lab: Save the City project, Broken City Lab researchers will facilitate a community workshop to brainstorm, uncover, and share personal histories of Windsor, inviting a range of community members to participate in the process. The workshop [...]](http://d1ugx41kvdwavn.cloudfront.net/wp-content/uploads/2010/01/BCL-STC-Jan-5x7-front-outlines-1024-150x150.jpg)

![BCL Report: March 25, 2011 (Imaginary Portals & Ongoing Construction) With almost a full crew we spent this Friday night testing finishes, planning ways to cross the border unnoticed, and building supports for the letter ‘R’, all while being filmed by a documentary crew from the Department of Communications, Media & Film. Above, some notes from Danielle’s sprawling research on inventions for tactically crossing a [...]](http://d1ugx41kvdwavn.cloudfront.net/wp-content/uploads/2011/03/IMG_91951-150x150.jpg)
![Tools in Forgetting the Border Part of our research for How to Forget the Border Completely is going to come from a lot of video. We’re not sure how many interviews we’ll do or exactly where we’ll be shooting, but we wanted to be prepared. I’ve had a Canon T2i for over a year now and it’s a very solid [...]](http://d1ugx41kvdwavn.cloudfront.net/wp-content/uploads/2011/01/IMG_8438-150x150.jpg)
![BCL Report – Nov 1, 2008 In preparation of our upcoming Tetris Tournament / Wheat Paste Demo / Sticker Making Party, we had made a list of supplies and had set out to find the goods at (what we thought) was an obvious choice—Value Village. At the top of our list was a hot plate, Tetris for SNES, and supplies for making [...]](http://d1ugx41kvdwavn.cloudfront.net/wp-content/uploads/2008/11/the-glory-that-is-value-village-150x150.jpg)
![ATTC Calgary Day 1: Shortcuts for Urban Resistance & Algorithmic Walks We’re in Calgary working with Truck Gallery’s CAMPER Urban Discovery project, doing a residency based on our “…and then the city…” (ATTC) research. Developed after a six-month community research project back in Windsor called, Save the City, ATTC was initially realized as two billboards in Windsor and an accompanying publication that looked at the cyclical [...]](http://d1ugx41kvdwavn.cloudfront.net/wp-content/uploads/2011/07/DSC26601-150x150.jpg)
![BCL Report: May 5, 2011 (Big Books & Small Letters) We met twice on Thursday, and those meetings were after Michelle and I headed over to SB Contemporary Art to finally check out “On Your Mark” (a great exhibition featuring work by many of our friends) and talk about how we could partner in some way on Homework: Infrastructures & Collaboration in Social Practices. Back [...]](http://d1ugx41kvdwavn.cloudfront.net/wp-content/uploads/2011/05/IMG_9710-150x150.jpg)
![What is Google trying to tell us? Danielle first wrote about the Gmail ad phenomenon a while ago — that is, how Google tries to place relevant ads by reading your emails and the curiosities that can arise from that technique. So, the screenshot above is what Google thinks about an email regarding Broken City Lab, Bruce Mau, a revisited idea, and [...]](http://d1ugx41kvdwavn.cloudfront.net/wp-content/uploads/2010/03/google-ad-150x150.jpg)
![Getting Reacquainted with the Neighbourhood I took a leisurely bike ride around the neighbourhood yesterday afternoon. It’s been a while since I’ve taken the time to explore, to spend time paying attention to things. I basically wanted an update on the neighbourhood that Danielle and I had lived in a couple years ago. The eastern edge of Sandwich is quieter than ever. [...]](http://d1ugx41kvdwavn.cloudfront.net/wp-content/uploads/2010/07/IMG_2416-150x150.jpg)
![BCL Report: April 11, 2011 (oh, the logistics) It was Monday night and Karlyn’s Birthday, so Hiba and Kevin brought a fun cake. Other things happened as well, and strangely, or maybe expectedly, now that the semester’s done and since we didn’t meet at the very end of the week, we had a marathon five hour meeting. It was so great!!! We had [...]](http://d1ugx41kvdwavn.cloudfront.net/wp-content/uploads/2011/04/IMG_9446-150x150.jpg)
![Help Wanted: Ad-hoc volunteer studio assistant We’re looking for an ad-hoc volunteer studio assistant to help us do some or all of the following: -Visual and archival research -Building and making things -Silk screening -Scanning and archiving -Basic print and/or web design -Materials research -General office assistance -Installation assistance In return for your one or two day a week time commitment, we [...]](http://d1ugx41kvdwavn.cloudfront.net/wp-content/uploads/2012/10/wpid20169-IMG_1486-150x150.jpg)
![How to Forget the Border Completely, submitted for print! Months of work and research culminated in a 3am submission to Blurb to print our How to Forget the Border Completely publication. It’s about 150 pages long. I’m really happy with this, and I can’t wait to get it back in print. Above, a screenshot of some of the pages in the PDF. In terms [...]](http://d1ugx41kvdwavn.cloudfront.net/wp-content/uploads/2011/10/Screen-Shot-2011-10-06-at-9.15.16-AM-150x150.png)
![BCL Report – Nov 4, 2008 In preparation of the upcoming event, and in response to our sudden acquisition of 4 t-shirts, we spent Tuesday evening making stencils, shirts, testing Tetris 2, wheatpasting, and figuring out the logistics of a video game tournament. First thing on the list of to-do’s was to test my custom wheatpaste applicator. The results were mixed, though I [...]](http://d1ugx41kvdwavn.cloudfront.net/wp-content/uploads/2008/11/engage-and-disrupt-the-city-the-front-of-our-t-shirts-150x150.jpg)
![Being Productive Again: Day 1 Now that Intersession is done, we’ve finally been able to put that downtown space to some use. Cristina and I spent the better part of the day in the space, using it basically as an office, but we’ll be there at least one more day this week and potentially one day on the weekend picking [...]](http://d1ugx41kvdwavn.cloudfront.net/wp-content/uploads/2009/06/IMG_0583-150x150.jpg)
![Our Ribbons Have Arrived For our upcoming Sites of Apology / Sites of Hope event (a part of our ongoing Save the City project), we’ll be asking for your participation to help us come up with a list of those very things — the places around Windsor for which we need to apologize, and the places for which we [...]](http://d1ugx41kvdwavn.cloudfront.net/wp-content/uploads/2010/02/IMG_7327-150x150.jpg)

![Researching Ribbons, Preparing for this Week’s Events Tuesday was all about research. We looked up some more details on ribbons and talked more about how we would move forward with the Sites of Apology / Sites of Hope event. We’re also getting ready for Sunday’s event, Listen to the City (remember, 8pm at Phog), and for Thursday night’s projection performance at Propeller in Toronto. We were [...]](http://d1ugx41kvdwavn.cloudfront.net/wp-content/uploads/2010/01/IMG_6776-150x150.jpg)
![Smorgasborder 02: Rewriting Windsor Last night’s Noiseborder event was a success. A number of people came down to Studio A in Lambton tower and helped us collaboratively rewrite Windsor’s history using maps, time lines, and story boards. All content was digitally remixed and projected on the screen with old photos and videos of Windsor. Justin started off the night by explaining [...]](http://d1ugx41kvdwavn.cloudfront.net/wp-content/uploads/2009/03/michellegc1-150x150.jpg)
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?
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.
I do have some working python code now if you want it
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.
Thanks!
Got it working – http://www.iknowthe.net/blog/arduino-twitter-lcd-doorsign.html
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.
:)
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.
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 :)
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.