IAN LANG ELECTRONICS

William Joseph Wilberforce

           1759-1833

So far we've let our Arduino do various jobs that  interact with the user through a range of inputs and outputs including the PC. However physical computing can do far more than that, and in this chapter, which is going to be very long,so strap yourself in with plenty of tea, we are going to let Arduino boards interact with each other. Spiffy. So, let's start the legwork by a nice easy communication between two boards using the message board we made in the last chapter.. We'll need to add another Arduino board (I've used another UNO) .

 

Let's talk about revisions of the UNO board before we do this. My older one is a revision 2, or R2. My newer one is a revision 3 or R3. In practical terms, it doesn't matter. But in terms of software, it does. You can't run the R3 with an R2 driver on your PC. You need to download and install the R3 driver. This means that the R2 and R3 will occupy different virtual comports and when uploading the sketches you'll need to make sure you've got the right one selected in your IDE. This doesn't qualify as an embuggerance, but it is a gremlin to look out for if you don't want to spend twenty minutes swearing at your R3 when first you use it and then feel a bit stupid for an hour afterwards when you finally realise the above. And since you ask, yes I did thank you.

 

So, having plumbed the depths of dimwittedness on my part, let us now return unto the subject at hand. We're going to do this in nice easy steps and so first of all we're going to make one Arduino read a message typed in to the computer and then relay it by wire to the second which will display it on an LCD. That second is just the same thing we did in the last chapter and the whole thing looks like this:

Board to Board Communications

Go Back

For the sake of clarity I'm calling the board attached to the PC via USB ARD0  (ARDuino 0) and the board that's not  ARD1. So,  ARD0 is the USB board, ARD1 is the board connected to the independent power supply.

 

If you point the boards so that the USB connector is pointing in the direction directly opposite you as above, then look in the bottom right hand corner of each board, you'll find two pins labelled TX and RX. TX is transmit, and RX is receive, and what they do is pass (transmit) and accept(receive) serial data. It's this that we are going to exploit here.

 

The two white wires in the diagram above are the ones needed to transmit and receive data. You'll see that one end of the first white wire is attached to TX of ARD0 and RX of ARD1. It's in fact a crossover. This means that although ARD0 can talk to ARD1, ARD1 can't make a reply to ARD0. For that we'd need another wire going from TX ARD1 to RX ARD0. We'll get to that later. For now let's keep it one-way.

You might be asking why is that second white wire going to ground? Because if you are sending a cable transmission like this, you have to have a ground connector between the receiver and the original source. It won't get there if you don't.

 

Once you've wired up you'll need to upload a sketch to both boards. Here's ARD0's:

 

void setup(){

  Serial.begin(9600);

}

 

void loop(){

  if (Serial.available()) {

    delay(100);

     while (Serial.available() > 0) {

     Serial.write(Serial.read());

 }}}

 

If you upload this code with the device on (providing you've uploaded ARD1's sketch) you'll see the LCD display on ARD1 put out what looks like utter gibberish. It is in fact ARD0 communicating with the PC from which you're uploading code and transmitting to the LCD at the same time. Let's canter through:

 

 

void setup(){

  Serial.begin(9600);

}

 

We aren't going to be using any libraries or global variables here so it's straight to the setup where all we do is set the Baud rate. Then we go crashing into the loop

 

 

void loop(){

  if (Serial.available()) {

 

That conditional states that ARD0 only has to do anything if something's coming through the serial port. If there is, the code under the conditional gets executed:

 

   delay(100);

 

wait or a bit to make sure it's all there then:

 

     while (Serial.available() > 0) {

     Serial.write(Serial.read());

 

Whilst there's something in the buffer to read, read it character by character and chuck it back out through serial again.

 

Now, the code for ARD1 is exactly the same as it was for the message board in the last chapter or the simple reason that that's all it is. Here it is again:

 

 

#include <LiquidCrystal.h>

  boolean resetdigit=true;

LiquidCrystal lcd(12, 11, 5, 4, 3, 2);

 

void setup(){

    // set up the LCD's number of columns and rows:

  lcd.begin(16, 1);

  // initialize the serial communications:

  Serial.begin(9600);

  reset();

 

}

 

void loop(){

if (digitalRead(7)==1){reset();}

  if (Serial.available()) {

    tone(6,242);delay(1000);noTone(6);

    lcd.clear();

    delay(100);

     while (Serial.available() > 0) {

     lcd.write(Serial.read());

    }

   resetdigit=false;delay(2000);}

if (resetdigit==false){

   delay (500);

lcd.scrollDisplayLeft();}

 

}

 

void reset(){

  resetdigit=true;

  lcd.clear();

  lcd.print(" Ian Lang Etncs ");}

 

Right then, time to test it out. You'll remember that in the last chapter we built a small interface in Visual Basic. I've got a confession. That interface isn't really necessary. You could just type into the send box in the serial monitor of your IDE. It's not as functional though, and certainly not as stylish. Well, however you want to send, try this:

 

Hey hey, the white swan; by God I am thy man.

 

And if you find that sentence easily anywhere else I'll be a Russian Ballerina and so it makes a good testpiece. Once you've sent it, the LCD on ARD1 will display it.

 

If you sent that by the serial monitor, you'll find as well as being displayed by the LCD it'll appear in the serial monitor window too. That's because it's being sent both to ARD1 via serial TX and the PC via USB at the same time.

 

Type in the strangest message you can think of. Mine is "Stop that rhododendron he's interfering with my intangible benefits!". As long as it's shorter than eighty characters, the LCD on ARD1 will display it happily.

 

A one-way transmission like this is known as simplex and it's how a master control unit influences the behaviour of a slave one. Like Wilberforce (see left)  I don't hold much with slavery and so let's introduce a measure of equality to the two and give ARD1 a voice in the matter. Over the page, let's make a remote temperature device.

 

Wilberforce served as a Member of Parliament from

1784 to 1825 and was the chief voice for the abolition of the slave trade.

From 1787 until 1807, he battered on, in the teeth of fierce opposition, until the Slave Trade Act banning the transportation of slaves in British ships was passed. He was inluential in attracting  luminaries like Josiah Wedgewood to the cause, who made pots with cameos depicting African negroes in chains with the words "Am I not a man and a brother?" embossed upon them.

 

War with France meant that Britain did not become the first nation to abolish the trade. That was Denmark. But the tonnage of the British fleet was far,far more than the Danish and thus the biggest practitioners of the trade denied it overnight and moreover actively enforced it; denying a very lucrative market. It was as if the government of today banned all financial services.

 

The trade of slavery was abolished, but existing slaves within the British Empire were not freed until 1833, just before Wilberforce's death. It would be more than thirty years and a brutal war before the Americans followed suit.  In some parts of the World slavery is still accepted. Wilberforce and the rest of the abolitionists achieved what for the time was an Earth-shattering achievement.

 

Of course this has nothing to do with electronics. I doubt that Wilberforce would have known what to do with a Faraday Ring. Interesting though, just the same.

 

More>

In fact you could if you wanted use the 5V pin from ARD0 to power ARD1 and that negates the need for an independent supply. You'll still need a ground-ground wire though.

When running like this, ARD0 is said to be a master and ARD1 a slave. Another way of looking at it is ARD0 is a relay and ARD1 a receiver.

ARD0

ARD1