|
|
(One intermediate revision by the same user not shown) |
Line 1: |
Line 1: |
| [[Category:Language]]{{NoTitle}} | | #REDIRECT [[Language - C]] |
| {|
| |
| |style="vertical-align:middle; width: 60%;"|
| |
| <font size=6>'''Language - C'''
| |
| | |
| '''SBC Linux with GCC'''</font>
| |
| | |
| Welcome to using Phidgets with C! By using C, you will have access to the complete Phidget22 API, including events.
| |
| | |
| GCC is a compiler system for originally written for GNU, and is the standard compiler on unix-like operating systems like Linux. It allows compilation of C programs from the command line.
| |
| |{{TOC limit|2}}
| |
| |}
| |
| ==Getting Started With the Phidget SBC==
| |
| Welcome to using the Phidget SBC. If you haven't already, check out the [[SBC3003 User Guide#Getting Started | user guide]] in order to set up the following:
| |
| * Networking
| |
| * Administrator password
| |
| | |
| | |
| If you are ready to go, the first step will be deciding how you will use the SBC:
| |
| *Use a more powerful external computer to develop your code, and then simply copy the files to the SBC.
| |
| *Use the SBC like any other Linux computer, simply connect a monitor and a keyboard and begin your development.
| |
| | |
| | |
| This guide will cover development using an external machine. For development using the SBC itself, check the [[Language_-_C_Linux_GCC|GCC (Linux)]] page.
| |
| | |
| To begin, this video will help you get started:
| |
| <center>{{#ev:youtube|8vv8kx4743c|||||rel=0}}</center>
| |
| | |
| | |
| ===Developing with an External Computer===
| |
| {{SBC_Developing_with_an_External_Computer}}
| |
| | |
| ===Installing Packages for Development===
| |
| At this point you have connected to the SBC through one or more of these three options:
| |
| *SBC Web Interface
| |
| *SSH
| |
| *Directly via monitor and keyboard
| |
| | |
| Now that you are connected, you may want to start developing on/for the SBC. Before you do this, you need to install some packages.
| |
| | |
| The simplest way to install C support on the SBC is by using the install buttons on located on the SBC Web Interface (System->Packages). Check ''Include full Debian Package Repository'' before installing.
| |
| | |
| | |
| [[File:phidgetsbc_installpackages.PNG|link=|alt=|center]]
| |
| | |
| You're now ready to begin programming! Continue through this guide for code examples and directions on where to go next.
| |
| | |
| {{Finding Code Samples|C}}
| |
| | |
| ==Setting up a New Project==
| |
| '''''For simplicity, if you have not used Phidgets before, we recommend first trying them out directly on an external development machine like a desktop computer. For C development, check the [[Language_-_C_Windows_GCC|GCC (Windows)]], [[Language_-_C_macOS_GCC|GCC (MacOS)]], and [[Language_-_C_Linux_GCC|GCC (Linux)]] pages.'''''
| |
| | |
| When you are building a project from scratch, or adding Phidget functionality to an existing project, you'll need to configure your development environment to properly link the Phidget C library.
| |
| | |
| When developing on an external computer, you will write, compile, and test your programs on that machine. When you are ready, you will then upload your programs to the SBC to compile and run them.
| |
| | |
| | |
| Once your code is written, follow these steps to get your program running on the SBC:
| |
| | |
| 1. Using the SBC Web Interface, create a new project:
| |
| [[File:Phidgetsbc_createproject.PNG|link=|alt=|center]]
| |
| | |
| 2. Transfer all the project files from the development machine to the SBC, either using the SBC Web Interface or a tool like [https://winscp.net/eng/download.php WinSCP]. The project directory will be <code>/usr/userapps/ProjectName</code>.
| |
| | |
| 3. Use [[#SSH|SSH]] to access the SBC terminal
| |
| | |
| 4. Navigate to the project folder using the command:
| |
| | |
| <syntaxhighlight lang=bash>
| |
| cd /usr/userapps/ProjectName
| |
| </syntaxhighlight>
| |
| | |
| 5. Compile the example by entering the following command in the terminal, replacing "example" with the name of your C file:
| |
| | |
| <syntaxhighlight lang='bash'>
| |
| gcc example.c -o example -lphidget22
| |
| </syntaxhighlight>
| |
| | |
| 6. You can now run the program with the command:
| |
| | |
| <syntaxhighlight lang='bash'>
| |
| ./example
| |
| </syntaxhighlight>
| |
| | |
| Success! The program is running on your SBC. Next, you may want to learn about [[#Running a program automatically|running a program automatically]].
| |
| | |
| ==Running a Program Automatically==
| |
| After testing your program, you will likely want it to run on boot, or on a schedule, without your input.
| |
| | |
| {{SBC_Running_A_Program_Automatically}}
| |
| | |
| {{Language Page What's Next}}
| |