User Tools

Site Tools


workshops:arduino_to_the_next_level:ethernet_shield

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

workshops:arduino_to_the_next_level:ethernet_shield [2017-04-05 12:42] – external edit 127.0.0.1workshops:arduino_to_the_next_level:ethernet_shield [2017-04-11 11:27] (current) Simon
Line 22: Line 22:
 Computers (and your Arduino) each need a unique hardware address, called a MAC address, to attach to the local network. They also need another unique address to allow communication with other devices, called an IP address. Computers (and your Arduino) each need a unique hardware address, called a MAC address, to attach to the local network. They also need another unique address to allow communication with other devices, called an IP address.
  
-In this case the Arduino will already know it'MAC address but will need to ask the network for an IP address (your computer does this every time you connect to a network using ethernet or WIFI). This first test makes sure that this IP address request works.+In this case the Arduino will already know its MAC address but will need to ask the network for an IP address (your computer does this every time you connect to a network using ethernet or WiFi). This first test makes sure that this IP address request works.
  
 Run the Arduino software and open the example Ethernet->DHCPAddressPrinter, it should look a bit like this: Run the Arduino software and open the example Ethernet->DHCPAddressPrinter, it should look a bit like this:
  
 +<code>
 #include <SPI.h> #include <SPI.h>
 #include <Ethernet.h> #include <Ethernet.h>
Line 31: Line 32:
 // Enter a MAC address for your controller below, make one up! // Enter a MAC address for your controller below, make one up!
 byte mac[] = {   byte mac[] = {  
-  0x00, 0xAA, 0xBB, 0xCC, 0xDE, 0x02 };+  0x02, 0xAA, 0xBB, 0xCC, 0xDE, 0x02 };
  
 // Initialize the Ethernet client library // Initialize the Ethernet client library
Line 60: Line 61:
  
 } }
 +</code>
  
- +| {{workshops:tar_exclamation_icon_svg.png?50x0}}| IMPORTANT! At the top of the sketch is the hardware MAC address that the Arduino will use. Change this to something random, otherwise you might find someone else's Arduino is using the same address and that would break things! The MAC address is six bytes long, each byte can be a value between 0x00 (decimal 0) and 0xFF (decimal 255) so change the numbers to something else ([[https://en.wikipedia.org/wiki/MAC_address#Address_details|but leave the first byte at 0x02]]). |
-| {{workshops:tar_exclamation_icon_svg.png?50x0}}| IMPORTANT! At the top of the sketch is the hardware MAC address that the Arduino will use. Change this to something random, otherwise you might find someone else's Arduino is using the same address and that would break things!The MAC address is six bytes long, each byte can be a value between 0x00 (decimal 0) and 0xFF (decimal 255) so change the numbers to something else. |+
  
  
Line 74: Line 75:
 You could scrape the weather forecast from the Met Office, or the current Bitcoin price, but we're going to find out if the Hacklab is open. This data is online because we use it on our website. The box by the door has green and red buttons, long-pressing the green button sets the lab to "open", our website updates and we [[https://twitter.com/EdinHacklabOpen|tweet it]]. You could scrape the weather forecast from the Met Office, or the current Bitcoin price, but we're going to find out if the Hacklab is open. This data is online because we use it on our website. The box by the door has green and red buttons, long-pressing the green button sets the lab to "open", our website updates and we [[https://twitter.com/EdinHacklabOpen|tweet it]].
  
-The open/closed value is part of our Space API data, which you [[http://spaceapi.edinburghhacklab.com/spaceapi.json|can see here]]. The JSON file is designed to be machine-readable, the important bit we're looking for is the line: +The open/closed value is part of our Space API data, which you [[http://spaceapi.edinburghhacklab.com/spaceapi.json|can see here]]. The JSON file is designed to be machine-readable, the important bit we're looking for is the line: ''"open": true, ''
-<code>"open": true, </code>+
  
 Here's the Arduino code to connect to the server, request the JSON file and then find the lab status line. It's quite long, but commented, so run it and have a read through to see if you can figure out how it works: Here's the Arduino code to connect to the server, request the JSON file and then find the lab status line. It's quite long, but commented, so run it and have a read through to see if you can figure out how it works:
  
 +<code>
 /* /*
   This sketch connects to Edinburgh Hacklab's Space API server and pulls   This sketch connects to Edinburgh Hacklab's Space API server and pulls
Line 96: Line 97:
 // The IP address will be dependent on your local network: // The IP address will be dependent on your local network:
 byte mac[] = {  byte mac[] = { 
-  0x00, 0xAA, 0xBE, 0xCC, 0xBE, 0x01 };+  0x02, 0xAA, 0xBE, 0xCC, 0xBE, 0x01 };
  
 // initialise the Ethernet library instance // initialise the Ethernet library instance
Line 120: Line 121:
   labStatus.reserve(50);   labStatus.reserve(50);
  
- // Open serial to the host+  // Open serial to the host
   Serial.begin(9600);   Serial.begin(9600);
  
Line 232: Line 233:
   lastAttemptTime = millis();   lastAttemptTime = millis();
 }    }   
 +</code>
  
  
- +| {{workshops:challenge_yourself.jpg?200x0}}| **Intermediate** \\ **(1)** How about adding the LCD module you've already used and displaying the status on that? You'll need to merge in some code from the [[http://arduino.cc/en/Tutorial/LiquidCrystal|LCD tutorial]] but make sure you don't use pins 10, 11, 12 or 13 for the LCD as they're used by the Ethernet shield. \\ \\ **Harder** \\ **(2)** Scrape some other data! How about [[http://api.openweathermap.org/data/2.5/weather?q=Edinburgh,uk|the current weather in Edinburgh]] from [[http://openweathermap.org/API|Open Weather Map's API]]? See if you can grab the current temperature. |
-| {{workshops:challenge_yourself.jpg?200x0}}| **Intermediate****(1)** How about adding the LCD module you've already used and displaying the status on that? You'll need to merge in some code from the [[http://arduino.cc/en/Tutorial/LiquidCrystal|LCD tutorial]] but make sure you don't use pins 10, 11, 12 or 13 for the LCD as they're used by the Ethernet shield.**Harder****(2)** Scrape some other data! How about [[http://api.openweathermap.org/data/2.5/weather?q=Edinburgh,uk|the current weather in Edinburgh]] from [[http://openweathermap.org/API|Open Weather Map's API]]? See if you can grab the current temperature. |+
  
workshops/arduino_to_the_next_level/ethernet_shield.txt · Last modified: 2017-04-11 11:27 by Simon

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki