Difference between revisions of "2012 SJ One Hello World Sample Project"

From Embedded Systems Learning Academy
Jump to: navigation, search
 
 
Line 18: Line 18:
 
# Compile & Load the program onto the Board
 
# Compile & Load the program onto the Board
 
# Open COM Port in Hercules and press RESET on the board to view your <code>printf</code> message.
 
# Open COM Port in Hercules and press RESET on the board to view your <code>printf</code> message.
 
== Board Sensors ==
 
After you get a basic "Hello World" program working, you can now output various different sensor values.
 
 
Here are the sensors or devices of SJOne Board you can access:
 
*  Acceleration Sensor ('''AS''')
 
*  Temperature Sensor ('''TS''')
 
*  Light Sensor ('''LS''')
 
*  IR Sensor ('''IS''')
 
*  2-Digit 7-Segment Display('''LD''')
 
*  8 Board LEDs('''LE''')
 
*  8 Board Switches ('''SW''')
 
 
=== Output Sensor Data ===
 
To output sensor data, simply access the sensor device using the device name given between the parenthesis in the bullets above.  In your main() function, you could type a device name followed by a . (period) to see the list of things you could do with a device.  For example, you could type: "TS." and the Eclipse drop-down menu would show function calls you can make.  We will use the <code>Ts.getValueAsString()</code> function call in the example below:
 
 
<syntaxhighlight lang="c">
 
int main()
 
{
 
    printf("Hello World!");
 
    while(1) {
 
        printf("Temperature Sensor Reading: %s\n", TS.getValueAsString());
 
        delay_ms(1000);
 
    }
 
}
 
</syntaxhighlight>
 

Latest revision as of 23:03, 4 September 2013

Introduction

This article will teach you:

  • Write a simple program for the SJ One Board
  • Output data from the Board Sensors

Please note that you need to read the Development Package article before following along this article.

The MAIN Function

The main() function is the entry point of a program. A lot of things may happen before main(), but it would be usually abstracted away from the user.

Locate main.cpp in your project

Hello World

Your "Hello World" project consists of printf message, compiling, loading the program onto the board, and confirming that your message comes out as you intended it. Follow these steps:

  1. Open up Eclipse
  2. Open Hello World Sample Project
  3. Open up main.cpp (You could search for it using shortcut key Ctrl+Shift+R)
  4. Write your own printf outputting your favorite message: printf("My own hello world!");
  5. Compile & Load the program onto the Board
  6. Open COM Port in Hercules and press RESET on the board to view your printf message.