Difference between revisions of "CSC231 Lab 6"

From dftwiki3
Jump to: navigation, search
(CSC 231 Lab # 6)
Line 12: Line 12:
 
==Getting the Messenger Library for the Arduino==
 
==Getting the Messenger Library for the Arduino==
  
You need a new library for the Arduino called '''Messenger'''
+
You need a new library for the Arduino called '''[http://www.arduino.cc/playground/Code/Messenger Messenger]'''  
  
 
* Boot the Ubuntu CD-Rom
 
* Boot the Ubuntu CD-Rom
Line 26: Line 26:
 
* Copy the file in the Arduino hardware/libraries directory.
 
* Copy the file in the Arduino hardware/libraries directory.
  
 +
  cp Messenger arduino-0010/hardware/libraries
 +
 +
* Set the ownership of the new library the same ownership as that of the arduino software
 +
 +
  chown -R 1000:1000 arduino-0010/hardware/libraries/Messenger
 +
 +
* Create this new sketch
 +
<code><pre>
 +
// This example sets all the values of the digital pins with a list through a callback function
 +
 +
#include <Messenger.h>
 +
// Instantiate Messenger object with the default separator (the space character)
 +
Messenger message = Messenger();
 +
 +
// Create the callback function
 +
void messageReady() {
 +
    int pin = 0;
 +
      // Loop through all the available elements of the message
 +
      while ( message.available() ) {
 +
// Set the pin as determined by the message
 +
        digitalWrite( pin, message.readInt() );
 +
        pin=pin+1;
 +
      }
 +
}
 +
 +
 +
void setup() {
 +
  // Initiate Serial Communication
 +
  Serial.begin(115200);
 +
  // Attach the callback function to the Messenger
 +
  message.attach(messageReady);
 +
}
 +
 +
 +
void loop() {
 +
  // The following line is the most effective way of using Serial and Messenger's callback
 +
  while ( Serial.available() )  message.process(Serial.read () );
 +
}
 +
 +
</pre></code>
 
==Assembly Part==
 
==Assembly Part==
  

Revision as of 15:47, 29 October 2008

Back to CSC231 Weekly Schedule


CSC 231 Lab # 6

ArduinoStamp.jpg

© D. Thiebaut, 2008

In this lab we are going to make the Arduino keep on listening to commands it gets from the assembly language on the PC, and execute each command as it receives them.

Getting the Messenger Library for the Arduino

You need a new library for the Arduino called Messenger

  • Boot the Ubuntu CD-Rom
  • Open a Terminal window and type
  sudo su
  cd 
  wget http://www.arduino.cc/playground/uploads/Code/Messenger.zip
  • unzip the file
  unzip Messenger.zip
  • Copy the file in the Arduino hardware/libraries directory.
  cp Messenger arduino-0010/hardware/libraries
  • Set the ownership of the new library the same ownership as that of the arduino software
  chown -R 1000:1000 arduino-0010/hardware/libraries/Messenger
  • Create this new sketch
// This example sets all the values of the digital pins with a list through a callback function 

#include <Messenger.h>
// Instantiate Messenger object with the default separator (the space character)
Messenger message = Messenger(); 

// Create the callback function
void messageReady() {
    int pin = 0;
       // Loop through all the available elements of the message
       while ( message.available() ) {
	// Set the pin as determined by the message
         digitalWrite( pin, message.readInt() );
         pin=pin+1;
      }
}


void setup() {
  // Initiate Serial Communication
  Serial.begin(115200); 
  // Attach the callback function to the Messenger
  message.attach(messageReady);
}


void loop() {
  // The following line is the most effective way of using Serial and Messenger's callback
  while ( Serial.available() )  message.process(Serial.read () );
}

Assembly Part

  • Open a Terminal window under Ubuntu and type
  sudo su
  cd
  • Highlight the contents of the file driver.c and type Control-C to copy it to the clipboard
  • In the terminal window type
  cat > driver.c
and then click the middle button of your mouse to paste the code you had highlighted