Hardware Reference
In-Depth Information
Connecting Using Linux Commands
Now that you've tested your connection using the Ethernet library or WiFi
library for Galileo, I want to introduce you to a different way to make con-
nections. As mentioned in Chapter 1 , there's a version of Linux running on
Galileo, and a simple bit of Arduino code can run any Linux command. You
tried this out a bit in “Looking at Linux” on page 60 , but here you're going to
take a deeper dive.
If you've ever used the Linux or Unix command line before, you'll feel pretty
comfortable with this. Those of you who are well-versed in the command line
will quickly see how powerful this can be. No matter what your experience
level is, you'll find this to be a handy trick when you want to do things that are
more complicated than Arduino code can handle easily.
1. Make sure your Galileo is connected to the network via Ethernet, or has
the WiFi module installed and tested.
2. Connect power to the Galileo.
3. Connect your computer to Galileo via the USB client port.
4. Create a new sketch within the Arduino IDE and enter in the code from
Example 6-1 .
5. Upload the code to the Galileo.
6. Open the serial monitor.
7. In the text entry field at the top of the serial monitor, type any character
and click Send.
If everything is working correctly, you should see HTML from MAKE's website
pouring into your serial monitor.
Example 6-1. Using a system call to connect to a
server
void setup () {
Serial . begin ( 9600 );
}
void loop () {
if ( Serial . available ()) { //
Serial . read (); //
system ( "curl http://makezine.com &> /dev/ttyGS0" ); //
}
}
If there's a character available in the serial buffer, execute the code
in the block below. Where does this character come from? You'll type
it into the serial monitor.
Search WWH ::




Custom Search