arduino uno + SD карта + ds18b20
- Войдите на сайт для отправки комментариев
Пнд, 09/06/2014 - 12:44
Arduino uno + SD ридер работает использую родной пример.
Arduino + ds18b20 = тоже работает, выводит данные в com port.
Пробую соединить arduino uno + SD карта + ds18b20 = скетч заливается, далее скетч висит, без действия, не пойму где косяк, и как его определить...
/*
This example shows how to log data from three analog sensors
to an SD card using the SD library.
The circuit:
* analog sensors on analog ins 0, 1, and 2
* SD card attached to SPI bus as follows:
** MOSI - pin 11
** MISO - pin 12
** CLK - pin 13
** CS - pin 4
*/
#include <stdio.h>
#include <DS1302.h>
#include <SD.h>
#include <OneWire.h>
const int kCePin = 5; // Chip Enable
const int kIoPin = 6; // Input/Output
const int kSclkPin = 7; // Serial Clock
DS1302 rtc(kCePin, kIoPin, kSclkPin);
int i;
byte present = 0;
byte type_s;
byte data[12];
byte addr[8];
int ss = 0;
float celsius;
byte address_1[] = {0x28, 0x19, 0x00, 0xC0, 0x04, 0x00, 0x00, 0x74};
byte address_2[] = {0x28, 0x56, 0x04, 0xC0, 0x04, 0x00, 0x00, 0x3A};
OneWire ds (10); // все OneWire устройства на pin 10
byte done[8];
const int chipSelect = 4;
void setup()
{
// Open serial communications and wait for port to open:
Serial.begin(9600);
while (!Serial) {
; // wait for serial port to connect. Needed for Leonardo only
}
rtc.writeProtect(false);
rtc.halt(false);
Serial.print("Initializing SD card...");
if (!SD.begin(chipSelect)) {
Serial.println("Card failed, or not present");
return;
}
Serial.println("card initialized.");
}
void reeds()
{
if(ds.search(addr) != 1)
{
ds.reset_search();
delay(250);
for(byte i = 0; i < 8; i++) addr[i] = 0;
return;
}
ds.reset ();
ds.select (addr);
Serial.println("----------");
ds.write (0x44,1); // start conversion, with parasite power on at the end
delay (1000);
present = ds.reset ();
ds.select (addr);
ds.write (0xBE); // Read Scratchpad
for (i = 0; i < 9; i++) { // we need 9 bytes
data[i] = ds.read ();
}
// convert the data to actual temperature
unsigned int raw = (data[1] << 8) | data[0];
if (type_s) {
raw = raw << 3; // 9 bit resolution default
if (data[7] == 0x10) {
raw = (raw & 0xFFF0) + 12 - data[6];
}
}
else {
byte cfg = (data[4] & 0x60);
if (cfg == 0x00) raw = raw << 3; // 9 bit resolution, 93.75 ms
else if (cfg == 0x20) raw = raw << 2; // 10 bit res, 187.5 ms
else if (cfg == 0x40) raw = raw << 1; // 11 bit res, 375 ms
}
celsius = (float)raw / 16.0;
}
void zapis (){
reeds();
Time t = rtc.time();
char buf[50];
snprintf(buf, sizeof(buf), "%04d-%02d-%02d %02d:%02d:%02d",
t.yr, t.mon, t.date,
t.hr, t.min, t.sec);
Serial.println(buf);
char dist_str[6];
dtostrf(celsius,9, 6, dist_str);
String dataString = "";
dataString += buf;
dataString += " | ";
dataString += dist_str;
// open the file. note that only one file can be open at a time,
// so you have to close this one before opening another.
File dataFile = SD.open("datalog.txt", FILE_WRITE);
// if the file is available, write to it:
if (dataFile) {
dataFile.println(dataString);
dataFile.close();
// print to the serial port too:
Serial.println(dataString);
}
// if the file isn't open, pop up an error:
else {
Serial.println("error opening datalog.txt");
}
}
void loop()
{
Serial.println("++++");
for (i = 5; i < 55; i=i+5){
Serial.println(i);
Time t = rtc.time();
if (t.min = i){
if (ss != i){
zapis ();
ss = i;
}
}
}
}
Я предпологаю что где-то пересекаются используемые пины... Пробовал устанавливать в другой пин 18b20, результата нет.