Pages: [1]   Go Down
Author Topic: [Solved] Attiny85 and 24lc256 on i2c taking temperature. how to read it?  (Read 647 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Full Member
***
Karma: 2
Posts: 148
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hello all,
in experimenting, ive got an attiny85, 24lc256, lm34 and max1555 with a 110mah lipo taking temperature every minute for about 20 minutes. this experiment is all part of my learning, my question is, where do i go from here? specifically, instead of me pulling my eeprom every time i want to read it, whats a solid way to read the eeprom in place after my sampling is done. the sketch isnt 100% meaning its just in testing phase to get me 20 samples, and alert me when done. id like to be able to plug it up to usb and retrieve the data somehow. im not opposed to purchasing breakout boards, but would like to build it myself. thanks for the input. please feel free to streamline the sketch or advise if anything is being done wrong, or a better way to do it. thanks again.  smiley-grin  edit** and charge pump (max619) 50ma model.

Code:
#include <TinyWireM.h>
#define IO_ADDR 0x50
#define ledpin 1
float tempF;
float a;
byte x; //for testing
unsigned int pointer=0;//x5a2;
void setup() {
  pinMode(ledpin,OUTPUT);
  pinMode(3,INPUT);
  //  for (int i=0;i<20;i++){   for testing
  TinyWireM.begin();        // initialize the I2C interface
  beginsequence();
  //  }
}
void loop() {
  if (pointer==0x13){   //e2 addr 20. bust out of loop when 20 samples done.
    endrun();
  }
  a=analogRead(3);
  tempF=(5.0*a*100.0)/1023.0;
  byte c=tempF+0.5;
  TinyWireM.beginTransmission(IO_ADDR);
  TinyWireM.send(pointer>>8);
  TinyWireM.send(pointer & 0xFF);
  TinyWireM.send(c);
  TinyWireM.endTransmission();

  pointer=pointer+1;
  
  
delay(60000);
}

void endrun(){
  tone(4, 2000, 80);
  digitalWrite(ledpin,HIGH);
  while (1){       //just hang here with led on till i get up of lazy butt to retrieve. basically crash sketch here, best way for this?
  }
}

void beginsequence(){    //some kind of visual indicator that its gonna start, battery not dead
  tone(4, 2000, 80);
  digitalWrite(ledpin,HIGH);
  delay(500);
  digitalWrite(ledpin,LOW);
  delay(200);
  tone(4, 2000, 80);
  digitalWrite(ledpin,HIGH);
  delay(200);
  digitalWrite(ledpin,LOW);
delay(200);
}


« Last Edit: April 22, 2013, 11:19:37 am by grendle » Logged

Global Moderator
Dallas
Online Online
Shannon Member
*****
Karma: 207
Posts: 12903
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Hello,

in experimenting, ive got an attiny85...

Are there any free pins left (other than RESET)?
Logged

Offline Offline
Full Member
***
Karma: 2
Posts: 148
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

if i dump the tone(), gives me one pin. i could dump the led too, gives me 2 pins then.
Logged

Global Moderator
Dallas
Online Online
Shannon Member
*****
Karma: 207
Posts: 12903
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset


How precious is the data?  If a transfer fails, should the data be preserved for another attempt?
Logged

Offline Offline
Full Member
***
Karma: 2
Posts: 148
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

not important at this point at all, just learning stages still.
Logged

Global Moderator
Dallas
Online Online
Shannon Member
*****
Karma: 207
Posts: 12903
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset


What I would do...

• Use the LED pin for serial communications (leave the LED in place).

• On powerup / reset, dump all data to Serial.

• Leave everything else in your program the way it is.
Logged

Offline Offline
Full Member
***
Karma: 2
Posts: 148
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

i am going to give that a go, sounds good. thank you C.B. right now watching battlestar galactica when zarek and gaeta try to take over the galactica, i think blood on your hands episode. as soon as done im gonna get to work on this.
Logged

Offline Offline
Full Member
***
Karma: 2
Posts: 148
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

here is the code, the "test" comes through fine, everything else just blank lines. am i reading the 24lc256 correctly with tinywirem? core is attiny85 @8 internal, bod disabled.

Code:
#include <TinyWireM.h>
#define IO_ADDR 0x50
byte data;
unsigned int pointer=0;

void setup(){
  Serial.begin(9600);
  Serial.println("test");
 
 
//  for (int i=0;i<20;i++){

    TinyWireM.beginTransmission(IO_ADDR);
    TinyWireM.send(pointer>>8);
    TinyWireM.send(pointer & 0xFF);
    TinyWireM.endTransmission();
    TinyWireM.requestFrom(IO_ADDR,1);
    data=TinyWireM.receive();
//    pointer++;
    Serial.println(data);
   
//  }
}

void loop(){
 
}
Logged

Offline Offline
Full Member
***
Karma: 2
Posts: 148
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

wait i see, i forgot tinywire.begin, let me revise and retry.

SUCCESS!

thank you C.B.
i just got to put it all together now. revised read/reset/send sketch that works. i use putty, can save it to putty log and import to excel, as long as i know when readings started, i can add the times to excel afterwards, eliminating an rtc for this project. (which i may add anyway later on) thanks again.

Code:
#include <TinyWireM.h>
#define IO_ADDR 0x50
byte data;
unsigned int pointer=0;

void setup(){
  TinyWireM.begin();
  Serial.begin(9600);
  Serial.println("test");
 
  
  for (int i=0;i<20;i++){

    TinyWireM.beginTransmission(IO_ADDR);
    TinyWireM.send(pointer>>8);
    TinyWireM.send(pointer & 0xFF);
    TinyWireM.endTransmission();
    TinyWireM.requestFrom(IO_ADDR,1);
    data=TinyWireM.receive();
    pointer++;
    Serial.println(data,DEC);
    
  }
}

void loop(){
  
}


* attinyread.png (28.85 KB, 648x502 - viewed 27 times.)
« Last Edit: April 22, 2013, 11:27:00 am by grendle » Logged

Pages: [1]   Go Up
Jump to: