Author Topic: Digispark, one wire therm, RTC & EEPROM Kit...  (Read 12812 times)

gmbowen

  • Newbie
  • *
  • Posts: 11
Digispark, one wire therm, RTC & EEPROM Kit...
« on: March 21, 2016, 09:54:02 am »
Alright, noobish here (computer/hardware experience, some programming experience, solder-friendly)....I work with kids and I thought they'd find it interesting to collect logs of time/date/temperature. I bought the digispark, one-wire thermometer, RTC and EEPROM kit so that I could put together a small temp logging unit figuring I'd store the data on the EEPROM and dump it to the serial monitor. Whoops, digistump doesn't do dumping. Okay, I can't believe this hasn't come up before (since Digistump sells all 4 of the products I've bought)....but since you can't dump to the serial monitor, and I don't want to have to disconnect the EEPROM and attach it to another arduino (because I'm putting it all in a case w/ a battery so they can put it in different places), just how am I supposed to get the data off the eeprom and onto a computer where they can use it?? 

Any suggestions? I've done this with bigger arduino (i.e., uno & nano writing to an SD card or using the serial monitor), but the digispark has left me stymied.

Thanks.

cpetito

  • Newbie
  • *
  • Posts: 22
Re: Digispark, one wire therm, RTC & EEPROM Kit...
« Reply #1 on: March 21, 2016, 12:11:23 pm »
The good news: you can dump to the serial monitor.  You will need either a 3.3V USB to serial adapter or you can use an Arduino UNO. 

With the adapter simply connect Tx to Rx and Rx to Tx.

Serial is configured to use the Tx and Rx pins.

The end of this article will detail how to use the Uno: http://digistump.com/wiki/oak/tutorials/serial_through_arduino

There is also an article on how to use a Bus Pirate: http://digistump.com/wiki/oak/tutorials/serial

Thanks for inspiring children!

gmbowen

  • Newbie
  • *
  • Posts: 11
Re: Digispark, one wire therm, RTC & EEPROM Kit...
« Reply #2 on: March 21, 2016, 01:23:16 pm »
Thanks for replying. This is where my noobish status comes to the fore....because I have good knowledge in some areas, less so in others.

1) When you're referring to a 3.3V USB to Serial Adapter do you mean the FTDI adapters? I can find 3.3V versions of those, and I can see how their "end" pins have labels DTR-RX-TX-VCC-CTS-GND so I'm assuming these would be the RX and TX you're talking about.

But when I look at Pinout diagrams of the Digispark ATTiny 85 units such as this one:

http://blog.mister-bidouilles.fr/wp-content/uploads/2015/01/digispark-1.png

[I chose this image because it had the USB tab labeled too....most don't]

I don't see anything labeled Tx or Rx.....unless that's what the "Data-" and "Data+" on the USB tab are for....and if that's them I don't know which is which (is "Data+" Tx??? That'd make sense, but I'm not sure). I'd surely appreciate more help on this.

2) Why did you specify 3.3V? Nothing on the pin labels for the ATTiny are 3.3V so I wasn't clear why you'd specified that.

If I'm correct about the FTDI thing, then I can easily see how to connect Data+ to Rx on the FTDI, and Data- to the TX on the FTDI. What I'm unclear is if I should power the Digispark ATTiny 85 with 5v through the USB tab or if I should use 3.3V. If it *is* 3v3 I'm supposed to use, any chance you could explain why? (Like I said, nothing on the Digispark ATTiny85 diagram above says 3v3, that's why I'm confused about this)

3) I'm part of a group that's trying to get more arduino going on in schools to encourage kids both to build things and to learn to program. When I can show them things like this working then it encourages them to think about their own designs and plans. My computer classes are far in history, and I'm rusty as heck, but I recognize the potential arduino offers for them.

4) Even if I DO understand how to connect them together in 1), how do I go about seeing the output on my PC? Do I use a terminal program?? Like PuTTY or Hyperterminal?  If that's the case then how do I go about sending a command to get the EEPROM kit chip to "dump" its memory content (all the time/data & temp data) to the terminal window?

Thanks, I appreciate any help. I do workshops for teachers on doing classroom investigations in science. If I can get this sorted then I can show them the small digispark kits and they can just follow the code/instructions that I give them and build their own classroom units (the soldering some could do, the figuring out this stuff by themselves no way). Again, thanks. :)

digistump

  • Administrator
  • Hero Member
  • *****
  • Posts: 1465
Re: Digispark, one wire therm, RTC & EEPROM Kit...
« Reply #3 on: March 21, 2016, 01:32:58 pm »
@cpetito is mixing up the Oak and the Digispark, the instructions he gave are for the Oak.

The Digispark does not have serial.

We provide the DigiKeyboard, DigiCDC, and DigiUSB libraries for USB communications - you can use those to dump it, though there probably isn't enough room for DigiCDC to work with OneWire and EEPROM/RTC libraries.

gmbowen

  • Newbie
  • *
  • Posts: 11
Re: Digispark, one wire therm, RTC & EEPROM Kit...
« Reply #4 on: March 21, 2016, 02:40:32 pm »
>The Digispark does not have serial.

Ah, okay. I didn't know that not having serial monitor meant not having serial at all. Thanks for clearing that up. :)

I'll look for those libraries. I'd read that DigiUSB was no longer active, that's why I was asking about other possibilities.

Regarding DigiCDC (I found your post on it here: https://digistump.com/wiki/digispark/tutorials/digicdc)....

I don't need to "read" the information off using the same sketch that I get the date/time/temp sent to the EEPROM with do I? I was thinking of using two sketches....one sketch loaded to the digispark to write that date/time/temp info TO the EEPROM, the other sketch (now that I know about digicdc) with DigiCDC and EEPROM libraries so that I can access the data from the EEPROM using a serial monitor? Would something like that work?...or am I missing something?

Thanks Eric.

digistump

  • Administrator
  • Hero Member
  • *****
  • Posts: 1465
Re: Digispark, one wire therm, RTC & EEPROM Kit...
« Reply #5 on: March 21, 2016, 06:03:10 pm »
Two sketches will work fine - the EEPROM doesn't get erased unless your sketch erases it

gmbowen

  • Newbie
  • *
  • Posts: 11
Re: Digispark, one wire therm, RTC & EEPROM Kit...
« Reply #6 on: March 21, 2016, 09:18:42 pm »
That's what I thought, but it's nice to have it confirmed (I spend too much time trying to solve a problem that's based on me misunderstanding an issue). Thanks very much for your help.

gmbowen

  • Newbie
  • *
  • Posts: 11
Re: Digispark, one wire therm, RTC & EEPROM Kit...
« Reply #7 on: March 24, 2016, 09:05:02 am »
It was actually harder getting this whole setup (Digispark, therm, RTC & EEPROM) working with the Digispark than I thought it would be.

My first step has been to get the RTC working with DigiCDC so that I was sure I could set the time and read the output.

The next step is to get the thermometer working, then write something to and then read something from the EEPROM. And then write the time/date to the EEPROM, and then to check to see if I can read the EEPROM (using DigiCDC to check both of these).

To aid any other newbies in doing this I thought I'd post the sketch as I figured out something that worked (because I couldn't find clear worked out examples of using DigiCDC anywhere).

Here's the sketch for Digispark/RTC shown on DigiCDC (using the regular old Serial Monitor). If anyone has any "code efficiency" suggestions feel free to mention them (this sketch takes 95% of the memory on the Digispark)....altho' of course my long-term plan is to write time/date/temp to the EEPROM every few minutes using one sketch, and then using a "read" eeprom and DigiCDC using another sketch to get the data off. And then maybe a third sketch to "erase" the EEPROM.

Code: [Select]
#include <TinyWireM.h>                  // I2C Master lib for ATTinys which use USI - comment this out to use with standard arduinos
#include <DigiCDC.h>         
#include <TinyRTClib.h>
// WORKS but very slow. A bit faster if remove "Date" information.
RTC_DS1307 RTC;

void setup(){
 
  TinyWireM.begin();                    // initialize I2C lib - comment this out to use with standard arduinos
  RTC.begin();

  if (! RTC.isrunning()) {
    // following line sets the RTC to the date & time this sketch was compiled only for the first run
    RTC.adjust(DateTime(__DATE__, __TIME__));
  }
 
  SerialUSB.begin();
}


void loop(){
DateTime now = RTC.now();
     if(now.hour()<10){
    SerialUSB.print("0");}
    SerialUSB.print(now.hour(), DEC);
    SerialUSB.print(":");
     if(now.minute()<10){
    SerialUSB.print("0");}
    SerialUSB.print(now.minute(), DEC);
    SerialUSB.print(':');
     if(now.second()<10){
    SerialUSB.print("0");}
    SerialUSB.print(now.second(), DEC);
    SerialUSB.print(" ");
    SerialUSB.print(now.year(), DEC);
    SerialUSB.print('/');
    if(now.month()<10){
    SerialUSB.print("0");}
    SerialUSB.print(now.month(), DEC);
    SerialUSB.print('/');
    if(now.day()<10){
    SerialUSB.print("0");}
    SerialUSB.println(now.day(), DEC);
        SerialUSB.delay(3000);
}
« Last Edit: March 28, 2016, 08:21:57 am by gmbowen »

gmbowen

  • Newbie
  • *
  • Posts: 11
Re: Digispark, one wire therm, RTC & EEPROM Kit...
« Reply #8 on: March 25, 2016, 10:50:32 am »
The "Temperature Sensor" page in the wiki (for the digispark Cs18b20 shield) has extensive instructions for using it with the Oak, but for the Digispark it says "Digispark Arduino IDE goto Examples→OneWire→Digispark Example" but my IDE doesn't have any Digispark Examples listed.

I'm using Arduino IDE 1.6.7 and under Examples->OneWire it has DS18x20 and two others that don't seem relevant. Will that code work with the Digispark? I've tried now and can't get it to.

I managed to get CDC to echo input text back to the serial monitor screen, but when I use this code to access the one wire I get nada from the thermometer (I know the echo code is working because of that write line I can edit out)…now that's changed (see bottom of this post) but there's still no accurate temperature.
Code: [Select]
#include <DigiCDC.h>
#include <TinyWireM.h>
void setup(){
  TinyWireM.begin();
    // initialize the digital pin as an output.
  SerialUSB.begin();
}

int get_temp() {
   int raw = analogRead(A0+15);
   //raw -= 13; // raw adjust = kelvin
   int in_c = raw - 273; // celcius
   return in_c;
}

void loop(){
  SerialUSB.refresh();
  int temp = get_temp();
  SerialUSB.println(temp);
// debug. If below uncommented then will print "Hello" with a 2 or 3 space gap over and over.
//    SerialUSB.write("Hello");
  SerialUSB.delay(1000); // one second delay
}

[the temperature getting code in here came from another post in the forums here]

Any ideas folks?
A programmer friend suggested that SerialUSB.write needed to output a String, so we tried SerialUSB.write(String(temp)); but that didn't work at all.

Thanks,

Mike Bowen

p.s. I also know the temperature shield for the digispark is working because I tested it with an uno.

p.p.s. NOW get output. Changed "SerialUSB.write(temp);" to "SerialUSB.println(temp);"....and now the output is consistently -210. SOOoooo, there's something wrong with the function.....warming or cooling the DS18b20 doesn't change the output at all. So just what is wrong with the function to get the temperature??
« Last Edit: March 25, 2016, 09:12:18 pm by gmbowen »

digistump

  • Administrator
  • Hero Member
  • *****
  • Posts: 1465
Re: Digispark, one wire therm, RTC & EEPROM Kit...
« Reply #9 on: March 25, 2016, 10:30:25 pm »
If you have OneWire installed separately it is probably showing the examples from that copy instead of the copy included for the Digispark - but I can confirm if there is no conflict you should be able to see that example and use the modified library for the Digispark

gmbowen

  • Newbie
  • *
  • Posts: 11
Re: Digispark, one wire therm, RTC & EEPROM Kit...
« Reply #10 on: March 26, 2016, 06:14:51 am »
The problem is that the Onewire->Tiny85_Temp example in the 1.6.7 IDE is for a DS1621 and not the DS18b20 and the difference is that the former code needs an Address (but not unique to that chip) whereas the DS18B20 each do have a unique address (to that particular physical unit), but you normally don't need it to use just one of them. If I'm only using one 1-wire it shouldn't matter that I don't have an address.

Basically, I've figured out most of it but I can't figure out what the function would be to call the temperature from the Digispark 1-wire shield using the  TinywireM.h library. That's what's holding me up now.....that I don't know how to get a temperature reading from the DS18B20 using that library without knowing the address. Do you have a code example using  TinyWireM.h  and the DS18B20?

I've confirmed the temperature shield works (by hooking it up to a UNO). And I bought a second Digispark (from the local Microcenter) to make sure it wasn't a hardware problem. So it's merely down to not being able to find any example of using TinyWireM.h with the DS18B20 shield...which I keep reading SHOULD work, but I can't find any code example to show me how to make it work.

I now better understand my problem. The code I'm using for the temperature function is just wrong. It originally came from (and this isn't where I got it from) here:

Code: [Select]
int get_temp() {
   int raw = analogRead(A0+15);
   /* Original code used a 13 Cdeg adjustment. But based on my results, I didn't seem to need it. */
   // raw -= 13; // raw adjust = kelvin
   int in_c = raw - 273; // celcius
   return in_c;
}

Which was sourced from here: http://digistump.com/board/index.php/topic,893.0.html (altho' despite them saying it works I can't get it working at all....and it's also for the INTERNAL way of reading temp in the ATTiny, NOT for the 18B20 shield for the Digispark).

So here's the problem, I can find no code example of the onewire thermometer shield that I bought for the digispark providing a temperature to the Digispark. I can get the shield working with a UNO using the onewire library, but that library is too large for the digispark. So I guess I'm asking IS there a way of using that shield with the digispark it seems to be designed for??
« Last Edit: March 26, 2016, 12:59:05 pm by gmbowen »

gmbowen

  • Newbie
  • *
  • Posts: 11
Re: Digispark, one wire therm, RTC & EEPROM Kit...
« Reply #11 on: March 28, 2016, 08:41:08 am »
For now I've given up on using TinyWireM.h to get the onewire DS18b20 temp shield to work. You'd think, since it was a shield kit provided for the digispark, that there'd be code somewhere to show how they worked together, but no such luck (or advice). Basically, at this point, buying the temp shield for the digispark was a waste of moolah....minor moolah, but still moolah. 

So as much as I'd like to keep using the TinyWireM.h library to read temperature on the DS18b20 so that I could reduce the overall size of libraries I'm loading into the digispark, at this point just to have a thermometer working with the Digispark I'm going to go a different route and use a DHT11. Adafruit supplies various libraries for their Tinker and one of them is the TinyDHT library (https://github.com/adafruit/TinyDHT). It seems to work pretty well with the DHT11 and outputs Degrees F (oddly, but more on that below) successfully to the DigiCDC serial monitor. Okay, so here's the "working" sketch....with instructions in it on how to hook up the DHT11 to the digispark.

Code: [Select]
// Integer Temperature sketch for Digispark to show digital output on serial monitor
// Gratefully adapted from TinyDHT_TestUno.ino sketch at https://github.com/adafruit/TinyDHT

#include <TinyDHT.h>
#include <DigiCDC.h>

#define DHTPIN 5  // DHT connected to Arduino Uno Digital Pin 5 (the 6th digispark pin)

// Uncomment whatever type you're using!
#define DHTTYPE DHT11   // DHT 11 - I've only tested this one.
//#define DHTTYPE DHT22   // DHT 22  (AM2302)
//#define DHTTYPE DHT21   // DHT 21 (AM2301)

// Connect pin 1 (on the left) of the sensor to +5V
// Connect pin 2 of the sensor to whatever your DHTPIN is (in this case P5 on the digispark)
// Connect pin 4 (on the right) of the sensor to GROUND
// Connect a 10K resistor from pin 2 (data) to pin 1 (power)
//    of the sensor (I've used a 4k7 resistor with a digispark w/o a problem)

DHT dht(DHTPIN, DHTTYPE);

void setup() {
  pinMode(5, INPUT);
  // initialize the digital pin as an output.
  SerialUSB.begin();
  SerialUSB.println("DHTxx test!");
  dht.begin();
}

void loop() {
  // Reading temperature or humidity takes about 250 milliseconds!
  // Sensor readings may also be up to 2 seconds 'old' (its a very slow sensor)
  int8_t h = dht.readHumidity();
  int16_t t = dht.readTemperature(1);

  // check if returns are valid then something went wrong!
  if ( t == BAD_TEMP || h == BAD_HUM ) { // if error conditions         
    SerialUSB.println("Failed to read from DHT");
  } else {
    SerialUSB.print("Humidity: ");
    SerialUSB.print(h);
    SerialUSB.print(" %\t");
    SerialUSB.print("Temperature: ");
    SerialUSB.print(t);
    SerialUSB.println(" *F");
  }
  delay(2000);
}

It IS possible I suspect to make the library even smaller by making it specific to the DHT11. This sensor only records integer temp in the first place, so since that's what the library does there's not really a reason to use the DHT22 (which, as far as I know, does temperature to decimal places). I wish I knew how to tweak libraries, because by my read this library spends a bunch of code converting Celsius to Fahrenheit. But since I want Celsius anyways, that's making the library bigger than it needs to be. Perhaps at some point I'll try and make it smaller by removing the bits needed for the DHT 22 and 21 and removing the conversion from Celsius to Fahrenheit so that my sketch won't need to convert it back.

Next I'm going to play with the EEPROM shield and see if I have any success with that....
« Last Edit: March 28, 2016, 01:03:57 pm by gmbowen »

gmbowen

  • Newbie
  • *
  • Posts: 11
Re: Digispark, one wire therm, RTC & EEPROM Kit...
« Reply #12 on: March 28, 2016, 12:48:56 pm »
I've now adapted the TinyDHT library to remove support for anything but DHT11 and renamed it TinyDHT11 (library files attached below) and altered my code to conform to the new smaller library. This saved almost 5% of the memory space (to me a significant amount on the Digispark). It also now outputs degrees celsius (since this was for kids working in science that was what I needed anyways). Hackng stuff out of a library file was far easier than I expected it to be....not saying I could write a library, but I can identify what isn't needed for my purposes in one...

Code: [Select]
// Integer Temperature sketch for Digispark to show digital output on serial monitor
// Gratefully adapted from TinyDHT_TestUno.ino sketch at https://github.com/adafruit/TinyDHT

#include <TinyDHT11.h>
#include <DigiCDC.h>

#define DHTPIN 5  // DHT11 connected to Arduino Uno Digital Pin 5 (the 6th digispark pin)

// Connect pin 1 (on the left) of the sensor to +5V
// Connect pin 2 of the sensor to whatever your DHTPIN is
// Connect pin 4 (on the right) of the sensor to GROUND
// Connect a 10K resistor from pin 2 (data) to pin 1 (power)
//    of the sensor (I've used a 4k7 resistor with a digispark w/o a problem)

DHT dht(DHTPIN);

void setup() {
  pinMode(5, INPUT);
  // initialize the digital pin as an output.
  SerialUSB.begin();
  dht.begin();
}

void loop() {
  // Reading temperature or humidity takes about 250 milliseconds!
  // Sensor readings may also be up to 2 seconds 'old' (its a very slow sensor)
  int8_t h = dht.readHumidity();
  int16_t t = dht.readTemperature(1);

  // check if returns are valid then something went wrong!
  if ( t == BAD_TEMP || h == BAD_HUM ) { // if error conditions         
    SerialUSB.println("Failed to read from DHT");
  } else {
    SerialUSB.print("Humidity: ");
    SerialUSB.print(h);
    SerialUSB.print(" %\t");
    SerialUSB.print("Temperature: ");
    SerialUSB.print(t);
    SerialUSB.println(" *C");
  }
  delay(2000);
}
« Last Edit: March 28, 2016, 01:05:03 pm by gmbowen »