Add code to test I²C in practise
This commit is contained in:
parent
da8350f2e4
commit
dcd5298323
@ -17,3 +17,6 @@ generate_arduino_firmware(WeatherStationLogger
|
|||||||
|
|
||||||
generate_arduino_firmware(WeatherStationWeb
|
generate_arduino_firmware(WeatherStationWeb
|
||||||
SKETCH WeatherStationWeb)
|
SKETCH WeatherStationWeb)
|
||||||
|
|
||||||
|
generate_arduino_firmware(I2CPractise
|
||||||
|
SKETCH I2CPractise)
|
||||||
|
107
arduino/I2CPractise/I2CPractise.ino
Normal file
107
arduino/I2CPractise/I2CPractise.ino
Normal file
@ -0,0 +1,107 @@
|
|||||||
|
/*
|
||||||
|
Copyright (C) 2012 Nathanaël Restori
|
||||||
|
|
||||||
|
Permission is hereby granted, free of charge, to any person
|
||||||
|
obtaining a copy of this software and associated documentation
|
||||||
|
files (the "Software"), to deal in the Software without
|
||||||
|
restriction, including without limitation the rights to use, copy,
|
||||||
|
modify, merge, publish, distribute, sublicense, and/or sell copies
|
||||||
|
of the Software, and to permit persons to whom the Software is
|
||||||
|
furnished to do so, subject to the following conditions:
|
||||||
|
|
||||||
|
The above copyright notice and this permission notice shall be
|
||||||
|
included in all copies or substantial portions of the Software.
|
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||||
|
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||||
|
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||||
|
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
|
||||||
|
BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
|
||||||
|
ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
||||||
|
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
|
SOFTWARE.
|
||||||
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <Wire.h>
|
||||||
|
#include "Chronodot.h"
|
||||||
|
|
||||||
|
#define CHRONODOT_ADDRESS 0x68
|
||||||
|
|
||||||
|
static uint8_t bcd2bin (uint8_t val) { return val - 6 * (val >> 4); }
|
||||||
|
|
||||||
|
void setup() {
|
||||||
|
Serial.begin(9600);
|
||||||
|
|
||||||
|
Wire.begin();
|
||||||
|
|
||||||
|
Serial.println("BEGIN transmission");
|
||||||
|
|
||||||
|
Wire.beginTransmission(CHRONODOT_ADDRESS);
|
||||||
|
Wire.write((byte)0);
|
||||||
|
Wire.endTransmission();
|
||||||
|
|
||||||
|
Wire.requestFrom(CHRONODOT_ADDRESS, 19);
|
||||||
|
byte blah[20];
|
||||||
|
int i;
|
||||||
|
for(i=0; i<20; i++) {
|
||||||
|
blah[i] = Wire.read();
|
||||||
|
}
|
||||||
|
|
||||||
|
Serial.println("END transmission");
|
||||||
|
|
||||||
|
uint8_t ss = bcd2bin(blah[0] & 0x7F);
|
||||||
|
uint8_t mm = bcd2bin(blah[1]);
|
||||||
|
uint8_t hh = bcd2bin(blah[2]);
|
||||||
|
uint8_t d = bcd2bin(blah[4]);
|
||||||
|
uint8_t m = bcd2bin(blah[5]);
|
||||||
|
uint16_t y = bcd2bin(blah[6]) + 2000;
|
||||||
|
float ttc = (float)(int)blah[17];
|
||||||
|
byte portion = blah[18];
|
||||||
|
if(portion == 0b01000000) ttc += 0.25;
|
||||||
|
if(portion == 0b10000000) ttc += 0.5;
|
||||||
|
if(portion == 0b11000000) ttc += 0.75;
|
||||||
|
float degF = (((ttc * 9.0) / 5.0) + 32.5);
|
||||||
|
int ttf = (int)degF;
|
||||||
|
//return DateTime (y, m, d, hh, mm, ss, ttf, ttc);
|
||||||
|
|
||||||
|
Serial.println();
|
||||||
|
Serial.println("What\tByte\tCorrespondance");
|
||||||
|
Serial.println("------------------------------");
|
||||||
|
Serial.print("seconds\t"); Serial.print(blah[0]); Serial.print("\t"); Serial.println(ss);
|
||||||
|
Serial.print("minutes\t"); Serial.print(blah[1]); Serial.print("\t"); Serial.println(mm);
|
||||||
|
Serial.print("hours\t"); Serial.print(blah[2]); Serial.print("\t"); Serial.println(hh);
|
||||||
|
Serial.print("days\t"); Serial.print(blah[4]); Serial.print("\t"); Serial.println(d);
|
||||||
|
Serial.print("monthes\t"); Serial.print(blah[5]); Serial.print("\t"); Serial.println(m);
|
||||||
|
Serial.print("years\t"); Serial.print(blah[6]); Serial.print("\t"); Serial.println(y);
|
||||||
|
Serial.print("temp\t"); Serial.print(blah[17]); Serial.print("\t"); Serial.println(ttc);
|
||||||
|
Serial.print("temp\t"); Serial.print(blah[18]); Serial.print("\t"); Serial.println(portion);
|
||||||
|
|
||||||
|
Serial.println();
|
||||||
|
Serial.println("Byte\tContent");
|
||||||
|
Serial.println("---------------");
|
||||||
|
Serial.print("0\t"); Serial.println(blah[0]);
|
||||||
|
Serial.print("1\t"); Serial.println(blah[1]);
|
||||||
|
Serial.print("2\t"); Serial.println(blah[2]);
|
||||||
|
Serial.print("3\t"); Serial.println(blah[3]);
|
||||||
|
Serial.print("4\t"); Serial.println(blah[4]);
|
||||||
|
Serial.print("5\t"); Serial.println(blah[5]);
|
||||||
|
Serial.print("6\t"); Serial.println(blah[6]);
|
||||||
|
Serial.print("7\t"); Serial.println(blah[7]);
|
||||||
|
Serial.print("8\t"); Serial.println(blah[8]);
|
||||||
|
Serial.print("9\t"); Serial.println(blah[9]);
|
||||||
|
Serial.print("10\t"); Serial.println(blah[10]);
|
||||||
|
Serial.print("11\t"); Serial.println(blah[11]);
|
||||||
|
Serial.print("12\t"); Serial.println(blah[12]);
|
||||||
|
Serial.print("13\t"); Serial.println(blah[13]);
|
||||||
|
Serial.print("14\t"); Serial.println(blah[14]);
|
||||||
|
Serial.print("15\t"); Serial.println(blah[15]);
|
||||||
|
Serial.print("16\t"); Serial.println(blah[16]);
|
||||||
|
Serial.print("17\t"); Serial.println(blah[17]);
|
||||||
|
Serial.print("18\t"); Serial.println(blah[18]);
|
||||||
|
Serial.print("19\t"); Serial.println(blah[19]);
|
||||||
|
}
|
||||||
|
|
||||||
|
void loop() {
|
||||||
|
delay(1000);
|
||||||
|
}
|
@ -40,7 +40,7 @@
|
|||||||
|
|
||||||
static uint8_t mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
|
static uint8_t mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
|
||||||
static IPAddress ip = IPAddress(192, 168, 1, 210);
|
static IPAddress ip = IPAddress(192, 168, 1, 210);
|
||||||
static IPAddress timeserver = IPAddress(192, 43, 244, 18);
|
static IPAddress timeserver = IPAddress(213, 239, 239, 164);
|
||||||
|
|
||||||
P(indexHtml) = "<!DOCTYPE html><html><head><meta charset='utf-8'/"
|
P(indexHtml) = "<!DOCTYPE html><html><head><meta charset='utf-8'/"
|
||||||
"><title>Station Météo</title><style>html, body{ba"
|
"><title>Station Météo</title><style>html, body{ba"
|
||||||
@ -178,7 +178,9 @@ void sendNTPpacket() {
|
|||||||
|
|
||||||
Serial.println("Adjusting time");
|
Serial.println("Adjusting time");
|
||||||
chronodot.adjust(DateTime(epoch));
|
chronodot.adjust(DateTime(epoch));
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
Serial.println("No reponse");
|
||||||
}
|
}
|
||||||
|
|
||||||
void setup() {
|
void setup() {
|
||||||
|
Loading…
Reference in New Issue
Block a user