workshops:arduino_to_the_next_level:ethernet_shield
Differences
This shows you the differences between two versions of the page.
workshops:arduino_to_the_next_level:ethernet_shield [2017-04-05 12:42] – external edit 127.0.0.1 | workshops: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' | + | 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-> | Run the Arduino software and open the example Ethernet-> | ||
+ | < | ||
#include < | #include < | ||
#include < | #include < | ||
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[] = { | ||
- | | + | |
// Initialize the Ethernet client library | // Initialize the Ethernet client library | ||
Line 60: | Line 61: | ||
} | } | ||
+ | </ | ||
- | + | | {{workshops: | |
- | | {{workshops: | + | |
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 " | 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 " | ||
- | The open/closed value is part of our Space API data, which you [[http:// | + | The open/closed value is part of our Space API data, which you [[http:// |
- | < | + | |
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: | ||
+ | < | ||
/* | /* | ||
This sketch connects to Edinburgh Hacklab' | This sketch connects to Edinburgh Hacklab' | ||
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[] = { | ||
- | | + | |
// 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 | + | |
Serial.begin(9600); | Serial.begin(9600); | ||
Line 232: | Line 233: | ||
lastAttemptTime = millis(); | lastAttemptTime = millis(); | ||
} | } | ||
+ | </ | ||
- | + | | {{workshops: | |
- | | {{workshops: | + | |
workshops/arduino_to_the_next_level/ethernet_shield.txt · Last modified: 2017-04-11 11:27 by Simon