I2C, 2Wire vonalon kérnék segítséget.
Összeállítottam a Pro Minire alapozott, Max6675 hőmérős, 2 relés termosztátot ami I2C kimenetén csatlakozik a meglevő I2C buszra.
Azt olvassa com1 porton a pc, a program vb6-ban lett megírva.
Az Arduino analóg 4. lába az SDA, 5. lába az SCL, címzése &H50, library wire.h, a kód:
/*
Single_Temp.pde - Example using the MAX6675 Library.
Created by Ryan McLaughlin <ryanjmclaughlin@gmail.com>
This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.
http://creativecommons.org/licenses/by-sa/3.0/
*/
#define HIDEGEBB 6 // relay1
#define MELEGEBB 7 // relay2
#define MOTORFUTASIDO 1000
#define CIKLUSIDOMP 30
#include <MAX6675.h>
#include <Wire.h>
int x = 0;
int row = 0;
int LED1 = 13; // Status LED Pin
int CS = 4; // CS pin on MAX6675
int SO = 3; // SO pin of MAX6675
int SCLK = 5; // SCLK pin of MAX6675
int units = 1; // Units to readout temp (0 = raw, 1 = ˚C, 2 = ˚F)
float temperature = 0.0; // Temperature output variable
float hofok10 = 0.0;
// Initialize the MAX6675 Library for our chip
MAX6675 temp(CS,SO,SCLK,units);
// Setup Serial output and LED Pin
// MAX6675 Library already sets pin modes for MAX6675 chip!
void setup() {
Wire.begin(4); // join i2c bus with address #4
Wire.onReceive(receiveEvent); // register event
Serial.begin(9600);
Serial.println("CLEARDATA");
Serial.println("LABEL, TIME, temperature");
pinMode(LED1, OUTPUT);
pinMode(HIDEGEBB, OUTPUT);
pinMode(MELEGEBB, OUTPUT);
}
void loop() {
// Read the temp from the MAX6675
temperature = temp.read_temp();
if(temperature < 0) {
// If there is an error with the TC, temperature will be < 0
Serial.print("Thermocouple Error on CS");
Serial.println( temperature );
digitalWrite(LED1, HIGH);
} else {
//Serial.print("Current Temperature: ");
Serial.println(temperature );
digitalWrite(LED1, LOW);
Serial.print("DATA, TIME,");
row++;
x++;
}
// Wait one second before reading again
delay(1000);
int hofok10 = temp.read_temp()*10;
if(hofok10 > 300) {
digitalWrite(HIDEGEBB, LOW);
}
if(hofok10 < 290) {
digitalWrite(MELEGEBB, LOW);
}
delay(MOTORFUTASIDO);
digitalWrite(HIDEGEBB, HIGH);
digitalWrite(MELEGEBB, HIGH);
delay(CIKLUSIDOMP*100);
}
Mivel nem egy másik Arduinoval kell I2C buszon kommunikálni, nem kell a lábakat külön megadni?