Hi
I am currently setting up some measurements for a refrigirator prototype. I have 10 temperatures which I am reading with a ds18b20 Temp Sensor and the one wire protocol.
The Arduino is interfacing with a python-GUI, which is supposed to plot live temp Data from the senors. While Reading the one-Wire Data, I can't take any other actions like opening a valve or whatever.
Thats why I was planing to have the standalone ATmega328 to read data and wait until the Master-Arduino gives a signal that he is ready. In this case I want to write the read sensor Data to the serial Port, so the pyhton app can read, save and plot it. When the data is transmitted, I would like the stand alone ATmega to read data and the Arduino being ready to receive data via the Serial-Port from my app. Afer around 30 secondes, I would like the Master to Contact the Slave again.
My external ATmega has a 16Mhz crystal.
Programming the external processor works.
I am using oneWire, DallasTemperature and the Wire library.
My Idea was:
Master: Send byte when 30 seconds have past
Slave: set a boolean true, which exits a while loop and returns to the loop function that writes data:
So far the Idea didn't work out. I put the current code to illustrate what I am trying to do. I would be thankful for any suggestion!
Master:
#include <Wire.h>
void setup() {
Serial.begin(9600);
Wire.begin(); // j,oin i2c bus (address optional for master)
}
void loop() {
//for(int i = 1; i < 10; i++){
Wire.beginTransmission(8); // transmit to device #8
int o = 1;
Wire.write(o); // sends five bytes
Wire.endTransmission(); // stop transmitting
}
}
Slave:
// One Wire Stuff
#include <OneWire.h>
#include <DallasTemperature.h>
// Communication Stuff
#include <Wire.h>
#define ONE_WIRE_BUS_PIN 6
OneWire ds(ONE_WIRE_BUS_PIN); // Connect your 1-wire device to pin 3
DallasTemperature sensors(&ds);
boolean startTransmission = false;
void setup(void) {
Wire.begin(8); // join i2c bus with adress #8
Wire.onReceive(receiveEvent); // register Event
Serial.begin(9600); //start Serial for output
pinMode(9,OUTPUT);
}
void receiveEvent(int howMany){
startTransmission = true;
}
void loop(void) {
delay(100);
/*
sensors.begin();
sensors.requestTemperatures();
DeviceAddress testAdd = {0x28, 0x03, 0x2B, 0xE0, 0x05, 0x00, 0x00, 0xB3};
DeviceAddress testAdd2 = {0x28, 0x93, 0xD5, 0xE0, 0x05, 0x00, 0x00, 0x06};
float tempC = sensors.getTempC(testAdd);
float tempC2 = sensors.getTempC(testAdd2);
digitalWrite(9,HIGH);
//waitForCall();
while (startTransmission == false){
delay(50);
}
startTransmission = false;
delay(500);
digitalWrite(9,LOW);
Serial.print(tempC,2);
Serial.print(',');
Serial.println(tempC2,2);
}