More Arduino + LCD + PHP fun

My work on this ongoing LCD Arduino project has been continuing over the last couple of weeks, I just haven’t had the time to update appropriately.

So, I switched over my plan of attack from Processing to PHP. I figured this made sense for a couple reasons: first, I’m already very well-acquainted with PHP, I’ve written and hacked together a good amount of code in this language before and so I feel like I’ll spend a lot less time just figuring this out and more time actually doing; second, I don’t think I was really going to use Processing for its strengths, and instead, I was going to rely on its string functions, which pale in comparison to PHP.

I’ve made quite a lot of progress over the last week or so — all of which is detailed below. There are still some major problems I need to sort out, but for the most part things are about where I’d hoped them to be at this point.

First off, I had to spend some time getting the server up and PHP and running on my MacBook Pro again. I had set this up a while back, probably before I upgraded to Leopard (and having since upgraded to Snow Leopard), some things needed some manual attention. I wish I had saved the links, but the gist of it was that I needed to change the user.conf file.

I also started working with the PHP Serial class, which is awesome, there are a few versions out there, but the one I’m using came from Rizwan Kassim who made changes to the oft-circulated Rémy Sanchez version.

So, I tweaked the example script to spit out the text that would appear on my LCD screen in my browser window.

Here’s the script.

And the result.

Then I moved onto a looped script.

This worked fairly well.

The script … wrapping the $serial -> sendMessage($i) in a while statement.

My diagram for what exactly I want this to do…

The counting numbers script was a bit wonky for reasons I’m not entirely clear about. Basically it would count up to a certain number, but then clear the screen and print the rest of the numbers. That is, if I wanted it to write up to 11, it would split the number sequence somewhere near 6 or 7, and then show the rest on a freshly cleared screen. I’m not sure why this was happening, but I wondered if the script was just moving too slowly (or too quickly) for the Arduino to catch it all at once.

Then I spent a long time trying to figure out how to break up the text correctly. The thing is, I had hoped for this project to be able to take a text string and display it all at once on the LCD screen. However, the LCD screen and Arduino don’t know how to automatically display this as I might wish. There are some inherent difficulties in this — while PHP can find me letters or entire words and break them up accordingly, I’m not sure how to signal Arduino to tell the LCD to start a new line. You can see above, I had momentarily programmed the PHP script to display correctly in the browser, but it made me think that if I could just find the right catch character, I could get this to work as I imagined.

The other thing that you’ll notice is that the Arduino sketch as I had written it at the moment, wasn’t right in its placement of characters on the LCD.

As I understand it, these LCDs are meant to write to the 1st line, then the 3rd, then the 2nd, then the 4th.

In this case, I had the Arduino sketch printing out one letter at a time — and I realized I actually liked this effect (simple I know), but I think it helps to communicate some level of this thing actually receiving new data.

One of the many Arduino sketches I was trying to piece together from other tutorials, etc. At some point I think I was trying to use command characters that I saw on Serial LCD tutorials — my LCD is parallel, so I have to imagine this is a big reason why it wasn’t working.

So, back to the drawing board…

This time, I got it to work…

See the comma — it went to the 2nd line, like it was supposed to!

The string carried on, though it’s awkward with not being able to determine in PHP where the string should break for a new line and have that information sent on to Arduino.

Here’s a screenshot of the Arduino code I’d settled on. Those letter variables are a counter for each line, allowing me to have Arduino automatically wrap the entire string when it’s reached the end of each line properly so that the string continues onto the next line, rather than the 1-3, 2-4 thing I described above.

So the string continues.

And here’s the string completed. Really awkward line breaks in the string, as Arduino will print until its reached 20 characters on each line. You can see why I need to figure out how to translated information from something like wordwrap() in PHP to Arduino.

And again, here’s the code that finally made this work, all those counters…

The other part of this project that I started to work towards is the process through which I will receive text messages and put them into the system. Sending text messages from computers is easy, but receiving text messages in an email or something like that is much more difficult. However, I found

Problems that remain at the moment:

I’m still not sure why I need the Arduino Serial Monitor open for this to work. Unless it’s open, the PHP script won’t work and because it doesn’t work, it gets stuck with the Serial port open, it crashes the Arduino IDE and the LCD itself obviously has no output.

I still need to figure out how to signal a line break earlier than 20 characters when appropriate. I can get this information about a string and split it up in PHP, but I’m not sure how to pass that along to Arduino. I’m guessing using something like a case break type of loop would do it. iPiPi seems to provide the technology that I need, which is essentially a number that can receive text messages and automatically route them to an email. The service that I need is going to be fairly costly, given that I’d want a dedicated number or long code, but would be worth it to see this project work as I imagined it … that part of the project is a little while off anyways. But, I’m just happy that I found what I was looking for.

Annotated bibliography for the last couple of weeks:

http://dorkbotpdx.org/blog/kmat/serial_lcd (serial –> LCD … this is making more sense now, using case breaks to look for specific characters to insert a function, such as starting a new line)

http://blog.datasingularity.com/?p=50 (control arduino through html)

http://stackoverflow.com/questions/899098/arduino-serial-reading (arduino serial reading)

http://www.ipipi.com/ContactUs.do (potential sms forwarding to email option)

http://www.ipipi.com/help/ipipi_in_out.htm (this is what I would need to receive messages, not as simple as a number, but maybe the best way to avoid having to get another phone number, I should also ask about a potential shortcode)

http://docs.upsidewireless.com/index.php?title=MO_HTTP (notes on how to bring sms messages into an application using HTTP POST)

http://www.upsidewireless.com/how_virtual_sms_works.htm (this is the kind of service I’ll need for this project … SMS messages forwarded to email or accessible through HTTP requests … with the possibility of getting a Windsor-based number AKA longcode)

http://www.mydarkmaterials.co.uk/2008/11/interfacing-php-with-the-arduino/ (this is an example of interfacing PHP Serial with Arduino, and I suspect old enough that many of the problems the author ran into aren’t there any longer … maybe it’s been silly of me to ignore PHP … I actually have a decent idea of what I’m doing there)

http://www.procata.com/blog/archives/2007/10/28/working-with-php-5-in-mac-os-x-105/ (helpful to get PHP running properly on 10.6)

http://opensourceprojects-torchris.blogspot.com/2009/09/arduino-pop3-email-checker.html (maybe or maybe not useful in some capacity, using arduino to check email)

http://www.arduino.cc/playground/Learning/SparkFunSerLCD (serial commands)

http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?action=print;num=1192470251 (word wrapping in Arduino)

http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1252901403/4 (word wrapping more)

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

Tagged:

Related Posts: Arduino + LCD + PHP, Part 2 New LCDs and Serial Ports and some Max/MSP for good measure Getting Things to Talk: Arduino + LCDs

Previous: « Next: »


Leave a Reply






Location

Windsor from Google Maps' perspective

Windsor, Ontario (South of Detroit)

Save the City !!!

Broken City Lab: Save the City
5 months of community events to imagine how to save this city.

Participate! March 20th, 3PM

Mailing List


 

Activity

Follow us on Twitter

Conversations

  • Michelle: SO FUNNY!
  • darren: I’m sure sparkfun has some too, maybe different.
  • Justin: ahhh nice. thanks for the link!
  • darren: adafruit has been selling those for quite a while http://www.adafruit.com/index. php?main_page=product_info&...
  • Justin: Yes, Mark, thanks for the pics and the suggestions for the list, that area around the Casino fell into the sites of apology side...
  • tinyenormous: Hi justin! For the 2 line contrast thing I have run into similar issues before. I recommend using a pot to control the...
  • Mark Boscariol: p.s. pelissier bldg isn’t mine, but I know the guy who bought it
  • Mark Boscariol: Cool, couldn’t make it but I hope you got the pics I dropped off. 3 houses across from casino parking garage...

Archives

Tags

3D 100 ways abandoned activism advertisements air airport algorithm Ambassador Bridge analog annotate architecture arduino art artist Artspace astroturf automobile awesome balloons banner baskets battery BCL Bench bicycle bike bikes billboard bio biodegradable Blog book books border brainstorm bridge buildings bus Canada car cellphone chalk Chattanooga Chicago cities city citynoise code collaborative collective community computer computers conference Conflux consultancy context costume create here crisis cross-border communication crowd-sourcing data database demo design Detroit development DIY documentary documentation downtown drawing driving ecohouse economy EC Row editing electricity electronics energy environment eric boucher event exhibition exploring extended field trip eye fake fashion fence field test fieldtrip fire firefox flagging tape fuel efficiency gallery game garbage garden gardening geography google google earth google maps graffiti grants grass green Green Corridor guerilla hack hacking Halloween hardware history house housing how to HQ ice ideas image inflatable infrastructure install installation inter-city interactive internet intervention interventions interview ironing knitting LCD Lebel LED light lights list lists magnetic magnets make making mapping maps materials math message michelles Michigan micro-residency mind map monitoring moss movie music naturalized area nature neighbourhood news newspaper newspapers New York new york city night noiseborder office hours open source opportunity paint painting paper parade paranoia park parking ticket parks participation party pedagogy performance perspective Peterborough photography PHP physics pixel planning plans plant planters plants plastic bags politics pollution presentation printers project projection projector projects psychogeography public public art public domain public realm public space public transit pulp radio Rain reading reblog recycle remote research residency resistors restaurant reuse ribbons river roof rope safety Sandwich Sao Paulo Save the City school science screening sculpture sculptures seed bombs seeds sign signage snow social practice software soil soldering sound Soundart space spray paint stencil stencils stickers story strategic plan street street art street art strike submissions suburb surveillance sustainability sustainable tags talk tea technology test tetris text Text In-Transit time-lapse tools Toronto transit transmit transplant travel tree trees tshirts tunnel tv university urban venues video visualization walk wall water Waterloo website wheat paste wildflowers Windsor youth youtube

Our Recent Research

Research Description

Broken City Lab is an interdisciplinary creative research group that tactically disrupts and engages the city, its communities, and its infrastructures to reimagine the potential for action in a collapsing post-industrial city.

Call for Submissions

Broken City Lab: Storefront Residencies for Social Innovation
The Storefront Residencies for Social Innovation invites the radical re-imagining of the possibilities in occupying a vacant storefront in the heart of Windsor for one month. Apply now!

Subscribe

Broken City Lab RSS icon Blog RSS

Broken City Lab RSS icon Comments RSS

Events

Sing to the Streets March 20, 2010, 3pm

City Share Conference in Chattanooga Feb 17 - 20, 2010

Sites of Apology / Sites of Hope Sunday, Feb 28, 2010, 1pm

Public Realm at Propeller Centre for the Visual Arts Jan 20 - 31, 2010

Save the City: Listen to the City Sunday, Jan 24, 2010, 8pm

» More Events...

Cross-Border Communication

Cross-Border Communication: We're In This Together
Cross-Border Communication is an interventionist performance series based on the desperate need to communicate with Detroit from Windsor.

Most Read Posts

Contact

info@brokencitylab.org

Bookmarks

What We're Reading

Links

Meta