Skip to content

Commit 9a46334

Browse files
committed
Added ethernet module to local hardware instance, since we have to hack it a bit in order to move it to alternative SPI port
Removed Wire and SAMD_AnalogCorrection libraries from HW section, as we didn't change anything in those, so let's keep it to the standard ones Modified SPI library, initializing extra SPI ports, also HW mux changes in the setup of individual SPI ports to match the GW setup Added MyHWSAMD files so they are included in the core headers (MyConfig.h / MySensors.h)
1 parent a9e8366 commit 9a46334

File tree

48 files changed

+4475
-1029
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+4475
-1029
lines changed

libraries/Ethernet/README.adoc

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
= Ethernet Library for Arduino =
2+
3+
With the Arduino Ethernet Shield, this library allows an Arduino board to connect to the internet.
4+
5+
For more information about this library please visit us at
6+
http://www.arduino.cc/en/Reference/Ethernet
7+
8+
== License ==
9+
10+
Copyright (c) 2010 Arduino LLC. All right reserved.
11+
12+
This library is free software; you can redistribute it and/or
13+
modify it under the terms of the GNU Lesser General Public
14+
License as published by the Free Software Foundation; either
15+
version 2.1 of the License, or (at your option) any later version.
16+
17+
This library is distributed in the hope that it will be useful,
18+
but WITHOUT ANY WARRANTY; without even the implied warranty of
19+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20+
Lesser General Public License for more details.
21+
22+
You should have received a copy of the GNU Lesser General Public
23+
License along with this library; if not, write to the Free Software
24+
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
/*
2+
Advanced Chat Server
3+
4+
A more advanced server that distributes any incoming messages
5+
to all connected clients but the client the message comes from.
6+
To use, telnet to your device's IP address and type.
7+
You can see the client's input in the serial monitor as well.
8+
Using an Arduino Wiznet Ethernet shield.
9+
10+
Circuit:
11+
* Ethernet shield attached to pins 10, 11, 12, 13
12+
13+
created 18 Dec 2009
14+
by David A. Mellis
15+
modified 9 Apr 2012
16+
by Tom Igoe
17+
redesigned to make use of operator== 25 Nov 2013
18+
by Norbert Truchsess
19+
20+
*/
21+
22+
#include <SPI.h>
23+
#include <Ethernet.h>
24+
25+
// Enter a MAC address and IP address for your controller below.
26+
// The IP address will be dependent on your local network.
27+
// gateway and subnet are optional:
28+
byte mac[] = {
29+
0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED
30+
};
31+
IPAddress ip(192, 168, 1, 177);
32+
IPAddress myDns(192, 168, 1, 1);
33+
IPAddress gateway(192, 168, 1, 1);
34+
IPAddress subnet(255, 255, 0, 0);
35+
36+
37+
// telnet defaults to port 23
38+
EthernetServer server(23);
39+
40+
EthernetClient clients[4];
41+
42+
void setup() {
43+
// initialize the Ethernet device
44+
Ethernet.begin(mac, ip, myDns, gateway, subnet);
45+
// start listening for clients
46+
server.begin();
47+
// Open serial communications and wait for port to open:
48+
Serial.begin(9600);
49+
while (!Serial) {
50+
; // wait for serial port to connect. Needed for native USB port only
51+
}
52+
53+
54+
Serial.print("Chat server address:");
55+
Serial.println(Ethernet.localIP());
56+
}
57+
58+
void loop() {
59+
// wait for a new client:
60+
EthernetClient client = server.available();
61+
62+
// when the client sends the first byte, say hello:
63+
if (client) {
64+
65+
boolean newClient = true;
66+
for (byte i = 0; i < 4; i++) {
67+
//check whether this client refers to the same socket as one of the existing instances:
68+
if (clients[i] == client) {
69+
newClient = false;
70+
break;
71+
}
72+
}
73+
74+
if (newClient) {
75+
//check which of the existing clients can be overridden:
76+
for (byte i = 0; i < 4; i++) {
77+
if (!clients[i] && clients[i] != client) {
78+
clients[i] = client;
79+
// clear out the input buffer:
80+
client.flush();
81+
Serial.println("We have a new client");
82+
client.print("Hello, client number: ");
83+
client.print(i);
84+
client.println();
85+
break;
86+
}
87+
}
88+
}
89+
90+
if (client.available() > 0) {
91+
// read the bytes incoming from the client:
92+
char thisChar = client.read();
93+
// echo the bytes back to all other connected clients:
94+
for (byte i = 0; i < 4; i++) {
95+
if (clients[i] && (clients[i] != client)) {
96+
clients[i].write(thisChar);
97+
}
98+
}
99+
// echo the bytes to the server as well:
100+
Serial.write(thisChar);
101+
}
102+
}
103+
for (byte i = 0; i < 4; i++) {
104+
if (!(clients[i].connected())) {
105+
// client.stop() invalidates the internal socket-descriptor, so next use of == will allways return false;
106+
clients[i].stop();
107+
}
108+
}
109+
}
Lines changed: 220 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,220 @@
1+
/*
2+
SCP1000 Barometric Pressure Sensor Display
3+
4+
Serves the output of a Barometric Pressure Sensor as a web page.
5+
Uses the SPI library. For details on the sensor, see:
6+
http://www.sparkfun.com/commerce/product_info.php?products_id=8161
7+
http://www.vti.fi/en/support/obsolete_products/pressure_sensors/
8+
9+
This sketch adapted from Nathan Seidle's SCP1000 example for PIC:
10+
http://www.sparkfun.com/datasheets/Sensors/SCP1000-Testing.zip
11+
12+
Circuit:
13+
SCP1000 sensor attached to pins 6,7, and 11 - 13:
14+
DRDY: pin 6
15+
CSB: pin 7
16+
MOSI: pin 11
17+
MISO: pin 12
18+
SCK: pin 13
19+
20+
created 31 July 2010
21+
by Tom Igoe
22+
*/
23+
24+
#include <Ethernet.h>
25+
// the sensor communicates using SPI, so include the library:
26+
#include <SPI.h>
27+
28+
29+
// assign a MAC address for the Ethernet controller.
30+
// fill in your address here:
31+
byte mac[] = {
32+
0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED
33+
};
34+
// assign an IP address for the controller:
35+
IPAddress ip(192, 168, 1, 20);
36+
37+
38+
// Initialize the Ethernet server library
39+
// with the IP address and port you want to use
40+
// (port 80 is default for HTTP):
41+
EthernetServer server(80);
42+
43+
44+
//Sensor's memory register addresses:
45+
const int PRESSURE = 0x1F; //3 most significant bits of pressure
46+
const int PRESSURE_LSB = 0x20; //16 least significant bits of pressure
47+
const int TEMPERATURE = 0x21; //16 bit temperature reading
48+
49+
// pins used for the connection with the sensor
50+
// the others you need are controlled by the SPI library):
51+
const int dataReadyPin = 6;
52+
const int chipSelectPin = 7;
53+
54+
float temperature = 0.0;
55+
long pressure = 0;
56+
long lastReadingTime = 0;
57+
58+
void setup() {
59+
// start the SPI library:
60+
SPI.begin();
61+
62+
// start the Ethernet connection and the server:
63+
Ethernet.begin(mac, ip);
64+
server.begin();
65+
66+
// initalize the data ready and chip select pins:
67+
pinMode(dataReadyPin, INPUT);
68+
pinMode(chipSelectPin, OUTPUT);
69+
70+
Serial.begin(9600);
71+
72+
//Configure SCP1000 for low noise configuration:
73+
writeRegister(0x02, 0x2D);
74+
writeRegister(0x01, 0x03);
75+
writeRegister(0x03, 0x02);
76+
77+
// give the sensor and Ethernet shield time to set up:
78+
delay(1000);
79+
80+
//Set the sensor to high resolution mode tp start readings:
81+
writeRegister(0x03, 0x0A);
82+
83+
}
84+
85+
void loop() {
86+
// check for a reading no more than once a second.
87+
if (millis() - lastReadingTime > 1000) {
88+
// if there's a reading ready, read it:
89+
// don't do anything until the data ready pin is high:
90+
if (digitalRead(dataReadyPin) == HIGH) {
91+
getData();
92+
// timestamp the last time you got a reading:
93+
lastReadingTime = millis();
94+
}
95+
}
96+
97+
// listen for incoming Ethernet connections:
98+
listenForEthernetClients();
99+
}
100+
101+
102+
void getData() {
103+
Serial.println("Getting reading");
104+
//Read the temperature data
105+
int tempData = readRegister(0x21, 2);
106+
107+
// convert the temperature to celsius and display it:
108+
temperature = (float)tempData / 20.0;
109+
110+
//Read the pressure data highest 3 bits:
111+
byte pressureDataHigh = readRegister(0x1F, 1);
112+
pressureDataHigh &= 0b00000111; //you only needs bits 2 to 0
113+
114+
//Read the pressure data lower 16 bits:
115+
unsigned int pressureDataLow = readRegister(0x20, 2);
116+
//combine the two parts into one 19-bit number:
117+
pressure = ((pressureDataHigh << 16) | pressureDataLow) / 4;
118+
119+
Serial.print("Temperature: ");
120+
Serial.print(temperature);
121+
Serial.println(" degrees C");
122+
Serial.print("Pressure: " + String(pressure));
123+
Serial.println(" Pa");
124+
}
125+
126+
void listenForEthernetClients() {
127+
// listen for incoming clients
128+
EthernetClient client = server.available();
129+
if (client) {
130+
Serial.println("Got a client");
131+
// an http request ends with a blank line
132+
boolean currentLineIsBlank = true;
133+
while (client.connected()) {
134+
if (client.available()) {
135+
char c = client.read();
136+
// if you've gotten to the end of the line (received a newline
137+
// character) and the line is blank, the http request has ended,
138+
// so you can send a reply
139+
if (c == '\n' && currentLineIsBlank) {
140+
// send a standard http response header
141+
client.println("HTTP/1.1 200 OK");
142+
client.println("Content-Type: text/html");
143+
client.println();
144+
// print the current readings, in HTML format:
145+
client.print("Temperature: ");
146+
client.print(temperature);
147+
client.print(" degrees C");
148+
client.println("<br />");
149+
client.print("Pressure: " + String(pressure));
150+
client.print(" Pa");
151+
client.println("<br />");
152+
break;
153+
}
154+
if (c == '\n') {
155+
// you're starting a new line
156+
currentLineIsBlank = true;
157+
} else if (c != '\r') {
158+
// you've gotten a character on the current line
159+
currentLineIsBlank = false;
160+
}
161+
}
162+
}
163+
// give the web browser time to receive the data
164+
delay(1);
165+
// close the connection:
166+
client.stop();
167+
}
168+
}
169+
170+
171+
//Send a write command to SCP1000
172+
void writeRegister(byte registerName, byte registerValue) {
173+
// SCP1000 expects the register name in the upper 6 bits
174+
// of the byte:
175+
registerName <<= 2;
176+
// command (read or write) goes in the lower two bits:
177+
registerName |= 0b00000010; //Write command
178+
179+
// take the chip select low to select the device:
180+
digitalWrite(chipSelectPin, LOW);
181+
182+
SPI.transfer(registerName); //Send register location
183+
SPI.transfer(registerValue); //Send value to record into register
184+
185+
// take the chip select high to de-select:
186+
digitalWrite(chipSelectPin, HIGH);
187+
}
188+
189+
190+
//Read register from the SCP1000:
191+
unsigned int readRegister(byte registerName, int numBytes) {
192+
byte inByte = 0; // incoming from the SPI read
193+
unsigned int result = 0; // result to return
194+
195+
// SCP1000 expects the register name in the upper 6 bits
196+
// of the byte:
197+
registerName <<= 2;
198+
// command (read or write) goes in the lower two bits:
199+
registerName &= 0b11111100; //Read command
200+
201+
// take the chip select low to select the device:
202+
digitalWrite(chipSelectPin, LOW);
203+
// send the device the register you want to read:
204+
int command = SPI.transfer(registerName);
205+
// send a value of 0 to read the first byte returned:
206+
inByte = SPI.transfer(0x00);
207+
208+
result = inByte;
209+
// if there's more than one byte returned,
210+
// shift the first byte then get the second byte:
211+
if (numBytes > 1) {
212+
result = inByte << 8;
213+
inByte = SPI.transfer(0x00);
214+
result = result | inByte;
215+
}
216+
// take the chip select high to de-select:
217+
digitalWrite(chipSelectPin, HIGH);
218+
// return the result:
219+
return (result);
220+
}

0 commit comments

Comments
 (0)