Tuesday, August 23, 2011

Task 8 - "Hello World" program


/*
 * Project:     HelloWorld_621Task08
 * Author:     Jane-Maree Howard
 * Date:            Tuesday 30/08/2011
 * Platform:     Arduino 22
 * Purpose:      To demonstrate a simple function call via the Serial Monitor (SM)            
 * Operation:  Description: uses a function in the main loop
                                to output text 10 times to the SM                
                               Declare: function called Hello()
                                Setup(): SM @ 9600 baud            
                                Loop(): call function Hello() 10 times, & print a blank line.
 */
void setup()  
{               
  Serial.begin(9600);  // Serial Monitor @ 9600 baud
}//end setup()

void loop()                    
{
  for (int j=0; j<10; j++)
  {
    Hello();
  }//for j
  Serial.println();
}//end loop()

// 'Hello()' print routine
void Hello()
{
  Serial.println("Hello, world.");
}//Hello()
//END


Task7 -2 Arduinos connected Tx -++ Rx pins

Wednesday, August 10, 2011

TASKS 7-14 -- Automation&Robotics: schedule 2


Tasks

Please respond to these tasks in your blog using the same reference numbers.

  • 7.  Connect up your RS232 Tx to the Rx of another Arduino.
         Output an "A" every second so that the input screen of the other Arduino writes this when it checks and prints the input serial screen.
    Take a photo of your set-up and publish it in your blog along with the code for Rx and Tx Arduinos.
    Reverse your roles with your colleague's Arduino. That is, swap the Rx/Tx duties.
    ~
  • 8.  Write a function called Hello()
          to output "Hello, world." when it's invoked.
    Call this function 10 times in your main loop().
    ~
  • 9.  Write a function DoubleInt to double an integer.
         Call it like this: Serial.println(DoubleInt(myInt)).
    Call it twice; once with a number and once with a variable.
    ~
  • 10.  Write a function to add B0111 to a byte passed to it.
           Call it 256 times in loop() using 0-255 as the parameters.
    ~
  • 11.  Write a function to AND a byte with B01
            and output the result to the screen.
    Test this in the main loop().
    ~
  • 12.  Write a function to say "yes" if the LSB (least significant bit)
           is a 1 or "no" otherwise.
    Test in the main loop.
    ~
  • 13.  Write a function to left shift a byte in the parameter position
           two places to the left then output the original and the final byte.
    ~
  • 14.  Write a program to output the bits, one by one,
           to the serial monitor screen from an arbitrary byte.

Task 6 - Key-Press program: other serial monitor output

/*
 * Project:    keyPressBrayOutput_621task06
 * Author:     Jane-Maree Howard
 * Date:       Wednesday 21/09/2011
 * Platform:   Arduino 22
 * Purpose:    To input a key-press from computer & output it to a Bray++ serial monitor
 * Operation:  Description:
 *             Declare: iKeyPress (int)
 *             Setup(): Bray++ serial monitor (BSM);  headings
 *             Arduino Library: LIB04_KeypressInput()            
 *             Loop(): reads input; prints character & ASCII codes                                             
 */


The program is exactly the same as in 621task06, except that the Bray++ Terminal monitor is used instead.

The COM port is selected on the PC running the Arduino to be the same as that selected on the opened Bray Terminal.

The line
   Serial.begin(9600); 
                                       is still needed to allow the connection to be made but the Arduino Serial Monitor is NOT opened.


 This is the Bray Terminal monitor.
Unfortunately, it presented me with only 2 COM ports, COM1 & COM3 - neither would work on the Arduino, which would upload only on COM4.

So this'll have to wait until i get home (where i hope i can make it work).

Task5 - Key Press program: Serial Monitor output - software

/*
 * Project:    keyPressOutput_621task05
 * Author:     Jane-Maree Howard
 * Date:       Wednesday 10/08/2011
 * Platform:   Arduino 22
 * Purpose:    To take a key press
 -                    and output the key and its codes
 -                    in binary, decimal & in hex.
 * Operation:  Description:
 -              Declare:   iKeyPress (int)
 -              Setup():   Serial Port (SP); headings            
 -              Loop():    reads input; prints character & ASCII codes              
 */

int     iKeyPress = 0;      // for incoming serial data

void setup()  
{
  Serial.begin(9600);     // SP @ 9600baud

  // print headings
  Serial.print("KEY-PRESS\t");   
  Serial.print("BIN\t");
  Serial.print("DEC\t"); 
  Serial.println("HEX");    
}//end setup()

void loop()                    
{
  // send data only when you receive data
  if (Serial.available() > 0)
  {
    // read incoming key-press
    iKeyPress = Serial.read();
    // output key-press & its codes
    Serial.print(iKeyPress, BYTE);   // print as ASCII character
    Serial.print("\t\t");                       // print tab   
   
    Serial.print(iKeyPress, BIN);    // print as ASCII-encoded binary
    Serial.print("\t");                        // print tab
   
    Serial.print(iKeyPress, DEC);    // print as ASCII-encoded decimal
    Serial.print("\t");                        // print tab

    Serial.println(iKeyPress, HEX);  // print as ASCII-encoded hexadecimal
  }//if()
 
}//end loop()
//END


This is the Serial Monitor
output - you can see the keys
that have already been outputted,
& the word "Yay!" which was about
to be entered by clicking the
'Send' button on the top right.

Task 4 - ASCII program: baud rate wind-up


This is the Arduino serial monitor running @ 14400 baud.
The program does the same.  It is producing gibberish; it won't even acknowledge line-endings, which i have seen in other experiments i've done like this..


Tuesday, August 9, 2011

Task 3 - ASCII program







On the right is a screen shot of my ASCII
program's output to the Arduino 
serial monitor.

What's not visible is the baud rate @ 9600.