I have been trying to build a temperature measurement and recording kit using an ATTiny84 chip and a DS18B20 temp sensor. The intention is to take temperature readings every 10 seconds and send these via serial communication to an external storage area such as a raspberry pi.
After some googling I managed to find a tutorial on how to use an arduino to read the sensor and send the result to the serial monitor every second.
Thanks Erni. I follow your post and the various pages that it led onto and managed to get as far as having my ATtiny pump out 0.00 to the serial which is a major leap forward for me so many thanks for your help. This at least proves I can write and send stuff from the chip.
When preparing, I was able to get the temp sensor working on an arduino so that it made a measurement every 10 seconds, and successfully sent the result to the serial monitor. For some reason it doesn't want to do this when I hook it up to the Tiny84. Ive tried connecting up the sensor to each leg of the chip in turn, and remembered to include the resistor each time but still no luck. Does anyone have any ideas why this may be?
There is a full example in the Cosa library that does all that. Download Cosa and install. Select the example sketch CosaDS18B20 and Cosa ATtiny84 as board. Compile and upload. All is included. You do not have to surf madly for libraries and cores. And there are tons of other classes to use. Fully integrated and compiles for all Arduino (AVR) boards, Mighty and Tiny.
Hi kowalski, Thanks for your response. I have just looked at the links you put and they look extremely interesting and worth further investigation however one part caught my attention; 'Unfortunately Cosa is not a beginners entry level programming platform'. Im afraid I would consider myself a beginner so I will have to leave it for now.
Im hoping that I might be able to get my present setup working first as Ido seem to have got quite close and I hoping that its just a couple of lines of code to change or a rearrangement of my wiring left to do. The sketch from my first post seems to be working. Just need to find out why those zeros are appearing instead of a temperature reading.
If anyone could offer any suggestions to help me solve it that would be a huge help.
My next step was to detach the ATtiny from the arduino and, using a hacked USB/Serial cable, plug it directly into the USB port of my windows laptop. I opened up the arduino IDE and opened the serial monitor. The text was garbled and mangled. Its definitely receiving things from the ATtiny as the monitor updates every 10sec, however the text is all on one line which suggests that the line break character is being mangled too. Any ideas gratefully received, and thanks in advance.
Another option is to use SoftwareSerial as an indicator for the tuning.
If you load this sketch to your Attiny84 it will output the OSCCAL value to the serial monitor.
A potmeter connected to PA3 will vary the OSCALL value, and you will see the output going
from garbled to readable and garbled again. Then you pick a value in tyhe midlle of the readable text.
#include <SoftwareSerial.h>
SoftwareSerial mySerial(2,3 ); //rx=PB2,tx=PA7 setup of software serial
void setup() {
mySerial.begin(9600);
}
void loop() {
int val=analogRead(3); //PA3
OSCCAL=val/4;
mySerial.print("Osccal= ");
mySerial.println(OSCCAL,HEX);
delay(200);
}
If you have a frequencee counter you can use the sketch below.
With a attiny84 @ 8MHz it will output 1MHz on pin5, if it is tuned correct.
Again a potmeter is connected to PA3, which will alter OSCCAL.
When you read 1 MHz on the frequence counter, you can read the OSCCAL value on the serial monitor.
#include <SoftwareSerial.h>
SoftwareSerial mySerial(2,3 ); //rx=PB2,tx=PA7 setup of software serial
void setup(){
mySerial.begin(9600);
OSCCAL = 0x9F;
pinMode(5,OUTPUT);
noInterrupts();
TCNT1 = 0;
TCCR1A=0;
TCCR1B=0;
TCCR1B |=(1<<WGM12); //Start timer 1 in CTC mode Table 14.4
TCCR1A |=(1<<COM1B0); //Timer1 in toggle mode Table 14-1
TCCR1B |=(1<<CS10) ; //prescaler Table 14-5, no prescal
interrupts();
OCR1A=3; //CTC Compare value
}
void loop(){
int val=analogRead(3); //PA3
OSCCAL=val/4;
mySerial.print("Osccal= ");
mySerial.println(OSCCAL,HEX);
delay(200);
}
'Reset the processor. A welcome message should be displayed.'
You breefly connect the reset pin (PB3) to ground, and you will see this in the serial monitor:
--------------------------------------------------------------------------------
Poor Man's Tiny Tuner
Slowly send lowercase 'x' to tune the oscillator...
// Starting OSCCAL value is 0x9C
Step OSCCAL
1
Then you start sending x 's.
You get a new line for every x, as the tuner try to determin the right OSCCAL value.
This is the final result for my particular ATtiny84
Poor Man's Tiny Tuner
Slowly send lowercase 'x' to tune the oscillator...
// Starting OSCCAL value is 0x9C
Step OSCCAL
1 9F
2 9E
3 9F
4 9F
5 9F
6 9F
7 9E
8 9E
9 A0
10 A0
11 A0
12 A0
13 A0
14 9F
Copy-and-paste the following line of code at the top of setup...
OSCCAL = 0x9F;
So in my sketch i will place this value in setup()