IAN LANG ELECTRONICS

Using an LCD display, we can make a message board that displays a message of up to eighty characters we type in to an interface we've built in Visual Basic. Moreover we can add a loudspeaker and a button to dismiss the message once we've read it, and then what we've got is the beginnings of an alphanumeric pager. Below is a short video showing the one I've just made:

 

A Simple PC to Arduino Message Board

Go Back

From that video you may have noticed that I've built an LCD display into a shield, and I recommend you do the same. The principal reason for me doing so is that I got fed up having to wire in an LCD every time I wanted to do an experiment with one, but an added benefit is that it reduces the mess of wires on the breadboard dramatically. You may also have noticed that a. I have a very large tea mug with Wallace and Grommit on it that sneaked into the film and b. I forgot to turn the radio off before I started recording.

I like tea. I like Wallace and Grommit too. The music was from Smetna's "Bartered Bride" and it was on Classic FM. That's bartered, by the way, don't get it confused like a work colleague of mine and say "What? Somebody's written an opera really called the Battered Bride? That's a bit sick."

 

And so on to the wiring for the thing. First of all, here's a complicated Fritzing diagram:

 

This isn't quite as bad as it looks because most of that wiring is in fact to do with the LCD and if you make yourself a shield to the Oomlout schematics on the right, you'll find the job goes much easier. Use some budget prototypes from Oomlout and run the wires underneath and Bob's your uncle. The speaker is attached to pin 6 via a resistor of 100 ohms to improve the impedance, and the button is set to keep pin 7 reliably low until the button's pressed. This is the button that's going to dismiss the incoming message once we've read it. This is how you set up two and four terminals:

5V

GND

5V

Arduino Pin 7

GND

Arduino Pin 7

In point of fact the value of that pull-down resistor isn't too critical as long as you don't go mad and go too high or low in value. I've found that a 560 ohm will do the job well, but I've used a 2.2k before now as well.

 

So, now we've got the physical hardware sorted out it's time to look at the software. Let's begin with the Visual Basic interface. You saw in the video what it looks like, and after filming I decided to add a clear button to it to clear all the text in the text box at one go. It now looks like:

The button on the left sends the message typed in to the textbox when clicked, and the button on the right clears down the text box when clicked. If  you've read earlier chapters or you know a bit about VB already, you'll know that in VB all objects have names, and the button marked send is called Buttonsend, the button marked Clear is called ButtonClear and the textbox is called inbox.

There's another component and again if you've read the previous chapters in which I've banged on about VB you'll know that it can only be a serial port. I've called it comport.

 

In the properties window you need to set inbox to allow a maximum input of only eighty characters. Why? Because the LCD display can handle eighty characters in one go (and more on that later). The serial port needs to be set to a Baud rate of 9600 and the portname to wherever your Arduino is. It's the same one that you upload sketches to, and in my case it's com8, and so that is where it gets set. Make sure DTREnable is set to false if it isn't already, and you shouldn't need to do anything else. Only the buttons need coding, and it's as follows:

 

    Private Sub ButtonSend_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ButtonSend.Click

        Dim outstring

        On Error Resume Next

        comport.Open()

        outstring = inbox.Text

        comport.Write(outstring)

        comport.Close()

    End Sub

 

    Private Sub ButtonClear_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ButtonClear.Click

        inbox.Text = ""

    End Sub

 

In each case the top and bottom lines will already be there, and so you just need to put in Buttonsend the following:

 

  Dim outstring

        On Error Resume Next

        comport.Open()

        outstring = inbox.Text

        comport.Write(outstring)

        comport.Close()

 

Dim outstring declares and resets a variable, On Error etc stops the program from crashing if there's a problem with the serial port. We open the port, assign the text contents of the textbox to the variable outstring and send it down the port to the Arduino, then close the port again. Clearing the textbox does not even involve the Arduino and is simply:

 

        inbox.Text = ""

 

Which returns an empty string to the textbox and thus clears it.

 

At the other end we need to code up for a receiver. Over the page, we look at how this is done on the Arduino and find out why we can only have eighty characters.

More>